# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
545139 | rainboy | Board (CEOI13_board) | C11 | 4 ms | 1072 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <string.h>
#define N 100000
int abs_(int a) { return a > 0 ? a : -a; }
int main() {
static char aa[N + 1], bb[N + 1];
static int aa_[N + 1], bb_[N + 1];
int n, m, n_, m_, h, i, j, d;
scanf("%s%s", aa, bb), n = strlen(aa), m = strlen(bb);
n_ = 0;
for (i = 0; i < n; i++)
if (aa[i] == '1')
aa_[n_++] = 0;
else if (aa[i] == '2')
aa_[n_++] = 1;
else if (aa[i] == 'U') {
if (--n_)
aa_[n_ - 1] += (aa_[n_] > 0 ? aa_[n_] / 2 : -(-aa_[n_] + 1) / 2);
} else if (aa[i] == 'L')
aa_[n_ - 1]--;
else
aa_[n_ - 1]++;
for (i = n_ - 1; i > 0; i--) {
aa_[i - 1] += (aa_[i] > 0 ? aa_[i] / 2 : -(-aa_[i] + 1) / 2);
aa_[i] = (aa_[i] % 2 + 2) % 2;
}
m_ = 0;
for (j = 0; j < m; j++)
if (bb[j] == '1')
bb_[m_++] = 0;
else if (bb[j] == '2')
bb_[m_++] = 1;
else if (bb[j] == 'U') {
if (--m_)
bb_[m_ - 1] += (bb_[m_] > 0 ? bb_[m_] / 2 : -(-bb_[m_] + 1) / 2);
} else if (bb[j] == 'L')
bb_[m_ - 1]--;
else
bb_[m_ - 1]++;
for (j = m_ - 1; j > 0; j--) {
bb_[j - 1] += (bb_[j] > 0 ? bb_[j] / 2 : -(-bb_[j] + 1) / 2);
bb_[j] = (bb_[j] % 2 + 2) % 2;
}
d = 0;
for (h = 0; h < n_ && h < m_; h++) {
int d_ = d * 2 + aa_[h] - bb_[h];
if (abs_(d_) > 3)
break;
d = d_;
}
printf("%d\n", n_ + m_ - h * 2 + abs_(d));
return 0;
}
Compilation message (stderr)
# | 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... |