#include "Memory_lib.h"
#include <bits/stdc++.h>
using namespace std;
int pw[25];
int val(int s, int e, int M) {
int val = 0, cnt = 1;
for(int i=s;i<e;i++) {
val += (M & pw[i]) * cnt;
cnt *= 2;
}
return val;
}
int Memory(int N, int M) {
int i;
pw[0] = 1;
for(i=1;i<=23;i++) pw[i] = pw[i-1] * 2;
int st = val(0, 7, M);
int pt = val(7, 14, M);
int cnt = val(14, 21, M);
int k = val(21, 22, M);
if(st==pt) {
char c = Get(st+1);
if(c=='<' || c=='[') {
if(st+1==N) return -2;
int v = st + pw[7] * (st+1) + pw[14] * 1 + pw[21] * (c=='<'?1:0);
return v;
}
else {
if(st-1<0) return -2;
int v = st + pw[7] * (st - 1) + pw[14] * 1 + pw[21] * (c=='>'?1:0);
return v;
}
}
char c = Get(pt+1);
if(c=='<'||c=='[') {
if(st < pt) {
if(pt+1==N) return -2;
int v = st + pw[7] * (pt + 1) + pw[14] * (cnt + 1) + pw[21] * k;
return v;
}
else { // pt < st case
if(cnt==1) {
int k2 = (c=='<'?1:0);
if(k==k2) {
if(st+1==N) return -1;
int v = st+1 + pw[7] * (st+1) + pw[14] * 0 + pw[21] * 0;
return v;
}
else return -2;
}
else {
if(pt-1<0) return -2;
int v = st + pw[7] * (pt - 1) + pw[14] * (cnt - 1) + pw[21] *k;
return v;
}
}
}
else { // c == '>' || c == ']'
if(st<pt) {
if(cnt==1) {
int k2 = (c=='>'?1:0);
if(k==k2) {
if(st+1==N) return -1;
int v = st+1 + pw[7] * (st+1) + pw[14] * 0 + pw[21] * 0;
return v;
}
else return -2;
}
else {
if(pt+1==N) return -2;
int v = st + pw[7] * (pt+1) + pw[14] * (cnt-1) + pw[21] * k;
return v;
}
}
else { // pt < st
if(pt-1<0) return -2;
int v = st + pw[7] * (pt-1) + pw[14] * (cnt+1) + pw[21] * k;
return v;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |