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>
using namespace std;
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define pll pair<lli,lli>
#define MAX 2000
#define INF (1ll<<60)
string st,fin;
lli n,a,b;
lli cambios[MAX+2],arr[MAX+2],dp[MAX+2],xors[MAX+2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> st >> fin;
rep(i,2,n) { //primero hare el de los cambios
cambios[i] = cambios[i-1];
if(fin[i-2] != fin[i-1]) cambios[i]++;
}
rep(i,1,n) { //ahora el de los xors
arr[i] = abs(st[i-1] - fin[i-1]);
xors[i] = xors[i-1];
if(arr[i] == 1 && arr[i-1] == 0) xors[i]++;
}
rep(i,1,n) {
dp[i] = INF;
repa(j,i,1) {
a = xors[i] - xors[j];
if (arr[j]) a++;
b = cambios[i] - cambios[j];
b = 1 + (b+1)/2;
dp[i] = min(dp[i], dp[j-1] + min(a,b));
}
//debug(dp[1]);
}
cout << dp[n];
return 0;
}
# | 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... |