Submission #916285

# Submission time Handle Problem Language Result Execution time Memory
916285 2024-01-25T15:20:06 Z berr Maze (JOI23_ho_t3) C++17
35 / 100
116 ms 38156 KB
#include <bits/stdc++.h>
using namespace std;
 
const int mod = 1e9+7;
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int r, c, n; cin >> c>> r >> n;
 
    array<int, 2> s, g;
 
    cin >> s[0] >> s[1];
    cin >> g[0] >> g[1];
 
    s[0]--; s[1]--;
    g[0]--; g[1]--;
 
    vector<string> a(c);
 
    for(auto &i: a){
        cin >> i;
    }
 
 
    int ans = 0;
    queue<array<int, 2>> q[2];
    int pos = 0;
 
    q[0].push(s);
 
    queue<array<int, 2>> sinir;
    queue<array<int, 3>>sinir2;
        queue<array<int, 3>>sinir3;
 
    int of = 500;
    auto check =[&](int x, int y, int z){
        if(x<0 || y<0) return 1;
        if(x>=c || y>=r) return 1;
        if(a[x][y]=='.'){
            q[z%2].push({x, y});
            return 1;
        }
        return 0;
    
    };
 
    vector vis(c, vector(r, 0));
    vector vis2(c, vector(r, 0));
    vector vis3(c, vector(r, 0));
    int anss = -1;
    while(pos <r+c && anss==-1){   
        if(q[pos%2].size()==0 ){
            pos++;
            if(pos == (max(r, c)/n+2)) break;
            while(sinir.size()){
                auto [x, y] = sinir.front();
                vis[x][y] = 0;
                sinir2.push({x, y, 0});
                q[pos%2].push({x, y});
                sinir.pop();
                for(int i=1; i<=n; i++){
                    if(y-i<0) break;
                    if(vis[x][y-i]) 
                    if(vis2[x][y-i]) break;
                    a[x][y-i] = '.';
                    vis2[x][y-i] = 1;
                    sinir2.push({x, y-i, (i==n)});
                }
                for(int i=1; i<=n; i++){
                    if(y+i>=r) break;
                    if(vis[x][y+i]) break;
                   if(vis2[x][y+i]) break;
                    a[x][y+i] = '.';
                    vis2[x][y+i] = 1;
                    sinir2.push({x, y+i, (i==n)});
                }
 
            }
 
            while(sinir2.size()){
                auto [x, y, z] = sinir2.front();
                vis[x][y] = 0;
                sinir2.pop();
                for(int i=1; i<=n-z; i++){
                    if(x-i<0) break;
                    if(vis[x-i][y]) break;
                    if(vis3[x-i][y]) break;
                    a[x-i][y] = '.';
                    vis3[x-i][y] = 1;
                    sinir3.push({x-i, y, (i==n)});
 
                }
                for(int i=1; i<=n-z; i++){
                    if(x+i>=c) break;
                    if(vis[x+i][y]) break;
                    if(vis3[x+i][y]) break;
 
                    a[x+i][y] = '.';
                    vis3[x+i][y] = 1;
                    sinir3.push({x+i, y, (i==n)});
                }
            }
 
 
            
        }
        else{
 
            while(q[pos%2].size()){
                auto [x, y] = q[pos%2].front();
                q[pos%2].pop();
                int ans = 0;
                if(vis[x][y]) continue;
 
                vis[x][y] = 1;
                if(x==g[0] && y == g[1]&& anss==-1){
                    anss = pos;
                } 
 
                ans += check(x-1, y, pos);
                ans += check(x+1, y, pos);
                ans += check(x, y-1, pos);
                ans += check(x, y+1, pos);
                if(ans!=4){
                    sinir.push({x, y});
                }
            }
        }
 
 
    }
 
    cout << anss;
 
}   

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:27:9: warning: unused variable 'ans' [-Wunused-variable]
   27 |     int ans = 0;
      |         ^~~
Main.cpp:37:9: warning: unused variable 'of' [-Wunused-variable]
   37 |     int of = 500;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 7 ms 1624 KB Output is correct
20 Correct 4 ms 1188 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 7 ms 1628 KB Output is correct
23 Incorrect 6 ms 1624 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 480 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 860 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 4 ms 1116 KB Output is correct
28 Correct 3 ms 1112 KB Output is correct
29 Correct 4 ms 1880 KB Output is correct
30 Correct 4 ms 1884 KB Output is correct
31 Correct 3 ms 1372 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 2 ms 1116 KB Output is correct
34 Correct 6 ms 2392 KB Output is correct
35 Correct 7 ms 2392 KB Output is correct
36 Correct 7 ms 2396 KB Output is correct
37 Correct 9 ms 4188 KB Output is correct
38 Correct 9 ms 4188 KB Output is correct
39 Correct 20 ms 7828 KB Output is correct
40 Correct 59 ms 22200 KB Output is correct
41 Correct 77 ms 20068 KB Output is correct
42 Correct 78 ms 20280 KB Output is correct
43 Correct 103 ms 38156 KB Output is correct
44 Correct 116 ms 38004 KB Output is correct
45 Correct 64 ms 25680 KB Output is correct
46 Correct 62 ms 25940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 480 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 7 ms 1628 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 2 ms 860 KB Output is correct
37 Correct 4 ms 1188 KB Output is correct
38 Correct 3 ms 1116 KB Output is correct
39 Correct 3 ms 1116 KB Output is correct
40 Correct 8 ms 1640 KB Output is correct
41 Incorrect 6 ms 1628 KB Output isn't correct
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 480 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 7 ms 1628 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 2 ms 860 KB Output is correct
37 Correct 4 ms 1188 KB Output is correct
38 Correct 3 ms 1116 KB Output is correct
39 Correct 3 ms 1116 KB Output is correct
40 Correct 8 ms 1640 KB Output is correct
41 Incorrect 6 ms 1628 KB Output isn't correct
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 7 ms 1624 KB Output is correct
20 Correct 4 ms 1188 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 7 ms 1628 KB Output is correct
23 Incorrect 6 ms 1624 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 7 ms 1624 KB Output is correct
20 Correct 4 ms 1188 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 7 ms 1628 KB Output is correct
23 Incorrect 6 ms 1624 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 7 ms 1624 KB Output is correct
20 Correct 4 ms 1188 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 7 ms 1628 KB Output is correct
23 Incorrect 6 ms 1624 KB Output isn't correct
24 Halted 0 ms 0 KB -