답안 #198949

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198949 2020-01-28T09:46:14 Z Alexa2001 게임판 (CEOI13_board) C++17
70 / 100
200 ms 760 KB
#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;
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 632 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 8 ms 632 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 9 ms 760 KB Output is correct
3 Correct 9 ms 632 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 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
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 456 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 9 ms 760 KB Output is correct
3 Correct 8 ms 632 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 760 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 760 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1097 ms 760 KB Time limit exceeded
2 Halted 0 ms 0 KB -