답안 #659948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659948 2022-11-20T02:39:17 Z RambaXGorilla 게임판 (CEOI13_board) C++17
20 / 100
12 ms 756 KB
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
string pos[2] = {"0", "0"};
string sub[2] = {"0", "0"};
void inc(string &a){
    for(int i = a.size() - 1;i > -1;i--){
        if(a[i] - '0'){
            a[i] = '0';
        }
        else{
            a[i] = '1';
            break;
        }
    }
}
int main(){
    for(int i = 0;i < 2;i++){
        char a;
        while(scanf("%c",&a) != EOF){
            if(a == '1'){
                pos[i].push_back('0');
                sub[i].push_back('0');
            }
            else if (a == '2'){
                pos[i].push_back('1');
                sub[i].push_back('0');
            }
            else if (a == 'U'){
                bool check = false;
                if(pos[i].back() < sub[i].back()){
                    check = true;
                }
                pos[i].pop_back();
                sub[i].pop_back();
                if(check){
                    inc(sub[i]);
                }
            }
            else if(a == 'L'){
                inc(sub[i]);
            }
            else if(a == 'R'){
                inc(pos[i]);
            }
            else{
                break;
            }
        }
    }
    for(int i = 0;i < 2;i++){
        bool borr = false;
        for(int j = pos[i].size() - 1;j > -1;j--){
            if(pos[i][j] > sub[i][j]){
                pos[i][j] -= borr;
                borr = false;
            }
            else if(pos[i][j] < sub[i][j]){
                pos[i][j] += 1 - borr;
                borr = true;
            }
            else{
                pos[i][j] = borr + '0';
            }
        }
    }
    sort(pos, pos + 2);
    int len = min(pos[0].size(), pos[1].size());
    int last = len;
    int add = 0;
    for(int i = 0;i < len;i++){
        if(pos[0][i] < pos[1][i]){
            last = i + 1;
            add = 1;
            break;
        }
    }
    for(int i = last;i < len;i++){
        if(pos[0][i] >= pos[1][i]){
            last = i + 1;
        }
        if(pos[0][i] == pos[1][i]){
            add = 2;
        }
        if(pos[0][i] <= pos[1][i]){
            break;
        }
    }
    printf("%d",pos[0].size() + pos[1].size() - last * 2 + add);
}

Compilation message

board.cpp: In function 'int main()':
board.cpp:90:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wformat=]
   90 |     printf("%d",pos[0].size() + pos[1].size() - last * 2 + add);
      |             ~^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |              |                                           |
      |              int                                         std::__cxx11::basic_string<char>::size_type {aka long unsigned int}
      |             %ld
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 2 ms 292 KB Output is correct
3 Incorrect 6 ms 412 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Incorrect 10 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 292 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 304 KB Output is correct
2 Incorrect 12 ms 480 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 672 KB Output is correct
2 Incorrect 8 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 724 KB Output is correct
2 Incorrect 10 ms 756 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 752 KB Output isn't correct
2 Halted 0 ms 0 KB -