結果
問題 | No.3114 0→1 |
ユーザー |
![]() |
提出日時 | 2025-04-19 02:53:19 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 606 bytes |
コンパイル時間 | 1,101 ms |
コンパイル使用メモリ | 99,740 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-04-19 02:53:21 |
合計ジャッジ時間 | 2,596 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; cin >> n; string s; cin >> s; if (n == 1) { cout << 0 << endl; return 0; } vector<int> dp(4); if (s[0] == '0') { ++dp[2]; ++dp[3]; } if (s[1] == '0') { ++dp[1]; ++dp[3]; } for (int i = 2; i < n; ++i) { vector<int> ndp(4); ndp[1] = dp[2] + (s[i] == '0'); ndp[2] = dp[3]; ndp[3] = min(dp[1], dp[3]) + (s[i] == '0'); swap(ndp, dp); } int ans = 1e9; for (int i = 1; i < 4; ++i) ans = min(ans, dp[i]); cout << ans << endl; }