Submission #592602

#TimeUsernameProblemLanguageResultExecution timeMemory
592602tqbfjotld기억 압축 (JOI15_memory)C++14
100 / 100
2359 ms284144 KiB
#include "Memory_lib.h" #include <bits/stdc++.h> using namespace std; int Memory(int N, int M) { int cur = M%N; int nowat = (M/N)%N; int rem = M/N/N; int dir = rem&1; rem>>=1; int typ = rem&1; rem >>=1; int height = rem; if (M==160){ //printf("%d %d %d %d %d\n",cur,nowat,dir,typ,height); } if (cur>=N || nowat>=N) return -2; assert(height>=0 && true); if (cur==nowat){ char res = Get(cur+1); //if (M==160)printf("received %c\n",res); if (res=='[' || res=='<'){ dir = 1; } else{ dir = 0; } if (res=='<' || res=='>'){ typ = 0; } else{ typ = 1; } nowat += dir?1:-1; if (nowat<0 || nowat>=N) return -2; height = 1; } else{ if (height==0) return -2; char res = Get(nowat+1); //if (M==100)printf("received %c\n",res); if (res=='[' || res=='<'){ if (dir==0){ height--; if (height==0){ if (typ==(res=='[')){ cur = cur+1; nowat = cur; dir = 0; typ = 0; height = 0; } else{ return -2; } } else{ nowat--; if (nowat<0) return -2; } } else{ height++; if (height>50) return -2; nowat++; if (nowat>=N) return -2; } } else{ if (dir==1){ height--; if (height==0){ if (typ==(res==']')){ cur = cur+1; nowat = cur; dir = 0; typ = 0; height = 0; } else{ return -2; } } else{ nowat++; if (nowat>=N) return -2; } } else{ height++; if (height>50) return -2; nowat--; if (nowat<0) return -2; } } } assert(height>=0); if (cur==N) return -1; //if (M==160) printf("%d %d %d %d %d end\n",cur,nowat,dir,typ,height); int retv = ((height*4+typ*2+dir)*N+nowat)*N+cur; if (retv>=(1<<22)) return -2; return retv; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...