제출 #198949

#제출 시각아이디문제언어결과실행 시간메모리
198949Alexa2001게임판 (CEOI13_board)C++17
70 / 100
1097 ms760 KiB
#include <bits/stdc++.h> using namespace std; /// 11:09 const int Nmax = 1e5 + 5; 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 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...