結果

問題 No.884 Eat and Add
ユーザー CleyLCleyL
提出日時 2020-02-09 00:17:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 1,000 ms
コード長 751 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 67,404 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 11:44:37
合計ジャッジ時間 1,813 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 7 ms
6,676 KB
testcase_04 AC 8 ms
6,676 KB
testcase_05 AC 7 ms
6,676 KB
testcase_06 AC 7 ms
6,676 KB
testcase_07 AC 6 ms
6,676 KB
testcase_08 AC 7 ms
6,676 KB
testcase_09 AC 7 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    string s;cin>>s;
    reverse(s.begin(),s.end());
    int ans = 0;
    for(int i = 0; s.size()-1 > i; i++){
        if(s[i] == '0')continue;
        if(s[i] == '1' && s[i+1] == '0'){
            //cout << i << endl;
            ans++;
            s[i] = '0';
        }else{
            //cout << "!" << i << endl;
            int z = i+1;
            for(; s[z] == '1' && s.size() > z;z++){
                s[z] = '0';
            }
            ans++;
            if(s.size() == z){
                cout << ans+1 << endl;
                return 0;
            }
            s[z] = '1';
            i = z-1;
        }
    }
    cout << ans+(s[s.size()-1]=='1'?1:0) << endl;
}
0