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 "Memory_lib.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int f(int pos, int lvl, int sz, int v)
{
return pos|(lvl<<7)|(sz<<13)|(v<<20);
}
int Memory(int N, int M)
{
int i, j;
if(N%2) return -2;
if(M==0) return f(1, 1, 0, 0);
int pos=M&((1<<7)-1), lvl=(M>>7)&((1<<6)-1), sz=(M>>13)&((1<<6)-1), v=(M>>20)&1;
if(lvl>N/2) return -1;
if(pos>N+1) return -2;
if(pos==0) return -2;
if(pos==N+1)
{
if(sz!=0) return -2;
return f(1, lvl+1, 0, 0);
}
//printf("%d %d %d %d %d\n", M, pos, lvl, sz, v);
char c=Get(pos);
if(c=='<')
{
sz++;
if(sz>N/2) return -2;
if(sz==lvl) v=0;
}
else if(c=='[')
{
sz++;
if(sz>N/2) return -2;
if(sz==lvl) v=1;
}
else if(c=='>')
{
if(sz==lvl)
{
if(v==1) return -2;
}
sz--;
if(sz<0) return -2;
}
else if(c==']')
{
if(sz==lvl)
{
if(v==0) return -2;
}
sz--;
if(sz<0) return -2;
}
pos++;
return f(pos, lvl, sz, v);
}
Compilation message (stderr)
memory.cpp: In function 'int Memory(int, int)':
memory.cpp:16:6: warning: unused variable 'i' [-Wunused-variable]
int i, j;
^
memory.cpp:16:9: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |