Submission #38700

# Submission time Handle Problem Language Result Execution time Memory
38700 2018-01-06T09:12:07 Z aome Board (CEOI13_board) C++14
70 / 100
200 ms 2700 KB
#include <bits/stdc++.h>
using namespace std;

void modify(string &S, vector<char>& V) {
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == '1') V.push_back('1');
        if (S[i] == '2') V.push_back('2');
        if (S[i] == 'U') V.pop_back();
        if (S[i] == 'L') {
            int id = V.size();
            while (id--) {
                if (V[id] == '1') V[id] = '2';
                else { V[id] = '1'; break; }
            }
        }
        if (S[i] == 'R') {
            int id = V.size();
            while (id--) {
                if (V[id] == '2') V[id] = '1';
                else { V[id] = '2'; break; }
            }
        }
    }
}

void print(vector<char> &V) {
    for (int i = 0; i < V.size(); ++i) cout << V[i]; cout << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    string sA, sB; cin >> sA >> sB;
    vector<char> vA, vB;
    modify(sA, vA), modify(sB, vB);
//    print(vA), print(vB);
    int res = 1e9, dis = 0;
    int szA = vA.size(), szB = vB.size();
    for (int i = 0; i < min(szA, szB); ++i) {
        res = min(res, szA + szB - 2 * i + dis);
        if (!dis) {
            if (vA[i] == vB[i]) continue;
            else {
                dis = 1;
                if (vA[i] == '2') swap(vA, vB), swap(szA, szB);
            }
        }
        else {
            if (vA[i] == '2' && vB[i] == '1') dis = dis * 2 - 1;
            else if (vA[i] == '1' && vB[i] == '2') dis = dis * 2 + 1;
            else dis = dis * 2;
        }
        if (dis > res) break;
    }
    res = min(res, szA + szB - 2 * min(szA, szB) + dis);
    cout << res;
}

Compilation message

board.cpp: In function 'void modify(std::__cxx11::string&, std::vector<char>&)':
board.cpp:5:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < S.size(); ++i) {
                       ^
board.cpp: In function 'void print(std::vector<char>&)':
board.cpp:27:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < V.size(); ++i) cout << V[i]; cout << '\n';
                       ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2176 KB Output is correct
2 Correct 0 ms 2176 KB Output is correct
3 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2496 KB Output is correct
2 Correct 0 ms 2176 KB Output is correct
3 Correct 0 ms 2540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2176 KB Output is correct
2 Correct 0 ms 2176 KB Output is correct
3 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2308 KB Output is correct
2 Correct 3 ms 2576 KB Output is correct
3 Correct 0 ms 2328 KB Output is correct
4 Correct 0 ms 2176 KB Output is correct
5 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2176 KB Output is correct
2 Correct 0 ms 2176 KB Output is correct
3 Correct 0 ms 2176 KB Output is correct
4 Correct 0 ms 2176 KB Output is correct
5 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2176 KB Output is correct
2 Correct 0 ms 2176 KB Output is correct
3 Correct 0 ms 2176 KB Output is correct
4 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2328 KB Output is correct
2 Correct 3 ms 2560 KB Output is correct
3 Correct 0 ms 2328 KB Output is correct
4 Correct 0 ms 2176 KB Output is correct
5 Correct 0 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 200 ms 2700 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 200 ms 2660 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 200 ms 2548 KB Execution timed out
2 Halted 0 ms 0 KB -