結果
| 問題 | No.3114 0→1 |
| コンテスト | |
| ユーザー |
テナガザル
|
| 提出日時 | 2025-04-19 02:53:19 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WJ
不安定
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 606 bytes |
| 記録 | |
| 最終ジャッジ日時 | 2026-10-16 03:23:14 |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge2_0 |
(要ログイン)
ソースコード
#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;
}
テナガザル