답안 #80309

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
80309 2018-10-20T03:13:19 Z Plurm 게임판 (CEOI13_board) C++11
30 / 100
200 ms 3116 KB
#include <bits/stdc++.h>
using namespace std;
char a[100005];
char b[100005];
class holder : public vector<bool> {
public:
	vector<int> hsh;
	inline int ghash(){
		return size() <= 20 ? -1 : hsh[size()-21];
	}
	inline int to_int(){
		int v = 1;
		for(int i = max((int)size()-20,0); i < size(); i++){
			v *= 2;
			if(vector<bool>::at(i)) v++;
		}
		return v;
	}
	void push_back(bool b){
		vector<bool>::push_back(b);
		if(hsh.empty()) hsh.push_back(b ? 1 : 0);
		else hsh.push_back(53*hsh.back() + (b ? 1 : 0));
	}
	void pop_back(){
		vector<bool>::pop_back();
		hsh.pop_back();
	}
};
inline void mmove(holder& x,char y){
	switch(y){
		case '1':
		x.push_back(false);
		break;
 
		case '2':
		x.push_back(true);
		break;
 
		case 'U':
		x.pop_back();
		break;
 
		case 'L':
		for(int i = x.size()-1; i >= 0; i--){
			if(x[i]){
				x[i] = false;
				break;
			}else{
				x[i] = true;
			}
		}
		break;
 
		case 'R':
		for(int i = x.size()-1; i >= 0; i--){
			if(x[i]){
				x[i] = false;
			}else{
				x[i] = true;
				break;
			}
		}
		break;
	}
}
inline int glv(int x){
	int l = 0;
	while(x > 1){
		x /= 2;
		l++;
	}
	return l;
}
pair<int,int> mem[100005];
int main(){
	gets(a);
	gets(b);
	holder ma;
	holder mb;
	for(int i = 0; a[i]; i++){
		mmove(ma,a[i]);
	}
	int lla = ma.size();
	while(!ma.empty()){
		mem[ma.size()] = make_pair(ma.ghash(),ma.to_int());
		ma.pop_back();
	}
	for(int i = 0; b[i]; i++){
		mmove(mb,b[i]);
	}
	int llb = mb.size();
	int d = 1e9;
	while(!mb.empty()){
		if(mb.ghash() == mem[mb.size()].first){
			d = min(d,(int)(lla - mb.size() + llb - mb.size() + abs(mb.to_int() - mem[mb.size()].second)));
		}
		mb.pop_back();
	}
	printf("%d\n",d);
}

Compilation message

board.cpp: In member function 'int holder::to_int()':
board.cpp:13:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = max((int)size()-20,0); i < size(); i++){
                                      ~~^~~~~~~~
board.cpp: In function 'int main()':
board.cpp:76:8: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
  gets(a);
        ^
In file included from /usr/include/c++/7/cstdio:42:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:46,
                 from board.cpp:1:
/usr/include/stdio.h:638:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
board.cpp:77:8: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
  gets(b);
        ^
In file included from /usr/include/c++/7/cstdio:42:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:46,
                 from board.cpp:1:
/usr/include/stdio.h:638:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
board.cpp:76:6: warning: ignoring return value of 'char* gets(char*)', declared with attribute warn_unused_result [-Wunused-result]
  gets(a);
  ~~~~^~~
board.cpp:77:6: warning: ignoring return value of 'char* gets(char*)', declared with attribute warn_unused_result [-Wunused-result]
  gets(b);
  ~~~~^~~
/tmp/cc8vC6SQ.o: In function `main':
board.cpp:(.text.startup+0x2a): warning: the `gets' function is dangerous and should not be used.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 708 KB Output is correct
2 Correct 2 ms 764 KB Output is correct
3 Correct 4 ms 812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 812 KB Output is correct
2 Correct 2 ms 1096 KB Output is correct
3 Correct 2 ms 1220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1220 KB Output is correct
2 Correct 6 ms 1492 KB Output is correct
3 Incorrect 4 ms 1604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1604 KB Output is correct
2 Correct 2 ms 1604 KB Output is correct
3 Incorrect 2 ms 1604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1604 KB Output is correct
2 Correct 2 ms 1604 KB Output is correct
3 Incorrect 2 ms 1616 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1620 KB Output is correct
2 Correct 6 ms 2176 KB Output is correct
3 Incorrect 4 ms 2176 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 2792 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1069 ms 3004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1067 ms 3116 KB Time limit exceeded
2 Halted 0 ms 0 KB -