# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
56908 |
2018-07-13T06:53:05 Z |
정원준(#1637) |
기억 압축 (JOI15_memory) |
C++11 |
|
35 ms |
1784 KB |
#include<Memory_lib.h>
#include <bits/stdc++.h>
using namespace std;
char Get(int I);
int trans(char a){
if(a=='[') return 1;
if(a==']') return 4;
if(a=='<') return 2;
if(a=='>') return 3;
}
int pack(int s,int h,int n,int f,int e){
int ret=0;
//h--;
//n--;
f--;
ret+=s<<19;
ret+=h*10100+n*100+f;
ret<<=1;
ret+=e;
return ret;
}
int Memory(int N,int M){
int ended,state,height,now,far,locvalues;
if(M==0)
{
ended=0;
state=0;
height=0;
now=1;
far=0;
}
else
{
ended=M%2;
M/=2;
state=(M>>19);
locvalues=(M-(state<<19));
height=locvalues/10100;
now=(locvalues/100)%101;
far=locvalues%100+1;
}
//printf("%d %d %d %d %d\n",state,height,now,far,ended);
if(ended)
{
if(now==0) return height==1?-1:-2;
if(now<1||now>N) return -1;
int temp=trans(Get(now));
if(temp<=2) height--;
else height++;
if(height<1) return -2;
now--;
return pack(state,height,now,far,ended);
}
if(state)
{
if(now<1) return -2;
if(now<1||now>N) return -1;
int temp=trans(Get(now));
if(temp<=2) height--;
else height++;
if(height==0)
{
if(temp+state!=5) return -2;
state=0;
height=0;
now++;
return pack(state,height,now,far,ended);
}
else
{
now--;
//printf("%lld\n",now);
return pack(state,height,now,far,ended);
}
}
else
{
if(now>far)
{
far=now;
if(now>N)
{
ended=1;
height=1;
now--;
return pack(state,height,now,far,ended);
}
else
{
if(now<1||now>N) return -1;
int temp=trans(Get(now));
if(temp<=2)
{
now++;
return pack(state,height,now,far,ended);
}
else
{
state=temp;
height=1;
now--;
return pack(state,height,now,far,ended);
}
}
}
else
{
now++;
return pack(state,height,now,far,ended);
}
}
}
/*
int n,tc;
char str[111];
void E(int x){
printf("Wrong answer %d",x);
}
char Get(int I){
if(I<1||I>n)
E(3);
return str[I-1];
}
int main()
{
scanf("%d %s",&n,str);
int mem=0,cnt;
do
{
mem=Memory(n,mem);
cnt++;
if(mem<0) break;
}while(1);
printf("%d %d",mem,cnt);
}*/
Compilation message
memory.cpp: In function 'int trans(char)':
memory.cpp:13:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
1784 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
1784 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
1784 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
1784 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1784 KB |
Wrong Answer [1] |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
1784 KB |
Wrong Answer [1] |
2 |
Halted |
0 ms |
0 KB |
- |