답안 #677481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
677481 2023-01-03T12:33:09 Z 79brue 기억 압축 (JOI15_memory) C++17
100 / 100
2417 ms 284176 KB
#include "Memory_lib.h"
#include <bits/stdc++.h>

void translate(int st, int &i, int &j, int &depth, int &num){
    num = st % 3;
    st /= 3;
    depth = st % 102;
    st /= 102;
    j = st % 102;
    st /= 102;
    i = st;
}

int translate(int i, int j, int depth, int num){
    return ((i*102+j)*102+depth)*3+num;
}

int INF = (1<<22) - 100000;

int Memory(int n, int _st){
    int i, j, depth, num;
    translate(_st, i, j, depth, num);

    if(_st >= INF){ /// 우선 개수를 맞춰 본다.
        int tmp = _st - INF;
        int i = tmp / 300, j = tmp % 300;
        if(i == n+1) return (j == 150) ? translate(1, 1, 50, 0) : -2;
        if(!(1 <= i && i <= n)) return -2;

        char chr = Get(i);
        if(chr == '<' || chr == '[') return (INF + (i+1)*300 + (j+1));
        else                         return (INF + (i+1)*300 + (j-1));
    }

    if(i==n+1) return -1;
    if(j==n+1) return -2;
    if(i == 0) return (INF + 300 + 150);
    if(i > n+1 || j > n || j == 0) return -2;



    if(num){ /// i랑 j를 매칭 중
        int chr = (Get(i) == '<') ? 1 : 2;
        if(chr != num) return -2;
        return translate(i+1, i+1, 50, 0);
    }
    else{ /// 아직 매칭 중이 아님
        if(i==j){
            char tmp = Get(i);
            if(tmp == ']' || tmp == '>') return translate(i+1, i+1, 50, 0); /// 이건 여는 괄호가 아님
            return translate(i, i+1, 51, 0);
        }
        /// 맞는지 확인
        char tmp = Get(j);
        if(tmp == '[' || tmp == '<') depth++;
        else depth--;
        if(depth == 50) return translate(i, j, depth, tmp == '>' ? 1 : 2);
        return translate(i, j+1, depth, 0);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2159 ms 284064 KB Output is correct
2 Correct 2114 ms 284080 KB Output is correct
3 Correct 2222 ms 284140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2159 ms 284064 KB Output is correct
2 Correct 2114 ms 284080 KB Output is correct
3 Correct 2222 ms 284140 KB Output is correct
4 Correct 2135 ms 284136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2159 ms 284064 KB Output is correct
2 Correct 2114 ms 284080 KB Output is correct
3 Correct 2222 ms 284140 KB Output is correct
4 Correct 2135 ms 284136 KB Output is correct
5 Correct 2117 ms 284108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2159 ms 284064 KB Output is correct
2 Correct 2114 ms 284080 KB Output is correct
3 Correct 2222 ms 284140 KB Output is correct
4 Correct 2135 ms 284136 KB Output is correct
5 Correct 2117 ms 284108 KB Output is correct
6 Correct 2193 ms 284176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2203 ms 284052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2159 ms 284064 KB Output is correct
2 Correct 2114 ms 284080 KB Output is correct
3 Correct 2222 ms 284140 KB Output is correct
4 Correct 2135 ms 284136 KB Output is correct
5 Correct 2117 ms 284108 KB Output is correct
6 Correct 2193 ms 284176 KB Output is correct
7 Correct 2203 ms 284052 KB Output is correct
8 Correct 2417 ms 284028 KB Output is correct
9 Correct 2242 ms 284060 KB Output is correct