結果
問題 |
No.3114 0→1
|
ユーザー |
|
提出日時 | 2025-04-18 20:24:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 1,141 bytes |
コンパイル時間 | 1,955 ms |
コンパイル使用メモリ | 198,220 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2025-04-18 20:24:56 |
合計ジャッジ時間 | 3,298 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; //#include<atcoder/all> //using namespace atcoder; using ll = long long int; using ull = unsigned long long int; using ld = long double; constexpr ll MAX = 2000000000000000000; constexpr ld PI = 3.14159265358979; constexpr ll MOD = 0;//2024948111; ld dotorad(ld K){ return PI * K / 180.0; } ld radtodo(ld K){ return K * 180.0 / PI; } mt19937 mt; void randinit(){ srand((unsigned)time(NULL));mt = mt19937(rand()); } int main(){ ll N; string S; cin >> N >> S; vector<vector<ll>> DP(4,vector<ll>(N + 1,MAX)); DP[3][0] = 0; for(ll i = 0;i < N;i++){ for(ll now = 0;now < 4;now++){ ll nxt = (now * 2 + 0) % 4; if(now % 2 != 0 && now != 1){ DP[nxt][i + 1] = min(DP[nxt][i + 1],DP[now][i] + ('0' != S[i])); } } for(ll now = 0;now < 4;now++){ ll nxt = (now * 2 + 1) % 4; DP[nxt][i + 1] = min(DP[nxt][i + 1],DP[now][i] + ('1' != S[i])); } } ll ans = MAX; for(ll i = 0;i < 4;i++){ ans = min(ans,DP[i][N]); } cout << ans << endl; }