Submission #811130

# Submission time Handle Problem Language Result Execution time Memory
811130 2023-08-07T00:55:56 Z davinpwk Tracks in the Snow (BOI13_tracks) C++14
2.1875 / 100
2000 ms 16276 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

char grid[4005][4005], cur;
int h, w, n, cnt, ans = 0;

bool valid(int i, int j){
    return (i>=1 && i<=h && j>=1 && j<=w);
}

void dfs(int i, int j){
    cnt++;
    if(valid(i+1,j) && grid[i+1][j]==cur){
        grid[i+1][j] = (cur=='F' ? 'R' : 'F');
        dfs(i+1,j);
    }
    if(valid(i,j+1) && grid[i][j+1]==cur){
        grid[i][j+1] = (cur=='F' ? 'R' : 'F');
        dfs(i,j+1);
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>grid[i][j];
            if(grid[i][j] != '.') n++;
        }
    }
    if(grid[1][1] == '.') {
        cout<<"0\n";
        return 0;
    }


    while(cnt<n){
        cnt = 0;
        cur = grid[1][1];
        grid[1][1] = (cur=='F' ? 'R' : 'F');
        dfs(1,1);
        ++ans;
        // for(int i=1;i<=h;i++){
        //     for(int j=1;j<=w;j++) cout<<grid[i][j]<<' ';
        //     cout<<'\n';
        // }
    }

    cout<<ans<<'\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 2087 ms 2260 KB Time limit exceeded
2 Execution timed out 2079 ms 340 KB Time limit exceeded
3 Execution timed out 2084 ms 468 KB Time limit exceeded
4 Incorrect 54 ms 2260 KB Output isn't correct
5 Execution timed out 2093 ms 1364 KB Time limit exceeded
6 Execution timed out 2085 ms 340 KB Time limit exceeded
7 Execution timed out 2093 ms 468 KB Time limit exceeded
8 Incorrect 1 ms 468 KB Output isn't correct
9 Execution timed out 2089 ms 724 KB Time limit exceeded
10 Execution timed out 2082 ms 1236 KB Time limit exceeded
11 Incorrect 4 ms 1108 KB Output isn't correct
12 Execution timed out 2072 ms 1364 KB Time limit exceeded
13 Execution timed out 2082 ms 1364 KB Time limit exceeded
14 Execution timed out 2080 ms 1364 KB Time limit exceeded
15 Execution timed out 2085 ms 2260 KB Time limit exceeded
16 Execution timed out 2077 ms 2260 KB Time limit exceeded
17 Execution timed out 2076 ms 2132 KB Time limit exceeded
18 Incorrect 54 ms 2260 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2090 ms 15476 KB Time limit exceeded
2 Execution timed out 2086 ms 5256 KB Time limit exceeded
3 Execution timed out 2089 ms 16164 KB Time limit exceeded
4 Execution timed out 2094 ms 7748 KB Time limit exceeded
5 Execution timed out 2085 ms 12196 KB Time limit exceeded
6 Execution timed out 2093 ms 16204 KB Time limit exceeded
7 Execution timed out 2090 ms 16212 KB Time limit exceeded
8 Execution timed out 2087 ms 15444 KB Time limit exceeded
9 Execution timed out 2088 ms 340 KB Time limit exceeded
10 Execution timed out 2081 ms 340 KB Time limit exceeded
11 Execution timed out 2079 ms 15828 KB Time limit exceeded
12 Execution timed out 2084 ms 852 KB Time limit exceeded
13 Execution timed out 2086 ms 5360 KB Time limit exceeded
14 Execution timed out 2084 ms 3924 KB Time limit exceeded
15 Execution timed out 2093 ms 4244 KB Time limit exceeded
16 Execution timed out 2049 ms 1876 KB Time limit exceeded
17 Execution timed out 2083 ms 8268 KB Time limit exceeded
18 Execution timed out 2075 ms 8396 KB Time limit exceeded
19 Execution timed out 2081 ms 7756 KB Time limit exceeded
20 Execution timed out 2070 ms 7212 KB Time limit exceeded
21 Execution timed out 2092 ms 12624 KB Time limit exceeded
22 Execution timed out 2079 ms 12172 KB Time limit exceeded
23 Execution timed out 2084 ms 10376 KB Time limit exceeded
24 Execution timed out 2097 ms 12608 KB Time limit exceeded
25 Execution timed out 2078 ms 16204 KB Time limit exceeded
26 Correct 149 ms 14164 KB Output is correct
27 Incorrect 611 ms 16276 KB Output isn't correct
28 Execution timed out 2093 ms 16204 KB Time limit exceeded
29 Execution timed out 2085 ms 16204 KB Time limit exceeded
30 Execution timed out 2072 ms 15960 KB Time limit exceeded
31 Execution timed out 2087 ms 13020 KB Time limit exceeded
32 Execution timed out 2082 ms 16204 KB Time limit exceeded