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 n;
int pack(int x, int y, int z, bool w) {
int res = (x << 15) | (y << 8) | (z << 1) | w;
if (res < 0 || res >= 4194304) return -2;
return res;
}
char get(int x) {
if (x < 0 || x >= n) return '[';
char t = Get(x + 1);
//printf("GET %d <- %c\n", x, t);
return t;
}
int Memory(int n, int m) {
::n = n;
if (n % 2) return -2;
int x = (m >> 15) & 127;
int y = (m >> 8) & 127;
int z = (m >> 1) & 127;
bool w = m & 1;
//printf("ENCOUNTER %d %d %d %d\n", x, y, z, w ? 1 : 0);
if (z > n) {
if (z < n + 4) { // step 2
//puts("STEP 2");
if (z == n + 1) {
char c = get(y - 1);
if (c == ']') z = n + 2;
else if (c == '>') z = n + 3;
else return -2;
return pack(x, y, z, w);
} else if (z == n + 2) {
char c = get(x);
if (c != '[') return -2;
} else if (z == n + 3) {
char c = get(x);
if (c != '<') return -2;
} else return -2;
x++;
y = x;
z = 0;
w = false;
return pack(x, y, z, w);
} else { // step 3
//puts("STEP 3");
if (z == n + 4) {
char c = get(y);
if (c == ']') z = n + 5;
else if (c == '>') z = n + 6;
else {
x = y;
w = false;
z = 0;
return pack(x, y, z, w);
}
return pack(x, y, z, w);
} else if (z == n + 5) {
char c = get(x);
if (c != '[') {
x = y;
w = false;
z = 0;
return pack(x, y, z, w);
}
} else if (z == n + 6) {
char c = get(x);
if (c != '<') {
x = y;
w = false;
z = 0;
return pack(x, y, z, w);
}
} else return -2;
x--;
y++;
z = n + 4;
if (x < 0 || y >= n) {
x = y;
w = false;
z = 0;
return pack(x, y, z, w);
}
return pack(x, y, z, w);
}
} else {
if (!w) { // step 1
//puts("STEP 1");
if (x == y || z) {
if (y >= n) {
if (z) return -2;
w = true;
z = 0;
return pack(x, y, z, w);
}
char c = get(y);
if (c == '[' || c == '<') z++;
else z--;
if (z < 0) {
w = true;
z = 0;
return pack(x, y, z, w);
}
y++;
return pack(x, y, z, w);
} else {
z = n + 1;
return pack(x, y, z, w);
}
} else { // step 4
//puts("STEP 4");
if (x == 0 && y == n) return -1;
if (!x) return -2;
x--;
char c = get(x);
if (c == ']' || c == '>') z++;
else z--;
if (z < 0) {
z = n + 4;
return pack(x, y, z, w);
}
return pack(x, y, z, w);
}
}
}
# | 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... |