結果
| 問題 | No.884 Eat and Add |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-09-22 14:42:01 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 2 ms / 1,000 ms |
| + 447µs | |
| コード長 | 461 bytes |
| 記録 | |
| コンパイル時間 | 1,189 ms |
| コンパイル使用メモリ | 215,552 KB |
| 実行使用メモリ | 9,848 KB |
| 最終ジャッジ日時 | 2026-09-22 14:42:05 |
| 合計ジャッジ時間 | 3,156 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge5_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin>>s;
reverse(s.begin(),s.end());
int cnt=0,n=s.size();
for(int i=0;i<n;i++)cnt+=s[i]-'0';
int ans=cnt,dp0=0,dp1=1e9;
for(int i=0;i<n;i++){
if(s[i]=='1'){
dp1=min(dp0+1,dp1);
dp0=dp0+1;
}else{
dp0=min(dp0,dp1+1);
dp1=dp1+1;
}
cnt-=(s[i]=='1');
ans=min(ans,dp0+cnt);
}
cout<<min({ans,dp0,dp1+1});
return 0;
}
vjudge1