Submission #384260

#TimeUsernameProblemLanguageResultExecution timeMemory
384260ijxjdjdBoard (CEOI13_board)C++17
40 / 100
1093 ms876 KiB
#include <bits/stdc++.h> #define FR(i, N) for (int i = 0; i < int(N); i++) #define all(x) begin(x), end(x) using namespace std; using ll = long long; int main() { cin.tie(0); cin.sync_with_stdio(0); string A; string B; cin >> A >> B; ll sA = 1; ll sB = 1; for (char c : A){ if (c == '1') { sA *= 2; } else if (c == '2') { sA *= 2; sA++; } else if (c == 'U') { sA /= 2; } else if (c == 'L') { sA--; } else if (c == 'R') { sA++; } } for (char c : B){ if (c == '1') { sB *= 2; } else if (c == '2') { sB *= 2; sB++; } else if (c == 'U') { sB /= 2; } else if (c == 'L') { sB--; } else if (c == 'R') { sB++; } } if (sA < sB) { swap(sA, sB); } ll d = 0; for (int k = 62; k >= 0; k--) { if (sB&(1LL<<k)) { while (sA>=(1LL<<(k+1))) { sA>>=1; d++; } break; } } if (sA < sB) { swap(sA, sB); } ll res = (ll)(1e18); while (sA != sB) { res = min(res, sA-sB+d); sA >>= 1; sB >>= 1; d+=2; } res = min(res, sA-sB+d); cout << res << '\n'; 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...