# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
421546 | 2021-06-09T08:54:53 Z | 장태환(#7576) | Collapse (JOI18_collapse) | C++17 | 15000 ms | 3524 KB |
#include "collapse.h" #include <string.h> using namespace std; int st[5001]; int e[5100]; int d[5100]; unsigned int vis[5200>>6]; vector<pair<int,int>>q[5100]; int sta[5100]; int siz; vector<int> simulateCollapse(int N,vector<int> T,vector<int> X,vector<int> Y,vector<int> W,vector<int> P) { memset(vis,-1,sizeof(vis)); vector<int>ann=vector<int>(W.size(), 0); int i; int M=T.size(); for(i=0;i<M;i++) { if(T[i]) { e[X[i]]--; e[Y[i]]--; } else { e[X[i]]++; e[Y[i]]++; st[X[i]+1]=max(st[X[i]+1],e[X[i]]); st[Y[i]+1]=max(st[Y[i]+1],e[Y[i]]); } } for(i=1;i<=N;i++) { st[i]+=st[i-1]; e[i]=st[i]; } int C=P.size(); for(i=0;i<C;i++) { q[W[i]].push_back({P[i],i}); } for(i=0;i<M;i++) { int ty=T[i]; int s=X[i]; int en=Y[i]; register int j; if(ty) { int fi=st[s]; int se=e[s]; for(j=fi;j<se;j++) { if(d[j]==en) { d[j]=d[se-1]; break; } } e[s]--; fi=st[en]; se=e[en]; for(j=fi;j<se;j++) { if(d[j]==s) { d[j]=d[se-1]; break; } } e[en]--; } else { d[e[s]++]=en; d[e[en]++]=s; } for(j=0;j<q[i].size();j++) { int div=q[i][j].first+1; int cur=0; int an=0; for(j=0;j<div;j++) { vis[j>>5]^=1U<<(j&31); } while(cur<div) { an++; sta[siz++]=cur; while(siz) { int cou=sta[--siz]; register int k; for(k=st[cou];k<e[cou];k++) { if(!(vis[d[k]>>5]&(1U<<(d[k]&31)))) { vis[d[k]>>5]|=1U<<(d[k]&31); sta[siz++]=d[k]; } } } cur++; while((vis[cur>>5]&(1U<<(cur&31)))) { cur++; } } for(j=div;j<N;j++) { vis[j>>5]^=1U<<(j&31); } cur=N-1; while(cur>=div) { an++; sta[siz++]=cur; while(siz) { int cou=sta[--siz]; register int k; for(k=st[cou];k<e[cou];k++) { if(!(vis[d[k]>>5]&(1U<<(d[k]&31)))) { vis[d[k]>>5]|=1U<<(d[k]&31); sta[siz++]=d[k]; } } } cur--; while(cur&&(vis[cur>>5]&(1U<<(cur&31)))) { cur--; } } ann[q[i][j].second]=an; } } return ann; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 780 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 15082 ms | 3524 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 15065 ms | 3524 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 780 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |