이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int H, W;
char grid[4001][4001];
vector<pair<int,int>> dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
void bfs(queue<pair<int,int>> &from, queue<pair<int,int>> &to, char cc){
while(!from.empty()){
auto temp = from.front();
from.pop();
//grid[temp.first][temp.second] = '.';
int x = temp.first, y = temp.second;
for(auto [dx, dy] : dir){
if(x+dx > -1 && x+dx < H && y+dy > -1 && y+dy < W && grid[x+dx][y+dy] != '.'){
if(grid[x+dx][y+dy] != cc) to.push({x+dx, y+dy});
else from.push({x+dx, y+dy});
grid[x+dx][y+dy] = '.';
}
}
}
}
int main(){
cin>>H>>W;
for(int i = 0; i < H; i++){
string s; cin>>s;
for(int j = 0; j < W; j++){
grid[i][j] = s[j];
}
}
int x = 0, y = 0, ans = 0;
char cc = grid[0][0];
queue<pair<int,int>> F, R;
if(cc == 'F') F.push({0,0});
else R.push({0,0});
grid[0][0] = '.';
while(true){
if(cc == 'F' && F.empty()) break;
if(cc == 'R' && R.empty()) break;
if(cc == 'F')
bfs(F, R, cc);
else if(cc == 'R')
bfs(R, F, cc);
ans++;
if(cc == 'F') cc = 'R';
else if(cc == 'R') cc = 'F';
}
cout<<ans<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
tracks.cpp: In function 'int main()':
tracks.cpp:31:6: warning: unused variable 'x' [-Wunused-variable]
31 | int x = 0, y = 0, ans = 0;
| ^
tracks.cpp:31:13: warning: unused variable 'y' [-Wunused-variable]
31 | int x = 0, y = 0, ans = 0;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |