답안 #811497

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
811497 2023-08-07T04:38:34 Z andecaandeci Tracks in the Snow (BOI13_tracks) C++17
45.3125 / 100
2000 ms 1048576 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

char grid[4005][4005], cur;
bool vis[4005][4005];
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++;
    vis[i][j] = 1;
    if(!vis[i+1][j] && valid(i+1,j) && grid[i+1][j]==cur){
        grid[i+1][j] = (cur=='F' ? 'R' : 'F');
        dfs(i+1,j);
    }
    if(!vis[i][j+1] && valid(i,j+1) && grid[i][j+1]==cur){
        grid[i][j+1] = (cur=='F' ? 'R' : 'F');
        dfs(i,j+1);
    }
    if(!vis[i-1][j] && valid(i-1,j) && grid[i-1][j]==cur){
        grid[i-1][j] = (cur=='F' ? 'R' : 'F');
        dfs(i-1,j);
    }
    if(!vis[i][j-1] && 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];
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++) vis[i][j] = 0;
        }

        grid[1][1] = (cur=='F' ? 'R' : 'F');
        dfs(1,1);
        ++ans;
    }

    cout<<ans<<'\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 224 ms 27048 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 708 KB Output is correct
4 Correct 27 ms 21048 KB Output is correct
5 Correct 34 ms 3676 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 2 ms 1104 KB Output is correct
10 Correct 26 ms 2568 KB Output is correct
11 Correct 7 ms 6228 KB Output is correct
12 Correct 51 ms 9876 KB Output is correct
13 Correct 32 ms 3688 KB Output is correct
14 Correct 32 ms 3576 KB Output is correct
15 Correct 241 ms 8792 KB Output is correct
16 Correct 202 ms 27060 KB Output is correct
17 Correct 250 ms 10244 KB Output is correct
18 Correct 22 ms 21080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1253 ms 31408 KB Output is correct
2 Execution timed out 2069 ms 15024 KB Time limit exceeded
3 Execution timed out 2020 ms 35152 KB Time limit exceeded
4 Execution timed out 2056 ms 36640 KB Time limit exceeded
5 Execution timed out 2073 ms 26496 KB Time limit exceeded
6 Runtime error 1039 ms 1048576 KB Execution killed with signal 9
7 Correct 1173 ms 32384 KB Output is correct
8 Correct 1347 ms 31460 KB Output is correct
9 Correct 70 ms 2068 KB Output is correct
10 Correct 137 ms 852 KB Output is correct
11 Correct 470 ms 31536 KB Output is correct
12 Correct 1062 ms 2716 KB Output is correct
13 Execution timed out 2073 ms 15340 KB Time limit exceeded
14 Execution timed out 2017 ms 10760 KB Time limit exceeded
15 Execution timed out 2064 ms 10792 KB Time limit exceeded
16 Execution timed out 2061 ms 7764 KB Time limit exceeded
17 Execution timed out 2070 ms 19420 KB Time limit exceeded
18 Execution timed out 2066 ms 18044 KB Time limit exceeded
19 Execution timed out 2049 ms 36744 KB Time limit exceeded
20 Execution timed out 2056 ms 15748 KB Time limit exceeded
21 Execution timed out 2085 ms 26564 KB Time limit exceeded
22 Execution timed out 2078 ms 25780 KB Time limit exceeded
23 Execution timed out 2096 ms 23212 KB Time limit exceeded
24 Execution timed out 2094 ms 26592 KB Time limit exceeded
25 Execution timed out 2074 ms 34416 KB Time limit exceeded
26 Runtime error 648 ms 1048576 KB Execution killed with signal 9
27 Runtime error 937 ms 1048576 KB Execution killed with signal 9
28 Runtime error 986 ms 1048576 KB Execution killed with signal 9
29 Runtime error 936 ms 1048576 KB Execution killed with signal 9
30 Runtime error 1076 ms 1048576 KB Execution killed with signal 9
31 Execution timed out 2112 ms 349552 KB Time limit exceeded
32 Runtime error 645 ms 1048576 KB Execution killed with signal 9