이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |