이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Faster!
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e6+10,mod=1e9+7;
const ll inf=1e18;
int dp[maxn][3][2];
string A,B;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int n;cin>>n>>A>>B;
for(int i=1;i<=n;i++){
int a=A[i-1]-'0',b=B[i-1]-'0';
for(int j=0;j<3;j++)
for(int k=0;k<2;k++)
dp[i][j][k]=n;
if(a==b){
for(int j=0;j<3;j++)
for(int k=0;k<2;k++)
dp[i][j][k]=min(dp[i][j][k],dp[i-1][0][0]);
}
else{
for(int j=0;j<3;j++)
for(int k=0;k<2;k++)
dp[i][j][k]=min(dp[i][j][k],(k==1 ? 0 : 1) + dp[i-1][0][1]);
}
for(int j=0;j<3;j++)
for(int k=0;k<2;k++)
dp[i][j][k]=min(dp[i][j][k],(j==b+1 ? 0 : 1) + dp[i-1][b+1][0] );
for(int j=0;j<3;j++)
for(int k=0;k<2;k++)
dp[i][j][k]=min(dp[i][j][k],(j==1-b+1 ? 0 : 1) + (k==1 ? 0 : 1) + dp[i-1][1-b+1][1] );
}
return cout<<dp[n][0][0]<<endl,0;
}
// Deathly mistakes:
// * Read the problem curfully.
// * Check maxn.
// * Overflows.
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |