# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
778513 | bachhoangxuan | Stray Cat (JOI20_stray) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
int A,B,p=-1;
int up=0,st=0,num=0;
int f[81];
} // namespace
void Init(int A, int B) {
::A = A;
::B = B;
for(int i=0;i<81;i++) f[i]=-2;
f[39]=-1;f[43]=0;f[32]=-1;f[13]=1;
f[16]=-1;f[31]=0;f[67]=-1;f[64]=1;
}
int Move(std::vector<int> y) {
auto g = [&](int val,int x){
p=(val==-1?p:val);
if(val!=-1) assert((to_string(x),y[val]));
return val;
};
if(A==2){
int d=y[0]+y[1]+(st!=0);st++;
if(up) return g(d>=3?(p^1):y[1],0);
if(d==1) return up=true,g(st!=1?-1:y[1],1);
if(d>2) return up=true,g(y[0]==0 || y[1]==0?-1:(y[1]+(p==1)>y[0]+(p==0)?0:1),2);
num=num*3+y[1]+(p==1);
if(st<=3) return g(!y[0],3);
else return up=true,g(f[num],4);
}
else for(int i=0;i<3;i++) if(y[i] && !y[(i+2)%3]) return i;
return -2;
}