제출 #592440

#제출 시각아이디문제언어결과실행 시간메모리
592440dantoh000기억 압축 (JOI15_memory)C++14
40 / 100
2394 ms284160 KiB
#include "Memory_lib.h"
#include <bits/stdc++.h>
int Memory(int N, int M) {
	if (N <= 30){
		int idx = M&31;
		int flag = M>>5&1;
		int state = M>>6;
		if (idx > N) return 0;
		if (idx == N) return state==0?-1:-2;
		char ch = Get(idx+1);
		int type = (ch == '<' || ch == '>') ? 0 : 1;
		int open = (ch == '<' || ch == '[') ? 1 : 0;
		if (!open){
			if (state == 0) return -2;
			if (flag^(state&1) == type){
				state>>=1;
			}
			else return -2;
		}
		else{
			if (state >= 65536) return -2;
			state<<=1;
			if (state == 0){
				state = 1;
				flag = type^1;
			}
			else{
				state |= (flag^type);
			}
		}
		M = (state<<6)|(flag<<5)|(idx+1);
		return M>=4194304?-2:M;
	}
	else{
		int idx = M&127;
		int ct = M>>7;
		if (idx > N) return 0;
		if (idx == N) return (ct==0)?-1:-2;
		char ch = Get(idx+1);
		if (ch == '<'){
			ct++;
		}
		else{
			if (ct == 0) return -2;
			ct--;
		}
		M = (ct<<7)|(idx+1);
		return M>=4194304?-2:M;
	}
}

컴파일 시 표준 에러 (stderr) 메시지

memory.cpp: In function 'int Memory(int, int)':
memory.cpp:15:23: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
   15 |    if (flag^(state&1) == type){
      |             ~~~~~~~~~~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...