이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<queue>
#include<set>
using namespace std;
int t[3010][3010];
int il[3010][3010];
//priority_queue< pair<int,pair<pair<int,int>,bool> > >pq;
set< pair<int,pair<pair<int,int>,bool> > >s;
set< pair<int,pair<pair<int,int>,bool> > >::iterator it;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,licz=0,x,y,kt;
string ss;
cin>>n>>m;
for(int i=2;i<=n+1;i++){
cin>>ss;
for(int j=2;j<=m+1;j++){
if(ss[j-2]=='R')t[i][j]=1;
if(ss[j-2]=='G')t[i][j]=2;
if(ss[j-2]=='W')t[i][j]=3;
}
}
for(int i=2;i<=n+1;i++){
for(int j=2;j<=m+1;j++){
if(t[i][j]==1){
if(t[i][j+1]==2&&t[i][j+2]==3){
il[i][j]++;
il[i][j+1]++;
il[i][j+2]++;
licz++;
}
if(t[i+1][j]==2&&t[i+2][j]==3){
il[i][j]++;
il[i+1][j]++;
il[i+2][j]++;
licz++;
}
}
}
}
//cout<<licz<<'\n';
for(int i=2;i<=n+1;i++){
for(int j=2;j<=m+1;j++){
if(t[i][j]==1){
if(t[i][j+1]==2&&t[i][j+2]==3){
s.insert({il[i][j]+il[i][j+1]+il[i][j+2],{{i,j},0}});
}
if(t[i+1][j]==2&&t[i+2][j]==3){
s.insert({il[i][j]+il[i+1][j]+il[i+2][j],{{i,j},1}});
}
}
}
}
while(1){
it=s.begin();
if((*it).first<=3)break;
x=(*it).second.first.first;
y=(*it).second.first.second;
kt=(*it).second.second;
s.erase(it);
if(kt==0){
licz--;
if(t[x+1][y]==2&&t[x+2][y]==3){
s.erase({il[x][y]+il[x+1][y]+il[x+2][y],{{x,y},1}});
s.insert({il[x][y]+il[x+1][y]+il[x+2][y]-1,{{x,y},1}});
}
if(t[x-1][y+1]==1&&t[x+1][y+1]==3){
s.erase({il[x][y+1]+il[x+1][y+1]+il[x-1][y+1],{{x-1,y+1},1}});
s.insert({il[x][y+1]+il[x+1][y+1]+il[x-1][y+1]-1,{{x-1,y+1},1}});
}
if(t[x-1][y+2]==2&&t[x-2][y+2]==1){
s.erase({il[x][y+2]+il[x-1][y+2]+il[x-2][y+2],{{x-2,y+2},1}});
s.insert({il[x][y+2]+il[x-1][y+2]+il[x-2][y+2]-1,{{x-2,y+2},1}});
}
il[x][y]--;
il[x][y+1]--;
il[x][y+2]--;
s.insert({il[x][y]+il[x][y+1]+il[x][y+2],{{x,y},0}});
}
if(kt==1){
licz--;
if(t[x][y+1]==2&&t[x][y+2]==3){
s.erase({il[x][y]+il[x][y+1]+il[x][y+2],{{x,y},0}});
s.insert({il[x][y]+il[x][y+1]+il[x][y+2]-1,{{x,y},0}});
}
if(t[x+1][y-1]==1&&t[x+1][y+1]==3){
s.erase({il[x+1][y]+il[x+1][y+1]+il[x+1][y-1],{{x+1,y-1},0}});
s.insert({il[x+1][y]+il[x+1][y+1]+il[x+1][y-1]-1,{{x+1,y-1},0}});
}
if(t[x+2][y-1]==2&&t[x+2][y-2]==1){
s.erase({il[x+2][y]+il[x+2][y-1]+il[x+2][y-2],{{x+2,y-2},0}});
s.insert({il[x+2][y]+il[x+2][y-1]+il[x+2][y-2]-1,{{x+2,y-2},0}});
}
il[x][y]--;
il[x+1][y]--;
il[x+2][y]--;
s.insert({il[x][y]+il[x+1][y]+il[x+2][y],{{x,y},1}});
}
}
cout<<licz;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |