結果
問題 | No.3114 0→1 |
ユーザー |
|
提出日時 | 2025-04-29 21:43:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 614 bytes |
コンパイル時間 | 2,299 ms |
コンパイル使用メモリ | 193,644 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2025-04-29 21:43:29 |
合計ジャッジ時間 | 4,440 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; string s; cin >> n >> s; constexpr array<int,4> S = {0b011, 0b101, 0b110, 0b111}; array<int, 8> dp{}, ndp; for(int i = 0; i < n; i++){ ndp.fill(1 << 30); int c = s[i] - '0'; for(auto U : S){ int NU = U / 2 + 4 * c; ndp[NU] = min(ndp[NU], dp[U]); ndp[NU ^ 4] = min(ndp[NU ^ 4], dp[U] + 1); } dp = ndp; } int ans = 1 << 30; for(auto U : S) ans = min(ans, dp[U]); cout << ans << '\n'; }