Submission #1080543

#TimeUsernameProblemLanguageResultExecution timeMemory
1080543TAhmed33Maze (JOI23_ho_t3)C++98
Compilation error
0 ms0 KiB
forfor#include <bits/stdc++.h> using namespace std; #pragma GCC optimize ("Ofast") typedef long long ll; const int inf = 1e9; int n, m, K; pair <int, int> s, g; vector <vector <char>> a; vector <vector <bool>> vis; vector <vector <int>> dist; int dx[4] = {0, -1, 0, 1}; int dy[4] = {1, 0, -1, 0}; bool valid (int x, int y) { return x >= 0 && x < n && y >= 0 && y < m && !vis[x][y]; } void solve () { cin >> n >> m >> K; cin >> s.first >> s.second; cin >> g.first >> g.second; s.first--; s.second--; g.first--; g.second--; a.resize(n, vector <char> (m)); vis.resize(n, vector <bool> (m, false)); dist.resize(n, vector <int> (m, inf)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; vis[i][j] = 0; } } vis[s.first][s.second] = 1; dist[s.first][s.second] = 0; deque <pair <int, int>> cur; cur.push_back(s); int rem = n * m - 1; int ss = 0; while (rem > 0) { /* cout << rem << '\n'; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout << vis[i][j]; } cout << '\n'; } cout << '\n';*/ if (cur.empty()) { break; } deque <array <int, 4>> dd; while (!cur.empty()) { auto k = cur.front(); cur.pop_front(); //cout << k.first << " " << k.second << '\n'; bool flag = 0; for (int i = 0; i < 4; i++) { int x = k.first + dx[i]; int y = k.second + dy[i]; if (!valid(x, y)) { continue; } if (a[x][y] == '.') { dist[x][y] = ss; vis[x][y] = 1; cur.push_back({x, y}); rem--; } else { flag = 1; } } if (flag) { dd.push_back({k.first, k.second, 0, 0}); } } ss++; while (!dd.empty()) { auto k = dd.front(); dd.pop_front(); bool flag = 0; for (int i = 0; i < 4; i++) { array <int, 4> g = {k[0] + dx[i], k[1] + dy[i], k[2] + abs(dx[i]), k[3] + abs(dy[i])}; /* for (auto j : k) cout << j << " "; cout << '\n'; cout << ": \n"; for (auto k : g) { cout << k << " "; } cout << '\n' << '\n';*/ if (valid(g[0], g[1]) && g[2] <= K && g[3] <= K && g[2] + g[3] < 2 * K) { vis[g[0]][g[1]] = 1; dist[g[0]][g[1]] = ss; dd.push_back(g); rem--; } } if (!flag) { cur.push_back({k[0], k[1]}); } } } cout << dist[g.first][g.second] << '\n'; } signed main () { #ifndef ONLINE_JUDGE //freopen("input_file", "r", stdin); //freopen("output_file", "w", stdout); #endif //ios::sync_with_stdio(0); cin.tie(0); int tc = 1; //cin >> tc; while (tc--) solve(); }

Compilation message (stderr)

Main.cpp:1:7: error: stray '#' in program
    1 | forfor#include <bits/stdc++.h>
      |       ^
Main.cpp:1:1: error: 'forfor' does not name a type
    1 | forfor#include <bits/stdc++.h>
      | ^~~~~~
Main.cpp:7:1: error: 'pair' does not name a type
    7 | pair <int, int> s, g;
      | ^~~~
Main.cpp:8:1: error: 'vector' does not name a type
    8 | vector <vector <char>> a;
      | ^~~~~~
Main.cpp:9:1: error: 'vector' does not name a type
    9 | vector <vector <bool>> vis;
      | ^~~~~~
Main.cpp:10:1: error: 'vector' does not name a type
   10 | vector <vector <int>> dist;
      | ^~~~~~
Main.cpp: In function 'bool valid(int, int)':
Main.cpp:14:48: error: 'vis' was not declared in this scope
   14 |  return x >= 0 && x < n && y >= 0 && y < m && !vis[x][y];
      |                                                ^~~
Main.cpp: In function 'void solve()':
Main.cpp:17:2: error: 'cin' was not declared in this scope
   17 |  cin >> n >> m >> K;
      |  ^~~
Main.cpp:18:9: error: 's' was not declared in this scope
   18 |  cin >> s.first >> s.second;
      |         ^
Main.cpp:19:9: error: 'g' was not declared in this scope
   19 |  cin >> g.first >> g.second;
      |         ^
Main.cpp:21:2: error: 'a' was not declared in this scope
   21 |  a.resize(n, vector <char> (m));
      |  ^
Main.cpp:21:14: error: 'vector' was not declared in this scope
   21 |  a.resize(n, vector <char> (m));
      |              ^~~~~~
Main.cpp:21:22: error: expected primary-expression before 'char'
   21 |  a.resize(n, vector <char> (m));
      |                      ^~~~
Main.cpp:22:2: error: 'vis' was not declared in this scope
   22 |  vis.resize(n, vector <bool> (m, false));
      |  ^~~
Main.cpp:22:24: error: expected primary-expression before 'bool'
   22 |  vis.resize(n, vector <bool> (m, false));
      |                        ^~~~
Main.cpp:23:2: error: 'dist' was not declared in this scope
   23 |  dist.resize(n, vector <int> (m, inf));
      |  ^~~~
Main.cpp:23:25: error: expected primary-expression before 'int'
   23 |  dist.resize(n, vector <int> (m, inf));
      |                         ^~~
Main.cpp:32:2: error: 'deque' was not declared in this scope
   32 |  deque <pair <int, int>> cur;
      |  ^~~~~
Main.cpp:32:9: error: 'pair' was not declared in this scope
   32 |  deque <pair <int, int>> cur;
      |         ^~~~
Main.cpp:32:15: error: expected primary-expression before 'int'
   32 |  deque <pair <int, int>> cur;
      |               ^~~
Main.cpp:33:2: error: 'cur' was not declared in this scope
   33 |  cur.push_back(s);
      |  ^~~
Main.cpp:48:10: error: 'array' was not declared in this scope
   48 |   deque <array <int, 4>> dd;
      |          ^~~~~
Main.cpp:48:17: error: expected primary-expression before 'int'
   48 |   deque <array <int, 4>> dd;
      |                 ^~~
Main.cpp:70:5: error: 'dd' was not declared in this scope; did you mean 'dy'?
   70 |     dd.push_back({k.first, k.second, 0, 0});
      |     ^~
      |     dy
Main.cpp:74:11: error: 'dd' was not declared in this scope; did you mean 'dy'?
   74 |   while (!dd.empty()) {
      |           ^~
      |           dy
Main.cpp:79:12: error: expected primary-expression before 'int'
   79 |     array <int, 4> g = {k[0] + dx[i], k[1] + dy[i], k[2] + abs(dx[i]), k[3] + abs(dy[i])};
      |            ^~~
Main.cpp:99:2: error: 'cout' was not declared in this scope
   99 |  cout << dist[g.first][g.second] << '\n';
      |  ^~~~