結果
問題 | No.3114 0→1 |
ユーザー |
|
提出日時 | 2025-04-19 17:30:00 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 849 bytes |
コンパイル時間 | 3,530 ms |
コンパイル使用メモリ | 274,896 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-04-19 17:30:05 |
合計ジャッジ時間 | 4,771 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; int dp[200010][2][2]; int main() { int N; cin >> N; string S; cin >> S; for(int i = 0; i <= N; i++) { for(int j = 0; j < 2; j++) { for(int k = 0; k < 2; k++) { dp[i][j][k] = INF; } } } // 110,101,011,111 dp[0][1][1] = 0; for(int i = 0; i < N; i++) { int num = S[i] - '0'; for(int j = 0; j < 2; j++) { for(int k = 0; k < 2; k++) { if(dp[i][j][k] == INF) continue; for(int n = 0; n < 2; n++) { if(num == 1 and n == 0) continue; if((n == 1 and j == 1 and k == 0) or (n == 1 and j == 0 and k == 1) or (n == 0 and j == 1 and k == 1) or (n == 1 and j == 1 and k == 1)) { dp[i + 1][n][j] = min(dp[i + 1][n][j], dp[i][j][k] + (num != n)); } } } } } cout << min({dp[N][1][1], dp[N][1][0], dp[N][0][1]}) << endl; }