# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
943201 | 2024-03-11T09:13:59 Z | itslq | Portals (BOI14_portals) | C++17 | 1 ms | 604 KB |
#include <bits/stdc++.h> using namespace std; int R, C; const pair<int, int> dirs[4] = {make_pair(0, 1), make_pair(0, -1), make_pair(1, 0), make_pair(-1, 0)}; queue<pair<pair<int, int>, int>> tocheck; vector<vector<int>> visited; bool grid[1000][1000]; void add(int x, int y, int n) { if (x < 0 || y < 0 || x >= R || x >= C) return; if (grid[x][y] || visited[x][y]) return; visited[x][y] = 1; tocheck.emplace(make_pair(x, y), n + 1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int P = 0, si, sj, ei, ej, ni, nj, ci, cj; cin >> R >> C; int left[R][C], right[R][C], up[R][C], down[R][C]; string row; visited = vector<vector<int>>(R, vector<int>(C, 0)); for (int i = 0; i < R; i++) { P = 0; cin >> row; for (int j = 0; j < C; j++) { left[i][j] = P; switch (row[j]) { case '.': grid[i][j] = 0; break; case '#': grid[i][j] = 1; P = j + 1; break; case 'S': si = i; sj = j; grid[i][j] = 0; break; case 'C': ei = i; ej = j; grid[i][j] = 0; break; } } P = C - 1; for (int j = C - 1; j >= 0; j--) { right[i][j] = P; if (grid[i][j]) P = j - 1; } } for (int j = 0; j < C; j++) { P = 0; for (int i = 0; i < R; i++) { up[i][j] = P; if (grid[i][j]) P = i + 1; } P = R - 1; for (int i = R - 1; i >= 0; i--) { down[i][j] = P; if (grid[i][j]) P = i - 1; } } pair<pair<int, int>, int> curr; add(si, sj, -1); while (true) { curr = tocheck.front(); tocheck.pop(); ci = curr.first.first; cj = curr.first.second; if (ci == ei && cj == ej) { cout << curr.second; return 0; } for (pair<int, int> d: dirs) add(ci + d.first, cj + d.second, curr.second); add(ci, left[ci][cj], curr.second); add(ci, right[ci][cj], curr.second); add(up[ci][cj], cj, curr.second); add(down[ci][cj], cj, curr.second); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Runtime error | 1 ms | 604 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Runtime error | 1 ms | 604 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Runtime error | 1 ms | 604 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Runtime error | 1 ms | 604 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Runtime error | 1 ms | 604 KB | Execution killed with signal 11 |
3 | Halted | 0 ms | 0 KB | - |