Submission #147444

# Submission time Handle Problem Language Result Execution time Memory
147444 2019-08-29T14:40:46 Z username Virus Experiment (JOI19_virus) C++14
100 / 100
447 ms 34168 KB
#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<2*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]]){
					assert(sz[b]>=z);
					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;
}

Compilation message

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:95: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
1 Correct 9 ms 636 KB Output is correct
2 Correct 385 ms 31864 KB Output is correct
3 Correct 309 ms 32284 KB Output is correct
4 Correct 272 ms 29852 KB Output is correct
5 Correct 258 ms 34168 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 350 ms 30240 KB Output is correct
8 Correct 149 ms 13852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 14 ms 764 KB Output is correct
3 Correct 61 ms 924 KB Output is correct
4 Correct 15 ms 888 KB Output is correct
5 Correct 59 ms 888 KB Output is correct
6 Correct 60 ms 924 KB Output is correct
7 Correct 2 ms 452 KB Output is correct
8 Correct 60 ms 888 KB Output is correct
9 Correct 3 ms 508 KB Output is correct
10 Correct 18 ms 888 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 508 KB Output is correct
13 Correct 51 ms 924 KB Output is correct
14 Correct 55 ms 924 KB Output is correct
15 Correct 47 ms 924 KB Output is correct
16 Correct 52 ms 924 KB Output is correct
17 Correct 32 ms 760 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
19 Correct 60 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 636 KB Output is correct
2 Correct 385 ms 31864 KB Output is correct
3 Correct 309 ms 32284 KB Output is correct
4 Correct 272 ms 29852 KB Output is correct
5 Correct 258 ms 34168 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 350 ms 30240 KB Output is correct
8 Correct 149 ms 13852 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 14 ms 764 KB Output is correct
11 Correct 61 ms 924 KB Output is correct
12 Correct 15 ms 888 KB Output is correct
13 Correct 59 ms 888 KB Output is correct
14 Correct 60 ms 924 KB Output is correct
15 Correct 2 ms 452 KB Output is correct
16 Correct 60 ms 888 KB Output is correct
17 Correct 3 ms 508 KB Output is correct
18 Correct 18 ms 888 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 508 KB Output is correct
21 Correct 51 ms 924 KB Output is correct
22 Correct 55 ms 924 KB Output is correct
23 Correct 47 ms 924 KB Output is correct
24 Correct 52 ms 924 KB Output is correct
25 Correct 32 ms 760 KB Output is correct
26 Correct 4 ms 504 KB Output is correct
27 Correct 60 ms 888 KB Output is correct
28 Correct 369 ms 27240 KB Output is correct
29 Correct 379 ms 27128 KB Output is correct
30 Correct 337 ms 27176 KB Output is correct
31 Correct 347 ms 27164 KB Output is correct
32 Correct 288 ms 27512 KB Output is correct
33 Correct 329 ms 31864 KB Output is correct
34 Correct 379 ms 26744 KB Output is correct
35 Correct 247 ms 20604 KB Output is correct
36 Correct 343 ms 28844 KB Output is correct
37 Correct 338 ms 27000 KB Output is correct
38 Correct 292 ms 26864 KB Output is correct
39 Correct 447 ms 33052 KB Output is correct
40 Correct 441 ms 33156 KB Output is correct
41 Correct 375 ms 31916 KB Output is correct
42 Correct 397 ms 29296 KB Output is correct
43 Correct 363 ms 30388 KB Output is correct
44 Correct 166 ms 13960 KB Output is correct