結果
| 問題 | No.3114 0→1 |
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2025-04-18 20:28:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 14 ms / 2,000 ms |
| コード長 | 973 bytes |
| 記録 | |
| コンパイル時間 | 3,577 ms |
| コンパイル使用メモリ | 251,260 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-04-18 20:28:37 |
| 合計ジャッジ時間 | 5,015 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001LL
int main(){
int n;
cin>>n;
string s;
cin>>s;
if(n==1){
cout<<0<<endl;
return 0;
}
if(n==2){
if(s==string(2,'0'))cout<<1<<endl;
else cout<<0<<endl;
return 0;
}
vector<int> dp(1<<2,Inf32);
rep(i,1<<2){
if(i==0)continue;
dp[i] = 0;
if(((i>>1)&1)!=s[0]-'0')dp[i]++;
if(((i>>0)&1)!=s[1]-'0')dp[i]++;
}
for(int i=2;i<n;i++){
vector<int> dp2(1<<2,Inf32);
rep(j,4){
if(dp[j]==Inf32)continue;
rep(k,2){
if(((j>>1)&1)==0 && k==0)continue;
int nj = (j<<1) + k;
nj &= 3;
if(nj==0)continue;
int v = dp[j];
if(k!=s[i]-'0')v++;
dp2[nj] = min(dp2[nj],v);
}
}
swap(dp,dp2);
}
int ans = Inf32;
rep(i,4)ans = min(ans,dp[i]);
cout<<ans<<endl;
return 0;
}
沙耶花