結果
問題 |
No.3114 0→1
|
ユーザー |
![]() |
提出日時 | 2025-08-26 02:13:04 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,321 bytes |
コンパイル時間 | 4,008 ms |
コンパイル使用メモリ | 281,156 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-26 02:13:10 |
合計ジャッジ時間 | 5,129 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 WA * 6 |
ソースコード
#include <bits/stdc++.h> //#include <atcoder/modint> using namespace std; //using namespace atcoder; using ll = long long; //using mint = modint998244353; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* 00はアウト、010もアウト 逆にこれを含まないならば良い文字列 前2文字を持っておけば良い。 */ int N; string S; cin >> N >> S; if (N == 1){ cout << 0 << endl; return 0; } vector dp(2, vector<int>(2)); for (int i=0; i<2; i++){ for (int j=0; j<2; j++){ int x=S[0]-'0', y=S[1]-'0'; if (i != x) dp[i][j]++; if (j != y) dp[i][j]++; } } for (int i=2; i<N; i++){ int c = S[i]-'0'; vector pd(2, vector<int>(2, 1e9)); for (int j=0; j<2; j++){ for (int k=0; k<2; k++){ for (int l=0; l<2; l++){ if (j == 0 && k == 1 && l == 0) continue; if (k == 0 && l == 0) continue; pd[k][l] = min(pd[k][l], dp[j][k]+(c!=l)); } } } swap(dp, pd); } int ans=1e9; for (int i=0; i<2; i++) for (int j=0; j<2; j++) ans = min(ans, dp[i][j]); cout << ans << endl; return 0; }