답안 #263601

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
263601 2020-08-13T20:23:02 Z Sorting 게임판 (CEOI13_board) C++17
0 / 100
5 ms 1408 KB
#include <bits/stdc++.h>

using namespace std;

string a, b;

string get_path(const string &s){
    vector<int> v;
    int curr = -1;
    int n = s.size();

    for(int i = 0; i < n; ++i){
        if(s[i] == '1' || s[i] == '2'){
            if(curr != (s[i] - '0')) v.push_back(1);
            else v.back()++;
            curr = (s[i] - '0');
        }
        else if(s[i] == 'U'){
            if(v.size() == 1){
                v.pop_back();
                curr = -1;
            }
            else{
                v.pop_back();
                curr = 3 - curr;
            }
        }
        else if(s[i] == 'L' || s[i] == 'R'){
            int num = (s[i] == 'L') ? 2 : 1;    
            if(curr == num){
                v.back()--;
                if(v.back() == 0){
                    v.pop_back();
                    if(v.empty()) v.push_back(1);
                    else v.back()++;
                }
                else v.push_back(1);

                curr = 3 - curr;
            }
            else{
                int x = v.back();
                v.pop_back();

                v.back()--;
                if(v.back() == 0){
                    v.pop_back();
                    if(v.empty()) v.push_back(1);
                    else v.back()++;
                }
                else v.push_back(1);

                v.push_back(x);

                curr = 3 - curr;
            }
        }
    }

    string ans = "";
    for(int i = (int)v.size() - 1; i >= 0; --i){
        for(int j = 0; j < v[i]; ++j)
            ans += curr + '0';
        curr = 3 - curr;
    }
    
    reverse(ans.begin(), ans.end());
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> a >> b;

    a = get_path(a);
    b = get_path(b);

    int x = a.size() + b.size();
    int dist = 0, ans = x;
    bool ok = false;
    for(int i = 0; i < min(a.size(), b.size()); ++i){
        if(a[i] != b[i] && !ok){
            ok = true;
            if(a[i] == '2')
                swap(a, b);
        }

        dist = 2 * dist - 1;
        if(a[i] == '1') dist++;
        if(b[i] == '2') dist++;

        if(dist > 3) break;
        ans = min(ans, dist + x - 2 * (i + 1));
    }

    cout << ans << "\n";
}

Compilation message

board.cpp: In function 'int main()':
board.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   83 |     for(int i = 0; i < min(a.size(), b.size()); ++i){
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 896 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 1280 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 1408 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 1280 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -