Submission #42235

#TimeUsernameProblemLanguageResultExecution timeMemory
42235gabrielsimoesPortals (BOI14_portals)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 52, INF = 1e9; typedef pair<int, int> pii; int n, m; bool open[MAXN][MAXN]; pii start, cake; // int ix(pii p) { return (p.first - 1) * m + p.second - 1; } // pii pr(int ix) { return pii(ix / m + 1, (ix % n) + 1); } // left, right, north, south int limit[MAXN][MAXN][4]; bool ok[MAXN][MAXN][MAXN][MAXN]; int dist[MAXN][MAXN][MAXN][MAXN]; int bfs() { deque<tuple<int, int, int, int>> q; q.push_back({start.first, start.second, 0, 0}); dist[start.first][start.second][0][0] = 0; while (!q.empty()) { int x, y, px, py; tie(x, y, px, py) = q.front(); q.pop_front(); // printf("x %d y %d px %d py %d\n", x, y, px, py); if (x == cake.first && y == cake.second) { return dist[x][y][px][py]; } bool haswall = 0; for (int i = 0; i < 8; i++) { int nx = x, ny = y; if (i < 4) { if (i == 0) ny--; if (i == 1) ny++; if (i == 2) nx--; if (i == 3) nx++; if (!open[nx][ny]) { haswall = true; } else if (!ok[nx][ny][px][py]) { dist[nx][ny][px][py] = dist[x][y][px][py] + 1; ok[nx][ny][px][py] = 1; q.push_back({nx, ny, px, py}); } } else { if (i == 4) ny -= limit[x][y][0]; if (i == 5) ny += limit[x][y][1]; if (i == 6) nx -= limit[x][y][2]; if (i == 7) nx += limit[x][y][3]; // printf("%d %d : %d %d\n", x, y, nx, ny); if (!ok[x][y][nx][ny]) { dist[x][y][nx][ny] = dist[x][y][px][py]; ok[x][y][nx][ny] = 1; q.push_front({x, y, nx, ny}); } } } if (haswall && px != 0 && !ok[px][py][px][py]) { dist[px][py][px][py] = dist[x][y][px][py] + 1; ok[px][py][px][py] = 1; q.push_back({px, py, px, py}); } } return dist[cake.first][cake.second][0][0]; } int main() { scanf("%d %d", &n, &m); char c; for (int i = 1; i <= n; i++) { for (int k = 1; k <= m; k++) { scanf(" %c", &c); if (c != '#') open[i][k] = 1; if (c == 'S') start = pii(i, k); if (c == 'C') cake = pii(i, k); } } for (int i = 1; i <= n; i++) { int last_wall = 0; for (int k = 1; k <= m; k++) { if (open[i][k]) limit[i][k][0] = k - last_wall - 1; else last_wall = k; } last_wall = m + 1; for (int k = m; k >= 1; k--) { if (open[i][k]) limit[i][k][1] = last_wall - k - 1; else last_wall = k; } } for (int k = 1; k <= m; k++) { int last_wall = 0; for (int i = 1; i <= n; i++) { if (open[i][k]) limit[i][k][2] = i - last_wall - 1; else last_wall = i; } last_wall = n + 1; for (int i = n; i >= 1; i--) { if (open[i][k]) limit[i][k][3] = last_wall - i - 1; else last_wall = i; } } printf("%d\n", bfs()); }

Compilation message (stderr)

portals.cpp: In function 'int bfs()':
portals.cpp:21:48: error: converting to 'std::deque<std::tuple<int, int, int, int> >::value_type {aka std::tuple<int, int, int, int>}' from initializer list would use explicit constructor 'constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {int&, int&, int, int}; <template-parameter-2-2> = void; _Elements = {int, int, int, int}]'
   q.push_back({start.first, start.second, 0, 0});
                                                ^
portals.cpp:48:39: error: converting to 'std::deque<std::tuple<int, int, int, int> >::value_type {aka std::tuple<int, int, int, int>}' from initializer list would use explicit constructor 'constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {int&, int&, int&, int&}; <template-parameter-2-2> = void; _Elements = {int, int, int, int}]'
           q.push_back({nx, ny, px, py});
                                       ^
portals.cpp:61:38: error: converting to 'std::deque<std::tuple<int, int, int, int> >::value_type {aka std::tuple<int, int, int, int>}' from initializer list would use explicit constructor 'constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {int&, int&, int&, int&}; <template-parameter-2-2> = void; _Elements = {int, int, int, int}]'
           q.push_front({x, y, nx, ny});
                                      ^
portals.cpp:69:35: error: converting to 'std::deque<std::tuple<int, int, int, int> >::value_type {aka std::tuple<int, int, int, int>}' from initializer list would use explicit constructor 'constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {int&, int&, int&, int&}; <template-parameter-2-2> = void; _Elements = {int, int, int, int}]'
       q.push_back({px, py, px, py});
                                   ^
portals.cpp: In function 'int main()':
portals.cpp:77:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &n, &m);
                         ^
portals.cpp:81:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf(" %c", &c);
                       ^