제출 #59578

#제출 시각아이디문제언어결과실행 시간메모리
59578WA_TLE게임 (IOI14_game)C++14
42 / 100
1084 ms66808 KiB
#include<deque> #include<queue> #include<vector> #include<algorithm> #include<iostream> #include<set> #include<cmath> #include<tuple> #include<string> #include<chrono> #include<functional> #include<iterator> #include<random> #include<unordered_set> #include<array> #include<map> #include<iomanip> #include<assert.h> #include<bitset> #include<stack> using namespace std; typedef long long int llint; typedef long double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase /* cout<<setprecision(20) cin.tie(0); ios::sync_with_stdio(false); */ const llint mod=998244353; const llint big=2.19e15+1; const long double pai=3.141592653589793238462643383279502884197; const long double eps=1e-15; template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;} template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;} llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);} llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;} template<class T> void SO(T& ve){sort(ve.begin(),ve.end());} template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());} template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();} template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();} #include"game.h" int n; int hen[1500][1500]={0};//直接の辺 -1->No 0->未定 1->想定解 2->Yes vector<bitset<1500>>kno;//可能性のある辺 mt19937 engine(13333); vector<int>rng; //O(n^2logn?) 自信がない //まずランダムな想定解を作る //想定解にかかってないなら無条件にNoを返していい //想定解にかかったなら想定解を変える vector<vector<int>>ki; bitset<1500>full; void initialize(int in){ full.flip(); n=in; //uとvをランダムに置き換える rng.res(n); int i,j; for(i=0;i<n;i++){rng[i]=i;} shuffle(rng.begin(),rng.end(),engine); //想定解を作る vector<bool>use(n); use[0]=true; int gen=0,oto=1; ki.res(n); while(oto<n){ int ne=engine()%n; if(use[ne]){gen=ne;} else{ki[gen].pub(ne);ki[ne].pub(gen);hen[gen][ne]=1;hen[ne][gen]=1;gen=ne;use[ne]=1;oto++;} } //cerr<<"de"; kno.res(n); for(i=0;i<n;i++){kno[i]=full;kno[i][i]=0;} } int hasEdge(int u,int v){ int i,j; u=rng[u]; v=rng[v]; if(hen[u][v]==0){kno[u][v]=0;kno[v][u]=0;hen[u][v]=-1;hen[v][u]=-1;return 0;} bitset<1500>ubis; ubis[u]=1; queue<int>que;que.push(u); while(que.size()>0){ int t=que.front();que.pop(); for(auto it:ki[t]){ if(ubis[it]){continue;} if(it==v){continue;} ubis[it]=1; que.push(it); } } int cou=ubis.count(); if(cou*2<n){cou=n-cou;swap(u,v);ubis.flip();} vector<int>zyu; zyu.reserve(n-cou); for(i=0;i<n;i++){if(!ubis[i]){zyu.pub(i);}} shuffle(zyu.begin(),zyu.end(),engine); //for(auto it:zyu){cerr<<it;}cerr<<endl; int au=-1,av=-1; for(i=0;i<zyu.size();i++){ int t=zyu[i];//v側 if(t==v){ubis[u]=0;}else{ubis[u]=1;} if(!((kno[t]&ubis).none())){ auto bi=kno[t]&ubis; av=t; for(j=0;j<n;j++){ if(bi[j]){ au=j; //cerr<<"u,v,au,av"<<u<<','<<v<<','<<au<<','<<av<<','<<endl; hen[u][v]=-1;hen[v][u]=-1; hen[au][av]=1;hen[av][au]=1; kno[u][v]=0;kno[v][u]=0; for(i=0;i<ki[u].size();i++){ if(ki[u][i]==v){ki[u][i]=ki[u].back();ki[u].pob();} } for(i=0;i<ki[v].size();i++){ if(ki[v][i]==u){ki[v][i]=ki[v].back();ki[v].pob();} } ki[au].pub(av); ki[av].pub(au); return 0; } } } } hen[u][v]=2;hen[v][u]=2;return 1; }

컴파일 시 표준 에러 (stderr) 메시지

game.cpp: In function 'void initialize(int)':
game.cpp:69:8: warning: unused variable 'j' [-Wunused-variable]
  int i,j;
        ^
game.cpp: In function 'int hasEdge(int, int)':
game.cpp:111:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<zyu.size();i++){
          ~^~~~~~~~~~~
game.cpp:124:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for(i=0;i<ki[u].size();i++){
              ~^~~~~~~~~~~~~
game.cpp:127:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for(i=0;i<ki[v].size();i++){
              ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...