Submission #1169633

#TimeUsernameProblemLanguageResultExecution timeMemory
1169633lighton게임 (APIO22_game)C++20
100 / 100
1412 ms214112 KiB
#include "game.h" #include <bits/stdc++.h> #define all(v) v.begin(),v.end() #define forf(i,s,e) for(int i = s; i<=e; i++) #define forb(i,s,e) for(int i = s; i>=e; i--) #define idx(i,v) lower_bound(all(v),i)-v.begin() #define comp(v) v.erase(unique(all(v)),v.end()) #define sz(v) (int)v.size() #define pb push_back #pragma GCC optimize("O3, Ofast, unroll-loops") using namespace std; int N,K; int S[1000001][31]; set<pair<int,int> > SET; int chk[1000001][31]; vector<pair<int,int> > adj[1000001],radj[1000001]; void dnc(int dep, int s, int e){ if(s>e) return; int m = s+e>>1; forf(i,2*s,2*m) S[i][dep] = 1; forf(i,2*m+1,2*e+1) S[i][dep] = 2; dnc(dep+1,s,m-1), dnc(dep+1,m+1,e); } int f = 0; int cnt = 0; void upd(int now, int h){ if(h!= -1) { assert(h<21); if(chk[now][h]) return; chk[now][h] = 1; } if(f==1) return; for(auto &[i,p] : adj[now]){ cnt++; while(p<30 && S[i][p] == S[now][p] && S[i][p] != 0) p++; if((S[now][p]&2) && (S[i][p]&1)) {f = 1; return;} if(S[i][p] == 1 && S[now][p] == 0){ while(p<30 && S[i][p] == 1) S[now][p] = 1, p++; upd(now,p); return; } } for(auto &[i,p] : radj[now]){ cnt++; while(p<30 && S[i][p] == S[now][p] && S[i][p] != 0) p++; if((S[now][p]&1) && (S[i][p]&2)) {f = 1; return;} if(S[i][p] == 2 && S[now][p] == 0){ while(p<30 && S[i][p] == 2) S[now][p] = 2, p++; upd(now,p); return; } } for(auto &[i,p] : adj[now]){ cnt++; if(S[now][p] == 2 && S[i][p] == 0){ while(p<30 && S[now][p] == 2) S[i][p] = 2, p++; upd(i,p); if(f==1) return; } } for(auto &[i,p] : radj[now]){ cnt++; assert(cnt < 52*(600000+500000)*4); if(S[now][p] == 1 && S[i][p] == 0){ while(p<30 && S[now][p] == 1) S[i][p] = 1, p++; upd(i,p); if(f==1) return; } } } void init(int n, int k){ N =n, K=k; dnc(0,0,k-1); forf(i,0,2*k-2){ int p = 0; while(p<30 && S[i][p] == S[i+1][p] && S[i][p] != 0) p++; adj[i].pb({i+1,p}), radj[i+1].pb({i,p}); } } int add_teleporter(int u, int v) { if(u < K) u = 2*u+1; else u += 2*K; if(v < K) v = 2*v; else v += 2*K; if(u==v) return 0; if(SET.find({u,v}) != SET.end()) return 0; else SET.insert({u,v}); int p = 0; while(p<30 && S[u][p] == S[v][p] && S[u][p] != 0) p++; if((S[u][p]&2) && (S[v][p]&1)) {f = 1; return 1; } if(S[u][p] == 2 && S[v][p] == 0){ while(p<30 && S[u][p] == 2) S[v][p] = 2, p++; adj[u].pb({v,p}), radj[v].pb({u,p}); upd(v,p); } else if(S[v][p] == 1 && S[u][p] == 0){ while(p<30 && S[v][p] == 1) S[u][p] = 1, p++; adj[u].pb({v,p}), radj[v].pb({u,p}); upd(u,p); } else adj[u].pb({v,p}), radj[v].pb({u,p}); if(f==1) return 1; return 0; }

Compilation message (stderr)

game.cpp:11:47: warning: bad option '-f Ofast' to pragma 'optimize' [-Wpragmas]
   11 | #pragma GCC optimize("O3, Ofast, unroll-loops")
      |                                               ^
game.cpp:11:47: warning: bad option '-f unroll-loops' to pragma 'optimize' [-Wpragmas]
game.cpp:18:31: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
   18 | void dnc(int dep, int s, int e){
      |                               ^
game.cpp:18:31: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
game.cpp:28:24: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
   28 | void upd(int now, int h){
      |                        ^
game.cpp:28:24: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
game.cpp:74:23: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
   74 | void init(int n, int k){
      |                       ^
game.cpp:74:23: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
game.cpp:84:32: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
   84 | int add_teleporter(int u, int v) {
      |                                ^
game.cpp:84:32: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
#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...