답안 #63680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
63680 2018-08-02T13:38:01 Z bazsi700 게임판 (CEOI13_board) C++14
40 / 100
200 ms 2252 KB
#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL

//15:20

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string a;
	string b;
	cin >> a >> b;
	//cout << a << " " << b << endl;
	ll node1 = 1;
	ll node2 = 1;
	for(int i = 0; i < a.length(); i++) {
		if(a.at(i) == '1') {
			node1*=2;
		} else if(a.at(i) == '2') {
			node1= node1*2+1;
		} else if(a.at(i) == 'L') {
			node1--;
		} else if(a.at(i) == 'R') {
			node1++;
		} else {
			node1/=2;
		}
	}
	for(int i = 0; i < b.length(); i++) {
		//cout <<"a" << node2 << " ";
		if(b.at(i) == '1') {
			node2*=2;
		} else if(b.at(i) == '2') {
			node2= node2*2+1;
		} else if(b.at(i) == 'L') {
			node2--;
		} else if(b.at(i) == 'R') {
			node2++;
		} else {
			node2/=2;
		}
	//	cout << node2 << endl;
	}
	int lev1 = 0;
	int lev2 = 0;
	ll num = 1;
	while(num <= node1) {
		lev1++;
		num*=2;
	}
	num = 1;
	while(num <= node2) {
		lev2++;
		num*=2;
	}
//	cout << node1 << " " << node2 << endl;
//	cout << lev1 << " " << lev2 << endl;
	lev1--;
	lev2--;
	if(lev1 > lev2) {
		swap(lev1,lev2);
		swap(node1,node2);
	}
	for(int i = 0; i < lev2-lev1; i++) {
		node2/=2;
	}
	ll ans = INF;
	for(int goesupmore = 0; goesupmore < lev1; goesupmore++) {
		ans = min(ans,lev2-lev1+goesupmore*2+abs(node1-node2));
		//cout << node1 << " " << node2 << " " << lev1-lev2<< " " << goesupmore*2<< " " << abs(node1-node2) << endl;
		node1/=2;
		node2/=2;
	}
	ans = min(ans,lev2-lev1+lev1*2+abs(node1-node2));
	//cout << node2 << endl;
	cout << ans;
	return 0;
}

Compilation message

board.cpp: In function 'int main()':
board.cpp:22:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < a.length(); i++) {
                 ~~^~~~~~~~~~~~
board.cpp:35:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < b.length(); i++) {
                 ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 548 KB Output is correct
3 Correct 2 ms 548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 888 KB Output is correct
2 Correct 3 ms 888 KB Output is correct
3 Correct 5 ms 1072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1072 KB Output is correct
2 Correct 2 ms 1072 KB Output is correct
3 Correct 3 ms 1072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1156 KB Output is correct
2 Correct 7 ms 1348 KB Output is correct
3 Correct 4 ms 1404 KB Output is correct
4 Correct 2 ms 1404 KB Output is correct
5 Correct 3 ms 1404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1064 ms 1404 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1071 ms 1404 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 2012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2252 KB Output isn't correct
2 Halted 0 ms 0 KB -