답안 #199205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199205 2020-01-30T07:29:16 Z arnold518 기억 압축 (JOI15_memory) C++14
100 / 100
2790 ms 283944 KB
#include "Memory_lib.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int f(int pos, int lvl, int sz, int v)
{
	return pos|(lvl<<7)|(sz<<13)|(v<<20);
}

int Memory(int N, int M)
{
	int i, j;

	if(N%2) return -2;
	if(M==0) return f(1, 1, 0, 0);

	int pos=M&((1<<7)-1), lvl=(M>>7)&((1<<6)-1), sz=(M>>13)&((1<<6)-1), v=(M>>20)&1;

	if(lvl>N/2) return -1;
	if(pos>N+1) return -2;
	if(pos==0) return -2;
	if(pos==N+1)
	{
		if(sz!=0) return -2;
		return f(1, lvl+1, 0, 0);
	}

	//printf("%d %d %d %d %d\n", M, pos, lvl, sz, v);
	char c=Get(pos);
	if(c=='<')
	{
		sz++;
		if(sz>N/2) return -2;
		if(sz==lvl) v=0;
	}
	else if(c=='[')
	{
		sz++;
		if(sz>N/2) return -2;
		if(sz==lvl) v=1;
	}
	else if(c=='>')
	{
		if(sz==lvl)
		{
			if(v==1) return -2;
		}
		sz--;
		if(sz<0) return -2;
	}
	else if(c==']')
	{
		if(sz==lvl)
		{
			if(v==0) return -2;
		}
		sz--;
		if(sz<0) return -2;
	}
	pos++;
	return f(pos, lvl, sz, v);
}

Compilation message

memory.cpp: In function 'int Memory(int, int)':
memory.cpp:16:6: warning: unused variable 'i' [-Wunused-variable]
  int i, j;
      ^
memory.cpp:16:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2783 ms 283908 KB Output is correct
2 Correct 2648 ms 283844 KB Output is correct
3 Correct 2609 ms 283924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2783 ms 283908 KB Output is correct
2 Correct 2648 ms 283844 KB Output is correct
3 Correct 2609 ms 283924 KB Output is correct
4 Correct 2589 ms 283896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2783 ms 283908 KB Output is correct
2 Correct 2648 ms 283844 KB Output is correct
3 Correct 2609 ms 283924 KB Output is correct
4 Correct 2589 ms 283896 KB Output is correct
5 Correct 2660 ms 283780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2783 ms 283908 KB Output is correct
2 Correct 2648 ms 283844 KB Output is correct
3 Correct 2609 ms 283924 KB Output is correct
4 Correct 2589 ms 283896 KB Output is correct
5 Correct 2660 ms 283780 KB Output is correct
6 Correct 2666 ms 283892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2766 ms 283944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2783 ms 283908 KB Output is correct
2 Correct 2648 ms 283844 KB Output is correct
3 Correct 2609 ms 283924 KB Output is correct
4 Correct 2589 ms 283896 KB Output is correct
5 Correct 2660 ms 283780 KB Output is correct
6 Correct 2666 ms 283892 KB Output is correct
7 Correct 2766 ms 283944 KB Output is correct
8 Correct 2615 ms 283776 KB Output is correct
9 Correct 2790 ms 283640 KB Output is correct