Submission #677444

# Submission time Handle Problem Language Result Execution time Memory
677444 2023-01-03T11:25:39 Z mjhmjh1104 None (JOI15_memory) C++17
0 / 100
1909 ms 284112 KB
#include "Memory_lib.h"

int pack(int x, int y, int z, bool w) {
    return (x << 15) | (y << 8) | (z << 1) | w;
}

char get(int x) {
    return Get(x + 1);
}

int Memory(int n, int m) {
    if (n % 2) return -2;
    int x = (m >> 15) & 127;
    int y = (m >> 8) & 127;
    int z = (m >> 1) & 127;
    bool w = m & 1;
    if (z > n) {
        if (z < n + 4) { // 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 {
                char c = get(x);
                if (c != '<') return -2;
            }
            x++;
            y = x;
            z = 0;
            w = false;
            return pack(x, y, z, w);
        } else { // 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 {
                char c = get(x);
                if (c != '<') {
                    x = y;
                    w = false;
                    z = 0;
                    return pack(x, y, z, w);
                }
            }
            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
            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
            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 1909 ms 284112 KB Output is correct
2 Incorrect 1 ms 280 KB Wrong Answer [3]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1909 ms 284112 KB Output is correct
2 Incorrect 1 ms 280 KB Wrong Answer [3]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1909 ms 284112 KB Output is correct
2 Incorrect 1 ms 280 KB Wrong Answer [3]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1909 ms 284112 KB Output is correct
2 Incorrect 1 ms 280 KB Wrong Answer [3]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1909 ms 284112 KB Output is correct
2 Incorrect 1 ms 280 KB Wrong Answer [3]
3 Halted 0 ms 0 KB -