Submission #465733

# Submission time Handle Problem Language Result Execution time Memory
465733 2021-08-16T17:26:58 Z MohamedFaresNebili Portals (BOI14_portals) C++14
70 / 100
1000 ms 5572 KB
#include <bits/stdc++.h>

using namespace std;

void solve()
{
    /// JUST KEEP GOING
    const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0};
    int n, m; cin>>n>>m; char grid[n][m]; int d[n][m];
    int sx, sy; int ex, ey;
    for(int l=0;l<n;l++) {
        for(int i=0;i<m;i++) {
            cin>>grid[l][i]; d[l][i]=1000000000;
            if(grid[l][i]=='S') {
                sx=l; sy=i; d[sx][sy]=0;
            }
            else if(grid[l][i]=='C') {
                ex=l; ey=i;
            }
        }
    }
    queue<pair<int, int>>q; q.push({sx, sy});
    while(!q.empty()) {
        int a=q.front().first, b=q.front().second; q.pop(); bool wall=false;
        for(int l=0;l<4;l++) {
            int x=a+nx[l], y=b+ny[l];
            if(x<0||x>=n||y<0||y>=m||grid[x][y]=='#') {
                wall=true; continue;
            }
            if(d[x][y]>d[a][b]+1) {
                d[x][y]=d[a][b]+1; q.push({x, y});
            }
        }
        int p=1000000000;
        if(!wall) {
            for(int l=0;l<4;l++) {
                int x=a, y=b; int k=0;
                while(x>=0&&y>=0&&x<n&&y<m&&grid[x][y]!='#') {
                    x+=nx[l]; y+=ny[l]; k++;
                }
                x-=nx[l]; y-=ny[l];
                p=min(p, k);
            }
        }
        else p=1;
        for(int l=0;l<4;l++) {
            int x=a, y=b;
            while(x>=0&&y>=0&&x<n&&y<m&&grid[x][y]!='#') {
                x+=nx[l]; y+=ny[l];
            }
            x-=nx[l], y-=ny[l];
            if(d[x][y]>d[a][b]+p) {
                d[x][y]=d[a][b]+p; q.push({x, y});
            }
        }
    }
    cout<<d[ex][ey]<<'\n';
}

int32_t main()
{

    int t; t=1;
    while(t--) {
        solve();
    }
    return 0;
}

Compilation message

portals.cpp: In function 'void solve()':
portals.cpp:57:22: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |     cout<<d[ex][ey]<<'\n';
      |                      ^~~~
portals.cpp:57:22: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 5 ms 460 KB Output is correct
6 Correct 6 ms 460 KB Output is correct
7 Correct 6 ms 460 KB Output is correct
8 Correct 4 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 3 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 5 ms 460 KB Output is correct
15 Correct 6 ms 588 KB Output is correct
16 Correct 6 ms 460 KB Output is correct
17 Correct 7 ms 484 KB Output is correct
18 Correct 10 ms 460 KB Output is correct
19 Correct 89 ms 484 KB Output is correct
20 Correct 117 ms 480 KB Output is correct
21 Correct 5 ms 460 KB Output is correct
22 Correct 6 ms 476 KB Output is correct
23 Correct 6 ms 460 KB Output is correct
24 Correct 63 ms 472 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 4 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 5 ms 460 KB Output is correct
15 Correct 6 ms 460 KB Output is correct
16 Correct 6 ms 460 KB Output is correct
17 Correct 7 ms 460 KB Output is correct
18 Correct 10 ms 460 KB Output is correct
19 Correct 88 ms 484 KB Output is correct
20 Correct 114 ms 460 KB Output is correct
21 Correct 7 ms 460 KB Output is correct
22 Correct 6 ms 460 KB Output is correct
23 Correct 6 ms 460 KB Output is correct
24 Correct 308 ms 5216 KB Output is correct
25 Execution timed out 1079 ms 5572 KB Time limit exceeded
26 Halted 0 ms 0 KB -