結果
| 問題 |
No.884 Eat and Add
|
| コンテスト | |
| ユーザー |
leaf_1415
|
| 提出日時 | 2019-09-13 22:00:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 1,000 ms |
| コード長 | 856 bytes |
| コンパイル時間 | 464 ms |
| コンパイル使用メモリ | 59,220 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-04 04:14:50 |
| 合計ジャッジ時間 | 1,031 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s;
int nx[200005];
int dp[200005][2];
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s;
int n = s.size();
reverse(s.begin(), s.end());
s += "00";
nx[n] = n+1;
for(int i = n-1; i >= 0; i--){
nx[i] = nx[i+1];
if(s[i+1] == '0') nx[i] = i+1;
}
for(int i = 0; i <= n+1; i++){
for(int j = 0; j < 2; j++){
dp[i][j] = 1e9;
}
}
dp[0][s[0]-'0'] = 0;
for(int i = 0; i <= n; i++){
dp[i+1][s[i+1]-'0'] = min(dp[i+1][s[i+1]-'0'], dp[i][0]);
dp[i+1][s[i+1]-'0'] = min(dp[i+1][s[i+1]-'0'], dp[i][1] + 1);
if(i < n) dp[nx[i]][1] = min(dp[nx[i]][1], dp[i][1] + 1);
}
/*for(int i = 0; i <= n+1; i++){
for(int j = 0; j < 2; j++){
cout << dp[i][j] << " ";
}
cout << endl;
}*/
cout << dp[n+1][0] << endl;
return 0;
}
leaf_1415