답안 #80466

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
80466 2018-10-20T22:47:30 Z Plurm 게임판 (CEOI13_board) C++11
80 / 100
23 ms 1956 KB
#include <bits/stdc++.h>
using namespace std;
char a[100005];
char b[100005];
class holder{
public:
	vector<int> masker;
	vector<int> hasher;
	bool updt = false;
	holder& operator=(const holder& y){
		masker = y.masker;
		hasher = y.hasher;
		updt = y.updt;
		return *this;
	}
	int length(){
		return masker.size();
	}
	int ghash(){
		return hasher.size() > 20 ? hasher[(int)hasher.size()-20] : -1;
	}
	int gint(){
		int ret = 0;
		for(int i = max((int)masker.size()-19,0); i < (int)masker.size(); i++){
			ret *= 2;
			ret += (int)masker[i];
		}
		return ret;
	}
	void update(){
		updt = false;
		for(int i = 1; i < 20 && (int)masker.size() - i - 1 >= 0; i++){
			if(masker[(int)masker.size() - i - 1]){
				masker.back() += 1 << i;
				masker[(int)masker.size() - i - 1] = 0;
			}
		}
		for(int i = 0; i < 20 && (int)masker.size() - i - 1 >= 0; i++){
			if(masker.back() & (1 << i)){
				masker[(int)masker.size() - i - 1]++;
				masker.back() -= 1 << i;
			}
		}
		for(int i = 0; i < 20 && (int)masker.size() - i - 1 >= 0; i++){
			if(masker[(int)masker.size() - i - 1] > 1){
				masker[(int)masker.size() - i - 1] -= 2;
				if((int)masker.size() - i - 2 >= 0) masker[(int)masker.size() - i - 2]++;
			}
		}
		for(int i = max(0,(int)masker.size() - 20); i < (int)masker.size(); i++){
			if(i == 0) hasher[i] = masker[i]+1;
			else hasher[i] = 53*hasher[i-1] + masker[i]+1;
		}
	}
	void move(char x){
		switch(x){
		case '1':
			if(updt) update();
			masker.push_back(0);
			hasher.push_back(hasher.empty() ? 1 : hasher.back()*53 + 1);
			break;
		case '2':
			if(updt) update();
			masker.push_back(1);
			hasher.push_back(hasher.empty() ? 2 : hasher.back()*53 + 1);
			break;
		case 'U':
			if(updt) update();
			masker.pop_back();
			hasher.pop_back();
			break;
		case 'L':
			masker.back()--;
			updt = true;
			break;
		case 'R':
			masker.back()++;
			updt = true;
			break;
		}
	}
};
int hsh[100005];
int mem[100005];
int main(){
	scanf("%s",a);
	scanf("%s",b);
	holder ma,mb;
  	ma.move('2');
  	mb.move('2');
	for(int i = 0; a[i]; i++){
		ma.move(a[i]);
	}
	ma.update();
	for(int i = 0; b[i]; i++){
		mb.move(b[i]);
	}
	mb.update();
	if(ma.length() < mb.length()){
		swap(ma,mb);
	}
	int lla = ma.length();
	int llb = mb.length();
	while(ma.length() > mb.length()){
		ma.move('U');
	}
	int d = lla + llb - 1;
	int cur = 0;
	int rig = 0;
	for(int i = 0; i < mb.length(); i++){
		if(!rig && ma.masker[i] != mb.masker[i]){
			if(ma.masker[i] < mb.masker[i]) rig = 2;
			else rig = 1;
		}
		cur *= 2;
		if(rig == 1) cur += ma.masker[i] - mb.masker[i];
		else if(rig == 2) cur += mb.masker[i] - ma.masker[i];
		d = min(d,cur + lla - 2*i + llb - 2);
		if(cur > d) break;
	}
	printf("%d\n",d);
	return 0;
}

Compilation message

board.cpp: In function 'int main()':
board.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",a);
  ~~~~~^~~~~~~~
board.cpp:87:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",b);
  ~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 632 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 8 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 736 KB Output is correct
2 Correct 2 ms 736 KB Output is correct
3 Correct 2 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 736 KB Output is correct
2 Correct 17 ms 788 KB Output is correct
3 Correct 9 ms 788 KB Output is correct
4 Correct 2 ms 788 KB Output is correct
5 Correct 2 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 788 KB Output is correct
2 Correct 2 ms 788 KB Output is correct
3 Correct 2 ms 788 KB Output is correct
4 Correct 2 ms 788 KB Output is correct
5 Correct 2 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 788 KB Output is correct
2 Correct 3 ms 788 KB Output is correct
3 Correct 2 ms 788 KB Output is correct
4 Correct 2 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 788 KB Output is correct
2 Correct 16 ms 788 KB Output is correct
3 Correct 10 ms 788 KB Output is correct
4 Correct 2 ms 788 KB Output is correct
5 Correct 2 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1956 KB Output is correct
2 Correct 21 ms 1956 KB Output is correct
3 Correct 2 ms 1956 KB Output is correct
4 Correct 3 ms 1956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1956 KB Output is correct
2 Correct 22 ms 1956 KB Output is correct
3 Correct 2 ms 1956 KB Output is correct
4 Correct 2 ms 1956 KB Output is correct
5 Incorrect 5 ms 1956 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1956 KB Output is correct
2 Correct 22 ms 1956 KB Output is correct
3 Incorrect 12 ms 1956 KB Output isn't correct
4 Halted 0 ms 0 KB -