This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int aa[n];
int bb[n];
char ss;
for(int i=0;i<n;i++){
cin>>ss;
if(ss=='1'){
aa[i]=1;
}
else{
aa[i]=0;
}
}
for(int i=0;i<n;i++){
cin>>ss;
if(ss=='1'){
bb[i]=1;
}
else{
bb[i]=0;
}
}
int dp[n][3];
if(aa[0]==bb[0]){
dp[0][2]=0;
}
else{
dp[0][2]=1;
}
if(bb[0]==1){
dp[0][0]=2;
}
else{
dp[0][0]=1;
}
if(bb[0]==0){
dp[0][1]=2;
}
else{
dp[0][1]=1;
}
for(int i=1;i<n;i++){
for(int j=0;j<3;j++){
dp[i][j]=n;
//0
int co=n;
int x,y,z;
x=dp[i-1][0];
y=dp[i-1][1]+1;
z=dp[i-1][2]+1;
if(bb[i-1]==0 and bb[i]==1){
x+=1;
}
if(bb[i-1]==1 and bb[i]==1){
y+=1;
}
if(bb[i-1]==aa[i-1] and bb[i]==1){
z+=1;
}
dp[i][0]=min(x,min(y,z));
//1
x=dp[i-1][0]+1;
y=dp[i-1][1];
z=dp[i-1][2]+1;
if(bb[i-1]==0 and bb[i]==0){
x+=1;
}
if(bb[i-1]==1 and bb[i]==0){
y+=1;
}
if(bb[i-1]==aa[i-1] and bb[i]==0){
z+=1;
}
dp[i][1]=min(x,min(y,z));
//2
x=dp[i-1][0];
y=dp[i-1][1];
z=dp[i-1][2];
if(bb[i-1]==0 and bb[i]==1-aa[i]){
x+=1;
}
if(bb[i-1]==1 and bb[i]==1-aa[i]){
y+=1;
}
if(bb[i-1]==aa[i-1] and bb[i]==1-aa[i]){
z+=1;
}
dp[i][2]=min(x,min(y,z));
}
}
cout<<min(dp[n-1][0],min(dp[n-1][1],dp[n-1][2]))<<endl;
return 0;
}
Compilation message (stderr)
lamp.cpp: In function 'int main()':
lamp.cpp:57:8: warning: unused variable 'co' [-Wunused-variable]
int co=n;
^~
# | 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... |