# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
198948 |
2020-01-28T09:41:58 Z |
Alexa2001 |
Board (CEOI13_board) |
C++17 |
|
7 ms |
632 KB |
#include <bits/stdc++.h>
using namespace std;
/// 11:09
const int Nmax = 105;
int n, m;
int ans = 0;
char A[Nmax], B[Nmax], aux[Nmax];
void trans(char A[], int &n)
{
int i, j, s = 0;
for(i=1; i<=n; ++i)
if(A[i] == 'L' || A[i] == 'R')
{
int nr = 0;
while(i<=n && (A[i] == 'L' || A[i] == 'R'))
{
if(A[i] == 'L') ++nr;
else --nr;
++i;
}
--i;
for(j=1; j<=nr; ++j) aux[++s] = 'L';
for(j=1; j<=-nr; ++j) aux[++s] = 'R';
}
else aux[++s] = A[i];
n = s;
for(i=1; i<=n; ++i) A[i] = aux[i];
s = 0;
for(i=1; i<=n; ++i)
if(A[i] == 'U') --s;
else if(A[i] == '1') aux[++s] = 0;
else if(A[i] == '2') aux[++s] = 1;
else if(A[i] == 'L')
{
j = s;
while(aux[j] == 0) --j;
aux[j] = 0;
for(++j; j<=s; ++j) aux[j] = 1;
}
else if(A[i] == 'R')
{
j = s;
while(aux[j] == 1) --j;
aux[j] = 1;
for(++j; j<=s; ++j) aux[j] = 0;
}
else assert(0);
n = s;
for(i=1; i<=n; ++i) A[i] = aux[i];
}
void read()
{
cin >> (A+1) >> (B+1);
n = strlen(A+1);
m = strlen(B+1);
trans(A, n);
trans(B, m);
if(n > m) ans += n - m, n = m;
else ans += m - n, m = n;
int i, p = 0;
while(A[p+1] == B[p+1] && p < n) ++p;
for(i=1; i<=n-p; ++i)
A[i] = A[i+p], B[i] = B[i+p];
n -= p;
}
int solve()
{
if(n == 0) return 0;
int i;
if(A[1] > B[1])
for(i=1; i<=n; ++i) swap(A[i], B[i]);
for(i=2; i<=n; ++i) A[i] ^= 1;
B[1] = 0;
int x = 0, y = 0;
int ans = 2 * n;
for(i=0; i<=n; ++i)
{
ans = min(ans, x + y + 2 * (n-i) + 1);
x = 2 * x + A[i+1];
y = 2 * y + B[i+1];
if(x + y > ans) break;
}
return ans;
}
int main()
{
// freopen("input", "r", stdin);
cin.sync_with_stdio(false); cin.tie(0);
read();
ans += solve();
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
608 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |