Submission #834870

#TimeUsernameProblemLanguageResultExecution timeMemory
834870OzyLamps (JOI19_lamps)C++17
0 / 100
7 ms6640 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...