답안 #282190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282190 2020-08-24T06:14:24 Z 송준혁(#5750) 기억 압축 (JOI15_memory) C++17
100 / 100
3038 ms 284076 KB
#include "Memory_lib.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int enc(int x, int y, int z, int t){
	int m=t;
	m = m * 51 + z;
	m = m * 102 + y;
	m = m * 102 + x;
	return m;
}

void dec(int M, int &x, int &y, int &z, int &t){
	x = M % 102, M /= 102;
	y = M % 102, M /= 102;
	z = M % 51, M /= 51;
	t = M;
}

int Memory(int N, int M) {
	int x, y, z, t;
	dec(M, x, y, z, t);
	if (M == 0) return enc(1, 1, 0, 0);
	if (x < y || x < 1 || x > N+1 || y > N+1 || t > 2) return -2;
	if (x == y){
		if (x > N) return enc(x, N, 0, 0);
		if (t){
			char ch = Get(x);
			if (ch == ']' && t == 2) return -2;
			if (ch == '>' && t == 1) return -2;
			return enc(x+1, x+1, 0, 0);
		}
		else{
			char ch = Get(x);
			if (ch == '[' || ch == '<') return enc(x+1, x+1, 0, 0);
			return enc(x, x-1, 0, 0);
		}
	}
	else{
		if (y == 0){
			if (x > N) return -1;
			return -2;
		}
		char ch=Get(y);
		if (ch == '[' || ch == '<'){
			if (z) return enc(x, y-1, z-1, 0);
			if (x > N) return -2;
			return enc(x, x, 0, (ch=='[')?1:2);
		}
		return enc(x, y-1, z+1, 0);
	}
	return -2;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2949 ms 283720 KB Output is correct
2 Correct 3038 ms 283688 KB Output is correct
3 Correct 2919 ms 283860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2949 ms 283720 KB Output is correct
2 Correct 3038 ms 283688 KB Output is correct
3 Correct 2919 ms 283860 KB Output is correct
4 Correct 2916 ms 283692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2949 ms 283720 KB Output is correct
2 Correct 3038 ms 283688 KB Output is correct
3 Correct 2919 ms 283860 KB Output is correct
4 Correct 2916 ms 283692 KB Output is correct
5 Correct 2930 ms 283648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2949 ms 283720 KB Output is correct
2 Correct 3038 ms 283688 KB Output is correct
3 Correct 2919 ms 283860 KB Output is correct
4 Correct 2916 ms 283692 KB Output is correct
5 Correct 2930 ms 283648 KB Output is correct
6 Correct 2962 ms 283724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2946 ms 283656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2949 ms 283720 KB Output is correct
2 Correct 3038 ms 283688 KB Output is correct
3 Correct 2919 ms 283860 KB Output is correct
4 Correct 2916 ms 283692 KB Output is correct
5 Correct 2930 ms 283648 KB Output is correct
6 Correct 2962 ms 283724 KB Output is correct
7 Correct 2946 ms 283656 KB Output is correct
8 Correct 2970 ms 283884 KB Output is correct
9 Correct 2950 ms 284076 KB Output is correct