이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define space <<' '<<
#define endl '\n'
#define inf 1e14
#define F first
#define S second
#define PB push_back
#define PF push_front
#define md(a) ((a+mod)%mod)
#define MP(a,b) make_pair(a,b)
#define MT(a,b,c) make_tuple(a,b,c)
typedef long long ll;
using namespace std;
template<typename t> using heap=
priority_queue<t,vector<t>,greater<t>>;
const int mx = 4e3+5;
deque<pair<int,int>> b;
deque<pair<int,int>> g;
char state[mx][mx];
bool seen[mx][mx];
int h,w;
bool c(int i,int j,char s){
if(i<0||h<=i) return 1;
if(j<0||w<=j) return 1;
if(seen[i][j])return 1;
if(state[i][j]==s){
g.push_front(MP(i,j));
return 1;
}
if (state[i][j]=='.')
return 1;
return 0;
}
int main(){
std::ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>h>>w;
for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
cin>>state[i][j];
int cnt=0;
g.PB(MP(h-1,w-1));
char cc=state[h-1][w-1];
while((!g.empty())||(!b.empty())){
cnt++;
while(!b.empty()){
auto p=b.back();
b.pop_back();
c(p.F+1,p.S,cc);
c(p.F-1,p.S,cc);
c(p.F,p.S+1,cc);
c(p.F,p.S-1,cc);
}
while(!g.empty()){
auto p=g.back();
g.pop_back();
bool k=1;
seen[p.F][p.S]=1;
k&=c(p.F+1,p.S,cc);
k&=c(p.F-1,p.S,cc);
k&=c(p.F,p.S+1,cc);
k&=c(p.F,p.S-1,cc);
if(!k)
b.push_front(p);
}
cc=((cc=='F')?'R':'F');
}
cout<<cnt;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |