Submission #677453

# Submission time Handle Problem Language Result Execution time Memory
677453 2023-01-03T11:36:17 Z mjhmjh1104 None (JOI15_memory) C++17
100 / 100
2416 ms 284164 KB
#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
1 Correct 2249 ms 283996 KB Output is correct
2 Correct 2333 ms 284108 KB Output is correct
3 Correct 2416 ms 283956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2249 ms 283996 KB Output is correct
2 Correct 2333 ms 284108 KB Output is correct
3 Correct 2416 ms 283956 KB Output is correct
4 Correct 2340 ms 284012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2249 ms 283996 KB Output is correct
2 Correct 2333 ms 284108 KB Output is correct
3 Correct 2416 ms 283956 KB Output is correct
4 Correct 2340 ms 284012 KB Output is correct
5 Correct 2413 ms 284164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2249 ms 283996 KB Output is correct
2 Correct 2333 ms 284108 KB Output is correct
3 Correct 2416 ms 283956 KB Output is correct
4 Correct 2340 ms 284012 KB Output is correct
5 Correct 2413 ms 284164 KB Output is correct
6 Correct 2381 ms 284092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2363 ms 284024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2249 ms 283996 KB Output is correct
2 Correct 2333 ms 284108 KB Output is correct
3 Correct 2416 ms 283956 KB Output is correct
4 Correct 2340 ms 284012 KB Output is correct
5 Correct 2413 ms 284164 KB Output is correct
6 Correct 2381 ms 284092 KB Output is correct
7 Correct 2363 ms 284024 KB Output is correct
8 Correct 2230 ms 284144 KB Output is correct
9 Correct 2374 ms 284036 KB Output is correct