# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101561 | dantoh000 | Tracks in the Snow (BOI13_tracks) | C++14 | 2097 ms | 31864 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
int main(){
int h,w;
scanf("%d%d",&h,&w);
char grid[h][w];
int nonempty = 0;
for (int i = 0; i < h; i++){
for (int j = 0; j < w; j++){
scanf(" %c",&grid[i][j]);
if (grid[i][j] != '.') nonempty++;
}
}
int num = 0;
bool vis[h][w];
int ans = 0;
while (num != nonempty){
char a = grid[0][0];
char b = a ^ 'F' ^ 'R';
memset(vis,0,sizeof(vis));
queue<ii> q;
q.push(ii(0,0));
vis[0][0] = 1;
grid[0][0] = b;
num = 1;
while(q.size()){
ii cur = q.front(); q.pop();
int x = cur.first, y = cur.second;
for (int k = 0; k < 4; k++){
int nx = x + dx[k], ny = y + dy[k];
if (nx >= 0 && nx < h && ny >= 0 && ny < w){
if (grid[nx][ny] == a && !vis[nx][ny]){
grid[nx][ny] = b;
vis[nx][ny] = 1;
num++;
q.push(ii(nx,ny));
}
}
}
}
ans++;
}
printf("%d",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |