답안 #777148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
777148 2023-07-08T17:52:29 Z NK_ 게임판 (CEOI13_board) C++17
40 / 100
200 ms 728 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 = 1e7;
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;

		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 (max(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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 5 ms 596 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 320 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 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 6 ms 596 KB Output is correct
3 Correct 3 ms 540 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 973 ms 724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 952 ms 728 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 971 ms 660 KB Time limit exceeded
2 Halted 0 ms 0 KB -