Submission #1092212

# Submission time Handle Problem Language Result Execution time Memory
1092212 2024-09-23T15:00:22 Z brinton Tracks in the Snow (BOI13_tracks) C++14
46.7708 / 100
2000 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
int H,W;
void dfs(int r,int c,vector<vector<int>>& matrix,vector<vector<int>>& minDist){
	// cout << r << " " << c << endl;
	int dx[4] = {0,1,-1,0};
	int dy[4] = {1,0,0,-1};
	for(int i = 0;i < 4;i++){
		int newX = r+dx[i];
		int newY = c+dy[i];
		if(newX < 0 || newY < 0 || newX >= H || newY >= W){
			continue;
		}
		if(matrix[newX][newY] == 0)continue;
		int newDist = minDist[r][c];
		if(matrix[newX][newY] != matrix[r][c]){
			newDist++;
		}
		if(minDist[newX][newY] > newDist){
			minDist[newX][newY] = newDist;
			dfs(newX,newY,matrix,minDist);
		}
	}
}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    //start here
    
    cin >> H >> W;
    vector<vector<int>> matrix(H,vector<int>(W,0));
    
    for(int i = 0;i < H;i++){
    	for(int j = 0; j < W;j++){
    		char tmp;
    		cin >> tmp;
    		if(tmp == 'F'){
    			matrix[i][j] = 1;
    		}else if(tmp == 'R'){
    			matrix[i][j] = 2;
    		}
    	}
    }
    vector<vector<int>> min_dist(H,vector<int>(W,INT_MAX));
    int ans = 0;
    min_dist[0][0] = 1;
    dfs(0,0,matrix,min_dist);
    for(int i = 0; i < H;i++){
    	for(int j = 0; j < W;j++){
    		if(matrix[i][j] != 0){
    			ans = max(min_dist[i][j],ans);
    			// cout << min_dist[i][j] << " ";
    		}
    		// else{
    			// cout << 0 << " ";
    		// }
    	}
    	// cout << endl;
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 2052 ms 31316 KB Time limit exceeded
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Execution timed out 2092 ms 20828 KB Time limit exceeded
5 Correct 469 ms 2384 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 30 ms 860 KB Output is correct
9 Correct 3 ms 672 KB Output is correct
10 Correct 749 ms 2200 KB Output is correct
11 Correct 1177 ms 5808 KB Output is correct
12 Execution timed out 2059 ms 11220 KB Time limit exceeded
13 Correct 469 ms 2416 KB Output is correct
14 Correct 495 ms 2168 KB Output is correct
15 Execution timed out 2045 ms 13904 KB Time limit exceeded
16 Execution timed out 2037 ms 31312 KB Time limit exceeded
17 Execution timed out 2044 ms 12636 KB Time limit exceeded
18 Execution timed out 2047 ms 20828 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2908 KB Output is correct
2 Execution timed out 2086 ms 44480 KB Time limit exceeded
3 Execution timed out 2081 ms 421972 KB Time limit exceeded
4 Execution timed out 2045 ms 78416 KB Time limit exceeded
5 Correct 527 ms 640952 KB Output is correct
6 Runtime error 893 ms 1048576 KB Execution killed with signal 9
7 Correct 3 ms 2136 KB Output is correct
8 Correct 2 ms 2904 KB Output is correct
9 Correct 1401 ms 3676 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
11 Correct 2 ms 1628 KB Output is correct
12 Correct 1 ms 1884 KB Output is correct
13 Execution timed out 2069 ms 44372 KB Time limit exceeded
14 Execution timed out 2052 ms 26708 KB Time limit exceeded
15 Correct 44 ms 44964 KB Output is correct
16 Execution timed out 2043 ms 23896 KB Time limit exceeded
17 Execution timed out 2055 ms 105552 KB Time limit exceeded
18 Correct 174 ms 173720 KB Output is correct
19 Execution timed out 2059 ms 78412 KB Time limit exceeded
20 Execution timed out 2040 ms 92172 KB Time limit exceeded
21 Execution timed out 2053 ms 244048 KB Time limit exceeded
22 Correct 634 ms 643156 KB Output is correct
23 Execution timed out 2081 ms 198996 KB Time limit exceeded
24 Correct 438 ms 456200 KB Output is correct
25 Correct 840 ms 712532 KB Output is correct
26 Runtime error 716 ms 1048576 KB Execution killed with signal 9
27 Runtime error 872 ms 1048576 KB Execution killed with signal 9
28 Runtime error 844 ms 1048576 KB Execution killed with signal 9
29 Runtime error 834 ms 1048576 KB Execution killed with signal 9
30 Runtime error 790 ms 1048576 KB Execution killed with signal 9
31 Runtime error 839 ms 1048576 KB Execution killed with signal 9
32 Runtime error 829 ms 1048576 KB Execution killed with signal 9