結果
| 問題 |
No.884 Eat and Add
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-09 00:17:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 1,000 ms |
| コード長 | 751 bytes |
| コンパイル時間 | 636 ms |
| コンパイル使用メモリ | 67,320 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-01 05:34:16 |
| 合計ジャッジ時間 | 1,348 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
ソースコード
#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;
}