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"
int Memory(int N, int M) {
int check = M & 127;
int pos = (M >> 7) & 127;
int sum = (M >> 14) & 127;
int type = (M >> 21);
if (N <= pos) return -1;
if (check == N) {
char c = Get(pos + 1);
if (c == '<' || c == '[') ++sum;
else --sum;
if (sum < 0) return -2;
if (++pos == N) {
if (sum != 0) return -2;
return -1;
}
int ret = (check | (pos << 7) | (sum << 14) | (type << 21));
if ((1 << 22) <= ret) return -1;
return ret;
}
switch (Get(pos + 1)) {
case '<':
if (check == pos) type = 0;
else if (check < pos) ++sum;
break;
case '>':
if (check == pos) {
pos = check++;
sum = 0;
break;
}
else if (check < pos) if (--sum < 0) {
if (type != 0) return -2;
pos = check++;
sum = 0;
break;
}
break;
case '[':
if (check == pos) type = 1;
else if (check < pos) ++sum;
break;
case ']':
if (check == pos) {
pos = check++;
sum = 0;
break;
}
else if (check < pos) if (--sum < 0) {
if (type != 1) return -2;
pos = check++;
sum = 0;
break;
}
break;
}
if (check == N) {
pos = 0;
sum = 0;
}
else if (++pos == N) return -2;
int ret = (check | (pos << 7) | (sum << 14) | (type << 21));
if ((1 << 22) <= ret) return -1;
return ret;
}
# | 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... |