#include <iostream>
#include <queue>
#include <vector>
using namespace std;
vector<vector<int>> box;
int m, n;
int is_inside(int ny, int nx)
{
return ((nx >= 0) && (ny >= 0) && (nx < m) && (ny < n));
}
void is_ripe()
{
int days = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
if (box[i][j] == 0)
{
cout << "-1";
return;
}
else
if (days < box[i][j])
days = box[i][j];
}
cout << days - 1;
}
int main()
{
cin >> m >> n;
queue<pair<int, int>> q;
int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, -1, 0, 1 };
for (int i = 0; i < n; i++)
{
vector<int> row;
for (int j = 0; j < m; j++)
{
int num;
cin >> num;
row.push_back(num);
if (num == 1)
q.push({ i, j });
}
box.push_back(row);
}
while (!q.empty())
{
int x = q.front().second;
int y = q.front().first;
q.pop();
for (int i = 0; i < 4; i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
if (is_inside(ny, nx) == 1 && box[ny][nx] == 0)
{
box[ny][nx] = box[y][x] + 1;
q.push({ ny, nx });
}
}
}
is_ripe();
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int arr[1001][1001] = { 0 };
int max(int a, int b)
{
return (a > b ? a : b);
}
int main(void)
{
string s1, s2;
int len1, len2;
cin >> s1 >> s2;
len1 = s1.length();
len2 = s2.length();
for (int i = 1; i <= len1; i++)
{
for (int j = 1; j <= len2; j++)
{
if (s1[i - 1] == s2[j - 1])
arr[i][j] = arr[i - 1][j - 1] + 1;
else
arr[i][j] = max(arr[i - 1][j], arr[i][j - 1]);
}
}
cout << arr[len1][len2];
return 0;
}
#include <iostream>
using namespace std;
void print_star(int line, int star, int space, int n)
{
if (line == n)
return;
else if (star == 0)
{
if (line + 1 < n)
cout << '\n';
line++;
star = 2 * line + 1;
space = 0;
}
else if (++space < n - line)
cout << ' ';
else
{
cout << '*';
star--;
}
print_star(line, star, space, n);
}
int main()
{
int n;
cin >> n;
print_star(0, 1, 0, n);
}
넷왓 공부 중 ! 담주에 평가 받아야징 크크
공부한 것들은 정리해서 포스팅 할 예정