# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1116224 | firewater | Lamps (JOI19_lamps) | C++14 | 22 ms | 29948 KiB |
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<bits/stdc++.h>
#define N 1001000
using namespace std;
int n,ans,a[N],b[N],f[N][5];
char s1[N],s2[N];
int main()
{
scanf("%d%s%s",&n,s1+1,s2+1);
for(int i=1;i<=n;++i)
a[i]=s2[i]-'0'+1,b[i]=(s1[i]!=s2[i]);
memset(f,127/3,sizeof(f));
f[0][0]=0;
b[0]=-1;
for(int i=1;i<=n;++i)
for(int j=0;j<=2;++j){
f[i][0]=min(f[i][0],f[i-1][j]+(b[i]&&(b[i]!=b[i-1]||j)));
if(j)f[i][j]=min(f[i][j],f[i-1][j]+(a[i]!=j&&a[i]!=a[i-1]));
f[i][a[i]]=min(f[i][a[i]],f[i-1][j]+1);
}
ans=f[0][1];
for(int j=0;j<=2;++j)
ans=min(ans,f[n][j]);
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
# | 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... |