답안 #777264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
777264 2023-07-09T00:39:15 Z NK_ 게임판 (CEOI13_board) C++17
70 / 100
200 ms 1032 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl '\n'
#define sz(x) int(x.size())
 
using str = string;
using ll = long long;
 
template<class T> using V = vector<T>;
 
const int INF = int(1e9) + 10;
const int MX = 10;
int main() {
	cin.tie(0)->sync_with_stdio(0);
		
	str A, B; cin >> A >> B;
 
	auto add = [&](str& S, bool pos) {
		char c = (pos ? '0' : '1');
		for(int i = sz(S)-1; i >= 0; i--) {
			if (S[i] == c) {
				S[i] = '0' + '1' - c;
				break;
			}
			S[i] = c;
		}
		return S;
	};
 
	auto get = [&](const str& S) {
		str T = "0";
 
		for(auto& c : S) {
			if (isdigit(c)) T.push_back(c-1);
			if (c == 'U') T.pop_back();
			if (c == 'L') add(T, 0);
			if (c == 'R') add(T, 1);
		}
 
		return T;
	};
 
	A = get(A), B = get(B);
 
	int ans = INF;
 
	// cout << A << " " << B << endl;
 
	int xa = 0, xb = 0; bool aft = 0;
	for(int i = 0; i < min(sz(A), sz(B)); i++) {
		if (abs(xa - xb) > MX) break;
		if (A[i] != B[i]) aft = 1;
 
		if (aft) {
			xa = (2 * xa) + (A[i] - '0');
			xb = (2 * xb) + (B[i] - '0');
		}
 
		int upa = sz(A) - i - 1, upb = sz(B) - i - 1; 
		ans = min(ans, upa + upb + abs(xa - xb));
	}
 
	cout << ans << nl;
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 612 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 5 ms 724 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 7 ms 728 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1063 ms 1032 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1071 ms 840 KB Time limit exceeded
2 Halted 0 ms 0 KB -