답안 #595945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
595945 2022-07-14T08:17:13 Z jamezzz 기억 압축 (JOI15_memory) C++17
100 / 100
4215 ms 284092 KB
#include "Memory_lib.h"
#include <bits/stdc++.h>
using namespace std;

int Memory(int N,int M){
	int cur=M&127;
	if(cur>N)return -2;
	if(cur==N){
		int mode=(M>>21);
		if(mode==0)return N+(1<<21);
		int pos=(M>>7)&127;
		if(pos>N)return -2;
		int sum=(M>>14)&127;
		if(sum>N)return -2;
		if(pos==N){
			if(sum==0)return -1;
			else return -2;
		}
		char c=Get(pos+1);
		if(c=='<'||c=='[')++sum;
		else --sum;
		if(sum<0)return -2;
		++pos;
		return N+(pos<<7)+(sum<<14)+(1<<21);
	}
	
	int mode=(M>>21);
	if(mode==1){//process cur element
		int cur=M&127;//current pos
		int type=(M>>7)&1;
		char c=Get(cur+1);
		if(c=='>'&&type==1)return -2;
		if(c==']'&&type==0)return -2;
		return (cur+1)+((cur+1)<<7);
	}
	else{
		int cur=M&127;//current pos
		int pos=(M>>7)&127;//top of stack?
		if(pos>=N)return -2;
		int sum=(M>>14)&127;//prefix sum
		if(sum>N)return -2;
		char c=Get(pos+1);
		if(cur==pos){
			if(c=='<'||c=='[')return cur+(1<<21);
			if(cur==0)return -2;
			else return cur+((pos-1)<<7);
		}
		if(sum==0&&(c=='<'||c=='[')){
			if(c=='<'){
				return cur+(1<<21);
			}
			else{
				return cur+(1<<7)+(1<<21);
			}
		}
		if(c=='<'||c=='[')--sum;
		else ++sum;
		--pos;
		if(pos<0)return -2;
		return cur+(pos<<7)+(sum<<14);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2296 ms 284000 KB Output is correct
2 Correct 2402 ms 284036 KB Output is correct
3 Correct 2561 ms 284056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2296 ms 284000 KB Output is correct
2 Correct 2402 ms 284036 KB Output is correct
3 Correct 2561 ms 284056 KB Output is correct
4 Correct 4215 ms 283968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2296 ms 284000 KB Output is correct
2 Correct 2402 ms 284036 KB Output is correct
3 Correct 2561 ms 284056 KB Output is correct
4 Correct 4215 ms 283968 KB Output is correct
5 Correct 2478 ms 283996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2296 ms 284000 KB Output is correct
2 Correct 2402 ms 284036 KB Output is correct
3 Correct 2561 ms 284056 KB Output is correct
4 Correct 4215 ms 283968 KB Output is correct
5 Correct 2478 ms 283996 KB Output is correct
6 Correct 2664 ms 284092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2414 ms 283976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2296 ms 284000 KB Output is correct
2 Correct 2402 ms 284036 KB Output is correct
3 Correct 2561 ms 284056 KB Output is correct
4 Correct 4215 ms 283968 KB Output is correct
5 Correct 2478 ms 283996 KB Output is correct
6 Correct 2664 ms 284092 KB Output is correct
7 Correct 2414 ms 283976 KB Output is correct
8 Correct 2388 ms 283980 KB Output is correct
9 Correct 3115 ms 283996 KB Output is correct