結果
問題 | No.884 Eat and Add |
ユーザー |
![]() |
提出日時 | 2019-09-13 22:44:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 1,000 ms |
コード長 | 470 bytes |
コンパイル時間 | 1,497 ms |
コンパイル使用メモリ | 168,872 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-04 10:06:58 |
合計ジャッジ時間 | 2,083 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main() { string s; cin>>s; s='0'+s; reverse(s.begin(),s.end()); int N=s.size(); int ans=0; for(int i=0;i<N;){ while(i<N and s[i]=='0') i++; int cnt=0; while(i<N and s[i]=='1') i++,cnt++; if(cnt==1){ ans+=1; if(i==N-1) break; }else{ ans+=1; s[i]='1'; } } cout<<ans<<endl; return 0; }