이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>pii;
int32_t main(){
//ios::sync_with_stdio(0);
//cin.tie(0);
int n,m;
cin >> n >> m;
string arr[n];
for(int x=0;x<n;x++){
cin >> arr[x];
}
queue<pii>q;
queue<pii>q2;
int counter=0;
bool visited[n+5][m+5];
memset(visited,0,sizeof(visited));
bool amos=true;
//true is R, false is F
if(arr[0][0]=='F') amos=false;
if(amos){
q.push({0,0});
visited[0][0]=true;
}
else{
q2.push({0,0});
visited[0][0]=true;
}
pii dir[4]={
{1,0},
{-1,0},
{0,1},
{0,-1},
};
while(!q.empty()||!q2.empty()){
if(amos){
while(!q.empty()){
pii cur=q.front();
q.pop();
for(auto it:dir){
int newx=cur.first+it.first;
int newy=cur.second+it.second;
if(newx<0||newy<0||newy>=n||newy>=m) continue;
if(visited[newx][newy]) continue;
if(arr[newx][newy]=='.') continue;
visited[newx][newy]=true;
if(arr[newx][newy]=='R'){
q.push({newx,newy});
}
else{
q2.push({newx,newy});
}
}
}
amos=false;
}
else{
while(!q2.empty()){
pii cur=q2.front();
//cout << cur.first << " " << cur.second << " visit\n";
q2.pop();
for(auto it:dir){
int newx=cur.first+it.first;
int newy=cur.second+it.second;
if(newx<0||newy<0||newy>=n||newy>=m) continue;
if(visited[newx][newy]) continue;
if(arr[newx][newy]=='.') continue;
visited[newx][newy]=true;
if(arr[newx][newy]=='R'){
q.push({newx,newy});
}
else{
q2.push({newx,newy});
}
}
}
amos=true;
}
counter++;
//cout << counter << "\n";
}
cout << counter;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |