Submission #90197

#TimeUsernameProblemLanguageResultExecution timeMemory
90197nikolapesic2802Cop and Robber (BOI14_coprobber)C++14
0 / 100
20 ms19968 KiB
#include <bits/stdc++.h> #include "coprobber.h" using namespace std; #define pb push_back int lim=MAX_N*MAX_N; vector<vector<int> > graf(2*lim); vector<vector<int> > graph(MAX_N); int convert(int i,int j,int k) { int br=i+j*MAX_N+k*lim; return br; } vector<int> winlose(2*lim); vector<int> dosada(2*lim); vector<int> visited(2*lim); vector<int> value(2*lim); int convert_back(int tr) { int k=0,j=0; while(tr>=lim) tr-=lim,k=1; while(tr>=MAX_N) tr-=MAX_N,j++; //printf("%i %i %i\n",tr,j,k); return tr; } int dfs(int tr) { //printf("Usao za "); //convert_back(tr); //printf("Usao za %i\n",tr); visited[tr]=1; assert(winlose[tr]==0); if(tr>=lim) { for(auto p:graf[tr]) { if(winlose[p]==1) continue; if(value[p]!=0) { if(value[p]==-1){ visited[tr]=2; return value[tr]=-1; } continue; } if(visited[p]==1){ //printf("Vracam -1 za "); //convert_back(tr); visited[tr]=2; return value[tr]=-1; } int val=dfs(p); if(val==-1){ visited[tr]=2; //printf("Nasao losing poziciju za "); //convert_back(tr); return value[tr]=-1; } } //printf("Vracam 1 za "); //convert_back(tr); return value[tr]=1; } else { for(auto p:graf[tr]) { if(winlose[p]==1){ //printf("Nasao win poziciju za "); //convert_back(tr); return p; } if(value[p]!=0) { if(value[p]!=-1){ visited[tr]=2; return value[tr]=p; } continue; } if(visited[p]==1) continue; int val=dfs(p); if(val!=-1){ visited[tr]=2; //printf("Nasao pobedu za "); //convert_back(tr); return value[tr]=p; } } //printf("Vracam -1 za "); //convert_back(tr); visited[tr]=2; return value[tr]=-1; } } int pozicija=0; int start(int N, bool A[MAX_N][MAX_N]) { for(int i=0;i<N;i++) for(int j=0;j<N;j++) if(A[i][j]) graph[i].pb(j); for(int i=0;i<N;i++) { for(int j=0;j<N;j++) { if(i==j) { winlose[convert(i,j,0)]=1; winlose[convert(i,j,1)]=1; continue; } //printf("%i %i %i->%i %i %i: %i->%i\n",i,j,0,i,j,1,convert(i,j,0),convert(i,j,1)); graf[convert(i,j,0)].pb(convert(i,j,1)); for(auto p:graph[i]) { //printf("%i %i %i->%i %i %i: %i->%i\n",i,j,0,p,j,1,convert(i,j,0),convert(p,j,1)); graf[convert(i,j,0)].pb(convert(p,j,1)); } for(auto p:graph[j]) { //printf("%i %i %i->%i %i %i: %i->%i\n",i,j,1,i,p,0,convert(i,j,1),convert(i,p,0)); graf[convert(i,j,1)].pb(convert(i,p,0)); } } } bool test=true; for(int i=2;i<3;i++) { //printf("I JEDNOAKO %i*****************\n",i); fill(visited.begin(),visited.end(),0); fill(value.begin(),value.end(),0); if(dfs(convert(0,i,0))==-1) test=false; } if(test) return 0; return -1; } int nextMove(int R) { visited=dosada; fill(value.begin(),value.end(),0); //printf("Trenutna pozicija: %i ",pozicija); pozicija=convert_back(dfs(convert(pozicija,R,0))); //printf("%i, idem na polje %i.\n",R,pozicija); dosada[convert(pozicija,R,0)]=1; return pozicija; }

Compilation message (stderr)

coprobber.cpp: In function 'int convert_back(int)':
coprobber.cpp:20:9: warning: variable 'k' set but not used [-Wunused-but-set-variable]
     int k=0,j=0;
         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...