답안 #442858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442858 2021-07-09T09:33:03 Z prvocislo 게임판 (CEOI13_board) C++17
100 / 100
4 ms 1408 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> get(const string &s)
{
    vector<int> v;
    for (const char &c : s)
    {
        if (c == '1') v.push_back(0);
        if (c == '2') v.push_back(1);
        if (c == 'L') v.back()--;
        if (c == 'R') v.back()++;
        if (c == 'U')
        {
            int val = v.back(); v.pop_back();
            v.back() += (val >> 1);
        }
    }
    for (int i = v.size() - 1; i > 0; i--)
    {
        int val = v[i] >> 1;
        v[i] -= (val << 1);
        v[i - 1] += val;
    }
    return v;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); 
    string sa, sb;
    cin >> sa >> sb;
    vector<int> a = get(sa), b = get(sb);
    int dif = 0, dist = a.size() + b.size(), ans = dist;
    for (int i = 0; i < min(a.size(), b.size()); i++)
    {
        dist -= 2;
        dif <<= 1, dif += a[i] - b[i];
        int val = dist + abs(dif);
        if (val > 1e6) break;
        ans = min(ans, val);
    }
    cout << ans << "\n";
    return 0;
}

Compilation message

board.cpp: In function 'int main()':
board.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   35 |     for (int i = 0; i < min(a.size(), b.size()); i++)
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 680 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 0 ms 316 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1288 KB Output is correct
2 Correct 3 ms 1280 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1288 KB Output is correct
2 Correct 3 ms 1408 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 1352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1284 KB Output is correct
2 Correct 3 ms 1352 KB Output is correct
3 Correct 2 ms 1152 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 3 ms 1352 KB Output is correct