이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define VIS(it,con) for(auto it=con.begin();it!=con.end();++it)
#define pob pop_back
#define pf push_front
#define pof pop_front
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mid (l+r>>1)
#define lch (idx*2+1)
#define rch (idx*2+2)
/*****************************************************************************/
#include<bits/stdc++.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
#define REP(i,j,k) for(register int i=(j);i<(k);++i)
#define RREP(i,j,k) for(register int i=int(j)-1;i>=(k);--i)
#define ALL(a) a.begin(),a.end()
#define pb push_back
#define f first
#define s second
#define endl '\n'
// #define __debug
#ifdef __debug
#define IOS (void)0
#define de(...) cerr<<__VA_ARGS__
#define ar(a,s,t) {REP(__i,s,t)de(a[__i]<<' ');de(endl);}
#else
#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
#define de(...) (void)0
#define ar(...) (void)0
#endif
/***********************************default***********************************/
const int maxm=2e5+9,maxr=809,maxn=maxr*maxr,inf=1ll<<60,dx[4]={1,0,0,-1},dy[4]={0,-1,1,0};
int m,n,r,c,cl=0,u[maxn],t[1<<4],fa[maxn],sz[maxn],p[maxn],fin[maxn],vis[maxn];
string d;
map<char,int>mp;
void init(int k){REP(i,0,k)fa[i]=i,sz[i]=1;}
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void unite(int x,int y){
if(sz[x]>sz[y])swap(x,y);
fa[x]=y,sz[y]+=sz[x];
}
bool ok(pii x){return 0<=x.f&&x.f<r&&0<=x.s&&x.s<c;}
main(){
IOS;
mp['N']=0,mp['E']=1,mp['W']=2,mp['S']=3;
cin>>m>>r>>c,n=r*c;
cin>>d;
REP(i,0,r)REP(j,0,c)cin>>u[i*c+j];
d+=d,m+=m;
REP(i,0,1<<4){
int le,ri=0;
while(ri<m){
le=ri;
while(ri<m&&((i>>mp[d[ri]])&1))++ri;
MAX(t[i],ri-le);
++ri;
}
if(t[i]==m)t[i]=inf;
}
init(n);
REP(i,0,n)p[i]=i;
pii res={n,0};
for(int z=1;z<n;z<<=1){
REP(i,0,r){
REP(j,0,c){
++cl;
int id=i*c+j,b=find(id);
if(u[id]&&p[b]==id&&!fin[p[b]]){
queue<pii>q;
q.push({i,j}),vis[id]=cl;
int cnt=0;
while(!q.empty()){
pii h=q.front();q.pop();
++cnt;
REP(k,0,4){
pii nh={h.f+dx[k],h.s+dy[k]};
int nid=nh.f*c+nh.s;
if(ok(nh)&&u[nid]&&vis[nid]!=cl){
int msk=0;
REP(l,0,4){
pii rh={nh.f+dx[l],nh.s+dy[l]};
if(ok(rh)&&vis[rh.f*c+rh.s]==cl)msk|=1<<3-l;
}
if(u[nid]<=t[msk]){
vis[nid]=cl;
q.push(nh);
int nb=find(nid);
if(b!=nb){
p[b]=p[nb];
unite(b,nb);
goto bot;
}
}
}
}
}
fin[id]=1;
if(cnt==res.f)res.s+=cnt;
else if(cnt<res.f)res={cnt,cnt};
}
bot:;
}
}
}
cout<<res.f<<" "<<res.s<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
virus.cpp:55:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
virus.cpp: In function 'int main()':
virus.cpp:94:51: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
if(ok(rh)&&vis[rh.f*c+rh.s]==cl)msk|=1<<3-l;
~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |