# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
210748 | mhy908 | Lamps (JOI19_lamps) | C++14 | 66 ms | 19636 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 pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortvec(x) sort(all(x))
#define compress(x) x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=1987654321987654321;
const int inf=2000000000;
int dp[1000010][4];
int n;
char str1[1000010], str2[1000010];
char alter(char c, int qu){
if(qu==1)return '0';
if(qu==2)return '1';
return c;
}
int main(){
scanf("%d", &n);
scanf("%s", str1+1);
scanf("%s", str2+1);
dp[0][1]=dp[0][2]=inf;
for(int i=1; i<=n; i++)dp[i][1]=dp[i][2]=dp[i][3]=inf;
for(int i=1; i<=n; i++){
for(int j=1; j<=3; j++){
for(int k=1; k<=3; k++){
int temp=dp[i-1][j];
if(j!=k&&k!=3)temp++;
if((i==1||alter(str1[i-1], j)==str2[i-1])&&alter(str1[i], k)!=str2[i])temp++;
dp[i][k]=min(dp[i][k], temp);
}
}
//for(int j=1; j<=3; j++)printf("dp[%d][%d]=%d\n", i, j, dp[i][j]);
}
printf("%d", min(min(dp[n][1], dp[n][2]), dp[n][3]));
}
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... |