제출 #659956

#제출 시각아이디문제언어결과실행 시간메모리
659956RambaXGorillaBoard (CEOI13_board)C++17
100 / 100
15 ms736 KiB
#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++){
        while(true){
            char a;
            scanf("%c",&a);
            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++){
        last = i + 1;
        if(pos[0][i] == pos[1][i]){
            add = 2;
            if(last < len && pos[0][last] > pos[1][last]){
                last++;
                add = 3;
            }
            break;
        }
        else if(pos[0][i] < pos[1][i]){
            add = 3;
            break;
        }
    }
    printf("%d",pos[0].size() + pos[1].size() - last * 2 + add);
}

컴파일 시 표준 에러 (stderr) 메시지

board.cpp: In function 'int main()':
board.cpp:95: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=]
   95 |     printf("%d",pos[0].size() + pos[1].size() - last * 2 + add);
      |             ~^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |              |                                           |
      |              int                                         std::__cxx11::basic_string<char>::size_type {aka long unsigned int}
      |             %ld
board.cpp:22:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |             scanf("%c",&a);
      |             ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...