Submission #1085762

#TimeUsernameProblemLanguageResultExecution timeMemory
1085762alexander707070Game (APIO22_game)C++17
60 / 100
4088 ms47028 KiB
#include<bits/stdc++.h> #define MAXN 300007 using namespace std; int bucket_sz; int n,k,bucket[MAXN]; int from[MAXN],to[MAXN]; int mins[MAXN],maxs[MAXN]; int li[MAXN],tim,cnt[MAXN]; vector<int> v[MAXN],r[MAXN],news; void init(int N,int K){ n=N; k=K; bucket_sz=int(sqrt(k))+1; for(int i=1;i<=k;i++){ bucket[i]=i/bucket_sz+1; } for(int i=1;i<=k;i++){ mins[i]=maxs[i]=bucket[i]; from[i]=to[i]=i; } for(int i=k+1;i<=n;i++){ from[i]=n+1; to[i]=0; mins[i]=800; maxs[i]=0; } } int dfs(int x,int val,int val2){ li[x]=tim; if(maxs[x]>val)return 0; if(maxs[x]==val and (mins[x]!=maxs[x] or to[x]>=val2))return 0; if(mins[x]==maxs[x]){ to[x]=val2; if(from[x]<=to[x] or mins[x]<val){ if(from[x]<to[x] or x>k)return 1; } }else{ maxs[x]=val; if(mins[x]<maxs[x])return 1; if(mins[x]==maxs[x])news.push_back(x); } for(int i=0;i<v[x].size();i++){ if(li[v[x][i]]==tim)continue; if(dfs(v[x][i],val,val2)==1)return 1; } return 0; } int dfs2(int x,int val,int val2){ li[x]=tim; if(mins[x]<val)return 0; if(mins[x]==val and (mins[x]!=maxs[x] or from[x]<=val2))return 0; if(mins[x]==maxs[x]){ from[x]=val2; if(from[x]<=to[x] or val<maxs[x]){ if(from[x]<to[x] or x>k)return 1; } }else{ mins[x]=val; if(mins[x]<maxs[x])return 1; if(mins[x]==maxs[x])news.push_back(x); } for(int i=0;i<r[x].size();i++){ if(li[r[x][i]]==tim)continue; if(dfs2(r[x][i],val,val2)==1)return 1; } return 0; } void dfs3(int x){ li[x]=tim; if(from[x]!=n+1)return; for(int i=0;i<v[x].size();i++){ if(li[v[x][i]]==tim)continue; dfs3(v[x][i]); from[x]=min(from[x],from[v[x][i]]); } } int dfs4(int x){ li[x]=tim; if(to[x]!=0)return 0; int z=0; for(int i=0;i<r[x].size();i++){ if(li[r[x][i]]==tim)continue; z=dfs4(r[x][i]); to[x]=max(to[x],to[r[x][i]]); if(z==1)return 1; } if(from[x]<=to[x])return 1; return 0; } int add_teleporter(int a, int b){ a++; b++; if(a==b){ if(a<=k)return 1; return 0; } news.clear(); v[a].push_back(b); tim++; int z=dfs(b,maxs[a],to[a]); if(z==1)return 1; r[b].push_back(a); tim++; z=dfs2(a,mins[b],from[b]); if(z==1)return 1; tim++; for(int i:news){ if(li[i]!=tim)dfs3(i); } tim++; for(int i:news){ if(li[i]!=tim){ if(dfs4(i)==1)return 1; } } return 0; } /*int main(){ init(6, 3); cout<<add_teleporter(3, 4); cout<<add_teleporter(5, 0); cout<<add_teleporter(4, 5); cout<<add_teleporter(5, 3); cout<<add_teleporter(1, 4); return 0; }*/

Compilation message (stderr)

game.cpp: In function 'int dfs(int, int, int)':
game.cpp:54:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
game.cpp: In function 'int dfs2(int, int, int)':
game.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for(int i=0;i<r[x].size();i++){
      |                 ~^~~~~~~~~~~~
game.cpp: In function 'void dfs3(int)':
game.cpp:95:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
game.cpp: In function 'int dfs4(int)':
game.cpp:109:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     for(int i=0;i<r[x].size();i++){
      |                 ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...