Submission #738964

# Submission time Handle Problem Language Result Execution time Memory
738964 2023-05-09T17:46:42 Z He_Huanglu Maze (JOI23_ho_t3) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
using namespace std;

const int N = 1005;
int n, m, s, rs, cs, re, ce;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vector <int> f[N], a[N];
queue <ii> q[2];

main () {
    cin.tie(0)->sync_with_stdio(0);
    if(fopen("task.inp", "r")) {
        freopen("task.inp", "r", stdin);
        freopen("wa.out", "w", stdout);
    }
    cin >> m >> n >> s >> rs >> cs >> re >> ce;
    for(int i = 1; i <= m; i++) a[i].resize(n + 1), f[i].resize(n + 1);
    for(int i = 1; i <= m; i++) {
        for(int j = 1; j <= n; j++) {
            char ch; cin >> ch;
            a[i][j] = (ch == '.' ? 1 : 0);
        }
    }
//    cout << " ^^\n";
    q[1].push({rs, cs}); f[rs][cs] = 1;
    while (!q[1].empty() || !q[0].empty()) {
//        cout << "ngu\n";
        while (!q[1].empty()) {
            int x, y; tie(x, y) = q[1].front(); q[1].pop();
//            cout << x << " " << y << " " << f[x][y] << " **\n";
            q[0].push({x, y});
            if(x == re && y == ce) return cout << f[x][y] - 1 << "\n", 0;
            for(int i = 0; i < 4; i++) {
                int u = x + dx[i], v = y + dy[i];
                if(u && u <= m && v && v <= n && !f[u][v] && a[u][v]) {
                    f[u][v] = f[x][y];
                    q[1].push({u, v});
                }
            }
        }
        while (!q[0].empty()) {
            int x, y; tie(x, y) = q[0].front(); q[0].pop();
            int s1 = max(1, x - s), s2 = max(1, y - s);
            int s3 = min(m, x + s), s4 = min(n, y + s);
            for(int i = s1; i <= s3; i++) {
                for(int j = s2; j <= s4; j++) if(!f[i][j]) {
                    if(i == s1 && (j == s1 || j == s4)) continue ;
                    if(i == s3 && (j == s1 || j == s4)) continue ;
                    f[i][j] = f[x][y] + 1;
                    q[1].push({i, j});
                }
            }
        }
    }
}

Compilation message

Main.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main () {
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen("task.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("wa.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -