diff --git "a/2022/16\354\243\274\354\260\250/\354\240\225\355\231\230\355\233\210/1766_\353\254\270\354\240\234\354\247\221.cpp" "b/2022/16\354\243\274\354\260\250/\354\240\225\355\231\230\355\233\210/1766_\353\254\270\354\240\234\354\247\221.cpp" new file mode 100644 index 0000000..56edb09 --- /dev/null +++ "b/2022/16\354\243\274\354\260\250/\354\240\225\355\231\230\355\233\210/1766_\353\254\270\354\240\234\354\247\221.cpp" @@ -0,0 +1,50 @@ +#include +using namespace std; + +int n; int m; +int in[32001]; +vector adj[32001]; +void input() { + cin >> n >> m; + for (int i = 0; i < m; i++) { + int a; int b; + cin >> a >> b; + adj[a].push_back(b); + in[b]++; + } +} + + +void solve() { + priority_queue, greater> q; + for (int i = 1; i <= n; i++) { + if (in[i] == 0) { + q.push(i); + } + } + + while (!q.empty()) { + int cur = q.top(); + q.pop(); + cout << cur << " "; + for (int i = 0; i < adj[cur].size(); i++) { + in[adj[cur][i]]--; + if (in[adj[cur][i]] == 0) + q.push(adj[cur][i]); + } + } + + +} + + +int main(void) { + ios_base::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + input(); + solve(); + + return 0; +} \ No newline at end of file diff --git "a/2022/16\354\243\274\354\260\250/\354\240\225\355\231\230\355\233\210/1992_\354\277\274\353\223\234\355\212\270\353\246\254.cpp" "b/2022/16\354\243\274\354\260\250/\354\240\225\355\231\230\355\233\210/1992_\354\277\274\353\223\234\355\212\270\353\246\254.cpp" new file mode 100644 index 0000000..65fcc0a --- /dev/null +++ "b/2022/16\354\243\274\354\260\250/\354\240\225\355\231\230\355\233\210/1992_\354\277\274\353\223\234\355\212\270\353\246\254.cpp" @@ -0,0 +1,68 @@ +#include +using namespace std; + +int n; +char board[64][64]; + +void input() { + cin >> n; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + cin >> board[i][j]; + } + } +} + +void check(int i, int j, int depth) { + + if (depth == 0) { + cout << board[i][j]; + return; + } + + int size = pow(2, depth); + bool cut = false; + for (int a = i; a < i + size; a++) { + for (int b = j; b < j + size; b++) { + if (a >= n || b >= n || board[i][j] != board[a][b]) { + cut = true; + break; + } + } + if (cut) break; + } + + if (cut) { + cout << "("; + check(i, j, depth - 1); + check(i, j + size/2, depth - 1); + check(i + size/2, j, depth - 1); + check(i + size/2, j + size/2, depth - 1); + cout << ")"; + } + else + cout << board[i][j]; +} + + +void solve() { + int sq = 0; int temp = n; + while (temp) { + temp = temp / 2; + sq++; + } + sq--; + check(0, 0, sq); +} + + +int main(void) { + ios_base::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + input(); + solve(); + + return 0; +} \ No newline at end of file diff --git "a/2022/16\354\243\274\354\260\250/\354\240\225\355\231\230\355\233\210/2230_\354\210\230 \352\263\240\353\245\264\352\270\260.cpp" "b/2022/16\354\243\274\354\260\250/\354\240\225\355\231\230\355\233\210/2230_\354\210\230 \352\263\240\353\245\264\352\270\260.cpp" new file mode 100644 index 0000000..864afab --- /dev/null +++ "b/2022/16\354\243\274\354\260\250/\354\240\225\355\231\230\355\233\210/2230_\354\210\230 \352\263\240\353\245\264\352\270\260.cpp" @@ -0,0 +1,46 @@ +#include +#include +#include +using namespace std; + +int n; int m; vector a; + +void input() { + cin >> n >> m; + for (int i = 0; i < n; i++) { + int temp; + cin >> temp; + a.push_back(temp); + } +} + +void solve() { + sort(a.begin(), a.end()); + int l = 0; int r = 0; + int ans = 2000000001; + while (l < n && r < n) { + if (a[r] - a[l] == m) { + cout << m; + return; + } + if (a[r] - a[l] < m) { + r++; + } + else { + ans = min(ans, a[r] - a[l]); + l++; + } + + } + cout << ans; +} + +int main() { + ios_base::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + input(); + solve(); + + return 0; +} \ No newline at end of file diff --git "a/2022/16\354\243\274\354\260\250/\354\240\225\355\231\230\355\233\210/5547_\354\235\274\353\243\250\353\257\270\353\204\244\354\235\264\354\205\230.cpp" "b/2022/16\354\243\274\354\260\250/\354\240\225\355\231\230\355\233\210/5547_\354\235\274\353\243\250\353\257\270\353\204\244\354\235\264\354\205\230.cpp" new file mode 100644 index 0000000..9393974 --- /dev/null +++ "b/2022/16\354\243\274\354\260\250/\354\240\225\355\231\230\355\233\210/5547_\354\235\274\353\243\250\353\257\270\353\204\244\354\235\264\354\205\230.cpp" @@ -0,0 +1,95 @@ +#include +using namespace std; + +// (-1,-1) (0,-1) (1,0) (0,1) (-1,1) (-1,0) +// (0,-1) (1,-1) (1,0) (1,1) (0,1) (-1,0) + +pair even[6] = { {-1,-1}, {0,-1}, {1,0}, {0,1}, {-1,1}, {-1,0} }; +pair odd[6] = { {0,-1}, {1,-1}, {1,0}, {1,1}, {0,1}, {-1,0} }; + +int w; int h; +int ans = 0; +int board[102][102]; +bool v[102][102]; +void input() { + cin >> w >> h; + for (int i = 0; i < 101; i++) { + for (int j = 0; j < 101; j++) { + board[i][j] = -1; + } + } + for (int i = 1; i <= h; i++) { + for (int j = 1; j <= w; j++) { + cin >> board[j][i]; + } + } + +} + +void bfs(int i, int j) { // 0,0부터 시작해서 만질 수 있는 벽들 개수 세기 + v[i][j] = true; + queue> q; + int walls = 0; + q.push({ i,j }); + while (!q.empty()) { + pair now = q.front(); + int x = now.first; + int y = now.second; + q.pop(); + if (y % 2 == 0) { + for (int k = 0; k < 6; k++) { + int ny = y + even[k].second; + int nx = x + even[k].first; + if (nx >= 0 && nx <= w + 1 && ny >= 0 && ny <= h + 1) { + if (board[nx][ny] == -1 && !v[nx][ny]) { + v[nx][ny] = true; + q.push({ nx,ny }); + } + if (board[nx][ny] == 1) + walls++; + if (board[nx][ny] == 0 && !v[nx][ny]) { + v[nx][ny] = true; + q.push({ nx,ny }); + } + } + } + } + else { + for (int k = 0; k < 6; k++) { + int ny = y + odd[k].second; + int nx = x + odd[k].first; + if (nx >= 0 && nx <= w + 1 && ny >= 0 && ny <= h + 1) { + if (board[nx][ny] == -1 && !v[nx][ny]) { + v[nx][ny] = true; + q.push({ nx,ny }); + } + if (board[nx][ny] == 1) + walls++; + if (board[nx][ny] == 0 && !v[nx][ny]) { + v[nx][ny] = true; + q.push({ nx,ny }); + } + } + } + } + } + ans += walls; + +} + +void solve() { + bfs(0, 0); + cout << ans; +} + + +int main(void) { + ios_base::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + + input(); + solve(); + + return 0; +} \ No newline at end of file