Submission #493650

# Submission time Handle Problem Language Result Execution time Memory
493650 2021-12-12T13:52:33 Z _Monkey_ Tracks in the Snow (BOI13_tracks) C++17
100 / 100
618 ms 105440 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define el '\n'
#define ld long double
const int maxn=4e3+1,oo=1e9;

char c[maxn][maxn];
bool ok[maxn][maxn]={0};
int n,m,ans,x,y,nx,ny;
char cnt;
struct pnt{
    int x,y;
};
int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
vector<pnt> now,net;
bool check(int xx,int yy){
    if(!ok[xx][yy]) return 0;
    ok[xx][yy]=0;
    return 1;
}
int main(){
    //freopen("T.INP","r",stdin);
    //freopen("T.OUT","w",stdout);
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> m;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j){
            cin >> c[i][j];
            if(c[i][j]!='.') ok[i][j]=1;
        }
    cnt=c[1][1];
    ok[1][1]=0;
    now.push_back({1,1});
    ans=0;
    while(!now.empty()){
        net.resize(0);
        ans++;
        while(!now.empty()){
            x=now.back().x;
            y=now.back().y;
            now.pop_back();
            for(int i=0;i<4;++i){
                nx=x+dx[i];
                ny=y+dy[i];
                if(check(nx,ny)){
                    if(c[nx][ny]==cnt) now.push_back({nx,ny});
                    else net.push_back({nx,ny});
                }
            }
        }
        now=net;
        if(cnt=='F') cnt='R';
        else cnt='F';
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4588 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 708 KB Output is correct
4 Correct 9 ms 4748 KB Output is correct
5 Correct 4 ms 2612 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 844 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 3 ms 2316 KB Output is correct
11 Correct 2 ms 1996 KB Output is correct
12 Correct 6 ms 2776 KB Output is correct
13 Correct 4 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 14 ms 4520 KB Output is correct
16 Correct 15 ms 4556 KB Output is correct
17 Correct 10 ms 4300 KB Output is correct
18 Correct 8 ms 4684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 30156 KB Output is correct
2 Correct 52 ms 11672 KB Output is correct
3 Correct 308 ms 47192 KB Output is correct
4 Correct 88 ms 18760 KB Output is correct
5 Correct 245 ms 32600 KB Output is correct
6 Correct 602 ms 76336 KB Output is correct
7 Correct 14 ms 31564 KB Output is correct
8 Correct 14 ms 30224 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 16 ms 31056 KB Output is correct
12 Correct 2 ms 1484 KB Output is correct
13 Correct 42 ms 11608 KB Output is correct
14 Correct 25 ms 8268 KB Output is correct
15 Correct 34 ms 9104 KB Output is correct
16 Correct 19 ms 4048 KB Output is correct
17 Correct 107 ms 20052 KB Output is correct
18 Correct 115 ms 19884 KB Output is correct
19 Correct 88 ms 18768 KB Output is correct
20 Correct 74 ms 17348 KB Output is correct
21 Correct 189 ms 33660 KB Output is correct
22 Correct 253 ms 32612 KB Output is correct
23 Correct 212 ms 27600 KB Output is correct
24 Correct 212 ms 33524 KB Output is correct
25 Correct 517 ms 47264 KB Output is correct
26 Correct 458 ms 105440 KB Output is correct
27 Correct 618 ms 81832 KB Output is correct
28 Correct 618 ms 76216 KB Output is correct
29 Correct 610 ms 63560 KB Output is correct
30 Correct 568 ms 82608 KB Output is correct
31 Correct 404 ms 36312 KB Output is correct
32 Correct 512 ms 84792 KB Output is correct