#include "Memory_lib.h"
#include <bits/stdc++.h>
using namespace std;
int f(int N,int col,int pos,int lst,int val){
return col*(N+2)*(N+2)*(N+2)+val*(N+2)*(N+2)+lst*(N+2)+pos;
}
int Memory(int N, int M) {
if(M==0) return f(N,0,1,1,0);
int pos=M%(N+2);M/=(N+2);
int lst=M%(N+2);M/=(N+2);
int val=M%(N+2);M/=(N+2);
//cout << pos << ' ' << lst << ' ' << val << ' ' << M << '\n';
if(M>=2 || pos==0) return 0;
if(pos==N+1) return -1;
if(pos==lst){
if(val!=0 || M!=0) return 0;
char c=Get(lst);
if(c=='>' || c==']') return f(N,(c=='>'),pos,pos-1,1);
else return f(N,(c=='<'),pos,pos+1,1);
}
else if(pos<lst){
if(lst==N+1) return -2;
char c=Get(lst);
if(c=='<' || c=='[') val++;
else val--;
if(val<0) return 0;
else if(val==0){
if(M!=(c=='>')) return -2;
else return f(N,0,pos+1,pos+1,0);
}
else return f(N,M,pos,lst+1,val);
}
else{
if(lst==0) return -2;
char c=Get(lst);
if(c=='>' || c==']') val++;
else val--;
if(val<0) return 0;
else if(val==0){
if(M!=(c=='<')) return -2;
else return f(N,0,pos+1,pos+1,0);
}
else return f(N,M,pos,lst-1,val);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2077 ms |
284108 KB |
Output is correct |
2 |
Correct |
1999 ms |
284400 KB |
Output is correct |
3 |
Correct |
1988 ms |
284440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2077 ms |
284108 KB |
Output is correct |
2 |
Correct |
1999 ms |
284400 KB |
Output is correct |
3 |
Correct |
1988 ms |
284440 KB |
Output is correct |
4 |
Correct |
2007 ms |
284292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2077 ms |
284108 KB |
Output is correct |
2 |
Correct |
1999 ms |
284400 KB |
Output is correct |
3 |
Correct |
1988 ms |
284440 KB |
Output is correct |
4 |
Correct |
2007 ms |
284292 KB |
Output is correct |
5 |
Correct |
1953 ms |
284440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2077 ms |
284108 KB |
Output is correct |
2 |
Correct |
1999 ms |
284400 KB |
Output is correct |
3 |
Correct |
1988 ms |
284440 KB |
Output is correct |
4 |
Correct |
2007 ms |
284292 KB |
Output is correct |
5 |
Correct |
1953 ms |
284440 KB |
Output is correct |
6 |
Correct |
1975 ms |
284168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1977 ms |
284216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2077 ms |
284108 KB |
Output is correct |
2 |
Correct |
1999 ms |
284400 KB |
Output is correct |
3 |
Correct |
1988 ms |
284440 KB |
Output is correct |
4 |
Correct |
2007 ms |
284292 KB |
Output is correct |
5 |
Correct |
1953 ms |
284440 KB |
Output is correct |
6 |
Correct |
1975 ms |
284168 KB |
Output is correct |
7 |
Correct |
1977 ms |
284216 KB |
Output is correct |
8 |
Correct |
2020 ms |
284200 KB |
Output is correct |
9 |
Correct |
2029 ms |
284168 KB |
Output is correct |