diff --git "a/202102649/10026-\354\240\201\353\241\235\354\203\211\354\225\275.py" "b/202102649/10026-\354\240\201\353\241\235\354\203\211\354\225\275.py" new file mode 100644 index 0000000..9e5b0f7 --- /dev/null +++ "b/202102649/10026-\354\240\201\353\241\235\354\203\211\354\225\275.py" @@ -0,0 +1,44 @@ +import sys +sys.setrecursionlimit(1000000) +input = sys.stdin.readline + +n = int(input().rstrip()) +matrix = [list(input().rstrip()) for _ in range(n)] +visited = [[False] * n for _ in range(n)] + +three_cnt, two_cnt = 0, 0 +dx = [-1,1,0,0] +dy = [0,0,-1,1] + +def dfs(x,y): + visited[x][y] = True + current_color = matrix[x][y] + + for k in range(4): + nx = x + dx[k] + ny = y + dy[k] + if (0 <= nx < n) and (0 <= ny < n): + if visited[nx][ny]==False: + if matrix[nx][ny] == current_color: + dfs(nx,ny) + +for i in range(n): + for j in range(n): + if visited[i][j]==False: + dfs(i,j) + three_cnt += 1 + +for i in range(n): + for j in range(n): + if matrix[i][j]=='R': + matrix[i][j]='G' + +visited = [[False] * n for _ in range(n)] + +for i in range(n): + for j in range(n): + if visited[i][j] == False: + dfs(i,j) + two_cnt += 1 + +print(three_cnt,two_cnt) diff --git "a/202102649/1003-\355\224\274\353\263\264\353\202\230\354\271\230\355\225\250\354\210\230.py" "b/202102649/1003-\355\224\274\353\263\264\353\202\230\354\271\230\355\225\250\354\210\230.py" new file mode 100644 index 0000000..f1e8a5a --- /dev/null +++ "b/202102649/1003-\355\224\274\353\263\264\353\202\230\354\271\230\355\225\250\354\210\230.py" @@ -0,0 +1,7 @@ +T = int(input()) +for _ in range(T): + N = int(input()) + a, b = 1, 0 + for i in range(N): + a, b = b, a + b + print(a, b) \ No newline at end of file diff --git "a/202102649/1167-\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204.py" "b/202102649/1167-\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204.py" new file mode 100644 index 0000000..faa94b5 --- /dev/null +++ "b/202102649/1167-\355\212\270\353\246\254\354\235\230\354\247\200\353\246\204.py" @@ -0,0 +1,29 @@ +import sys +sys.setrecursionlimit(10**9) +input = sys.stdin.readline + +n = int(input()) +graph = [[] for _ in range(n+1)] + +for _ in range(n): + node = list(map(int, input().split()))[:-1] + for i in range(1, len(node)//2 + 1): + graph[node[0]].append([node[i*2 - 1], node[i*2]]) + +def dfs(x, dist): + for i in graph[x]: + node, wei = i + if distance[node] == -1: + distance[node] = dist + wei + dfs(node, dist + wei) + +distance = [-1] * (n+1) +distance[1] = 0 +dfs(1, 0) + +res = distance.index(max(distance)) +distance = [-1] * (n+1) +distance[res] = 0 +dfs(res, 0) + +print(max(distance)) \ No newline at end of file diff --git "a/202102649/1463-1\353\241\234\353\247\214\353\223\244\352\270\260.py" "b/202102649/1463-1\353\241\234\353\247\214\353\223\244\352\270\260.py" new file mode 100644 index 0000000..e69de29 diff --git "a/202102649/1655-\352\260\200\354\232\264\353\215\260\353\245\274\353\247\220\355\225\264\354\232\224.py" "b/202102649/1655-\352\260\200\354\232\264\353\215\260\353\245\274\353\247\220\355\225\264\354\232\224.py" new file mode 100644 index 0000000..f47f412 --- /dev/null +++ "b/202102649/1655-\352\260\200\354\232\264\353\215\260\353\245\274\353\247\220\355\225\264\354\232\224.py" @@ -0,0 +1,23 @@ +import heapq +import sys + +n = int(sys.stdin.readline()) + +leftHeap = [] +rightHeap = [] +for i in range(n): + num = int(sys.stdin.readline()) + + if len(leftHeap) == len(rightHeap): + heapq.heappush(leftHeap, -num) + else: + heapq.heappush(rightHeap, num) + + if rightHeap and rightHeap[0] < -leftHeap[0]: + leftValue = heapq.heappop(leftHeap) + rightValue = heapq.heappop(rightHeap) + + heapq.heappush(leftHeap, -rightValue) + heapq.heappush(rightHeap, -leftValue) + + print(-leftHeap[0]) \ No newline at end of file diff --git "a/202102649/17298-\354\230\244\355\201\260\354\210\230.py" "b/202102649/17298-\354\230\244\355\201\260\354\210\230.py" new file mode 100644 index 0000000..e69de29 diff --git "a/202102649/1918-\355\233\204\354\234\204\355\221\234\352\270\260\354\213\235.py" "b/202102649/1918-\355\233\204\354\234\204\355\221\234\352\270\260\354\213\235.py" new file mode 100644 index 0000000..9cd2841 --- /dev/null +++ "b/202102649/1918-\355\233\204\354\234\204\355\221\234\352\270\260\354\213\235.py" @@ -0,0 +1,24 @@ +strn = list(input()) +stack=[] +res='' +for s in strn: + if s.isalpha(): + res+=s + else: + if s == '(': + stack.append(s) + elif s == '*' or s == '/': + while stack and (stack[-1] == '*' or stack[-1] =='/'): + res += stack.pop() + stack.append(s) + elif s == '+' or s == '-': + while stack and stack[-1] != '(': + res+= stack.pop() + stack.append(s) + elif s == ')': + while stack and stack[-1] != '(': + res += stack.pop() + stack.pop() +while stack : + res+=stack.pop() +print(res) \ No newline at end of file diff --git "a/202102649/7569-\355\206\240\353\247\210\355\206\240.cc" "b/202102649/7569-\355\206\240\353\247\210\355\206\240.cc" new file mode 100644 index 0000000..fe2c353 --- /dev/null +++ "b/202102649/7569-\355\206\240\353\247\210\355\206\240.cc" @@ -0,0 +1,66 @@ +#include +#include +#include + +using namespace std; + + +int m, n, h, ans, dist[102][102][102]; +int dx[] = {0,0,1,-1,0,0}; +int dy[] = {1,-1,0,0,0,0}; +int dz[] = {0,0,0,0,1,-1}; +queue, int>> q; + +void bfs(){ + while(!q.empty()){ + int xx = q.front().first.first; + int yy = q.front().first.second; + int zz = q.front().second; + q.pop(); + for(int i=0;i<6;i++){ + int nx = xx+dx[i]; + int ny = yy+dy[i]; + int nz = zz+dz[i]; + + if(nx>=0&&ny>=0&&nz>=0&&nx> m >> n >> h; + for(int k=0;k> dist[i][j][k]; + if(dist[i][j][k] == 1){ + q.push(make_pair(make_pair(i,j),k)); + } + } + } + } + + bfs(); + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + for(int k=0;k +#include + +using namespace std; + +int tomatoMap[1000][1000]; +queue> q; +int result = 0; +int M, N; +int dx[] = {1, 0, -1, 0}; +int dy[] = {0, 1, 0, -1}; +void tomatoBFS() { + while (!q.empty()) { + int xx = q.front().first; + int yy = q.front().second; + + q.pop(); + + for (int i = 0; i < 4; i++) { + int nx = xx + dx[i]; + int ny = yy + dy[i]; + + if (nx >= 0 && ny >= 0 && nx < N && ny < M) { + if (tomatoMap[nx][ny] == 0) { + tomatoMap[nx][ny] = tomatoMap[xx][yy] + 1; + q.push(make_pair(nx, ny)); + } + } + } + } +} + +void tomato() { + cin >> M >> N; + + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + cin >> tomatoMap[i][j]; + + if (tomatoMap[i][j] == 1) { + q.push(make_pair(i, j)); + } + } + } + tomatoBFS(); + + + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) { + if (tomatoMap[i][j] == 0) { + cout << -1 << "\n"; + return; + } + + if (result < tomatoMap[i][j]) { + result = tomatoMap[i][j]; + } + } + } + + cout << result - 1 << "\n"; +} +int main() { + tomato(); + + return 0; +} \ No newline at end of file diff --git "a/202102649/9095-123\353\215\224\355\225\230\352\270\260.py" "b/202102649/9095-123\353\215\224\355\225\230\352\270\260.py" new file mode 100644 index 0000000..fc5c6dc --- /dev/null +++ "b/202102649/9095-123\353\215\224\355\225\230\352\270\260.py" @@ -0,0 +1,17 @@ +import sys +input = sys.stdin.readline + +def func(x): + if x == 1: + return 1 + elif x == 2: + return 2 + elif x == 3: + return 4 + else: + return func(x - 1) + func(x - 2) + func(x - 3) + +t = int(input()) +for _ in range(t): + n = int(input()) + print(func(n)) \ No newline at end of file