Submission #777264

#TimeUsernameProblemLanguageResultExecution timeMemory
777264NK_Board (CEOI13_board)C++17
70 / 100
1077 ms1032 KiB
// 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...