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"
namespace {
int get_p(int x) { return x % 100; }
int get_phase(int x) { return x / 100 % 2; }
int get_p2(int x) { return x / 200 % 100 - 1; }
int get_depth(int x) { return x / 20000 % 100; }
char get_ch(int x) { return x / 2000000? '<': '['; }
int make(int p, int phase, int p2, int depth, int c) {
c = c == '<' || c == '>';
return p + phase * 100 + (p2 + 1) * 200 + depth * 20000 + c * 2000000;
}
char get(int i, int phase, int len) {
if (!phase)
return Get(i+1);
char c = Get(len - i);
switch (c) {
case '<': return '>';
case '>': return '<';
case '[': return ']';
case ']': return '[';
}
return -1;
}
}
int Memory(int N, int M) {
int p = get_p(M);
int phase = get_phase(M);
int p2 = get_p2(M);
int depth = get_depth(M);
char ch = get_ch(M);
if (p >= N)
return 0;
if (p2 >= p)
return 0;
if (p2 == -1) {
char c = get(p, phase, N);
if (c == '[' || c == '<') {
if (p == N-1)
return -2;
else
return make(p+1, phase, -1, 0, 0);
}
if (p == 0)
return -2;
return make(p, phase, p-1, 0, c);
}
char c = get(p2, phase, N);
if (c == ']' || c == '>') {
if (p2 == 0)
return -2;
return make(p, phase, p2-1, depth+1, ch);
}
if (depth) {
if (p2 == 0)
return -2;
return make(p, phase, p2-1, depth-1, ch);
}
if (c != ch)
return -2;
if (p == N-1) {
if (phase == 0)
return make(0, 1, -1, 0, 0);
else
return -1;
}
return make(p+1, phase, -1, 0, 0);
}
# | 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... |