#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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1678 ms |
284048 KB |
Output is correct |
2 |
Correct |
1743 ms |
284032 KB |
Output is correct |
3 |
Correct |
1685 ms |
284024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1678 ms |
284048 KB |
Output is correct |
2 |
Correct |
1743 ms |
284032 KB |
Output is correct |
3 |
Correct |
1685 ms |
284024 KB |
Output is correct |
4 |
Correct |
1655 ms |
284020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1678 ms |
284048 KB |
Output is correct |
2 |
Correct |
1743 ms |
284032 KB |
Output is correct |
3 |
Correct |
1685 ms |
284024 KB |
Output is correct |
4 |
Correct |
1655 ms |
284020 KB |
Output is correct |
5 |
Correct |
1702 ms |
283960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1678 ms |
284048 KB |
Output is correct |
2 |
Correct |
1743 ms |
284032 KB |
Output is correct |
3 |
Correct |
1685 ms |
284024 KB |
Output is correct |
4 |
Correct |
1655 ms |
284020 KB |
Output is correct |
5 |
Correct |
1702 ms |
283960 KB |
Output is correct |
6 |
Correct |
1675 ms |
283984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1764 ms |
283968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1678 ms |
284048 KB |
Output is correct |
2 |
Correct |
1743 ms |
284032 KB |
Output is correct |
3 |
Correct |
1685 ms |
284024 KB |
Output is correct |
4 |
Correct |
1655 ms |
284020 KB |
Output is correct |
5 |
Correct |
1702 ms |
283960 KB |
Output is correct |
6 |
Correct |
1675 ms |
283984 KB |
Output is correct |
7 |
Correct |
1764 ms |
283968 KB |
Output is correct |
8 |
Correct |
1818 ms |
283948 KB |
Output is correct |
9 |
Correct |
1762 ms |
284024 KB |
Output is correct |