제출 #105863

#제출 시각아이디문제언어결과실행 시간메모리
105863Alexa2001Lamps (JOI19_lamps)C++17
0 / 100
1070 ms22344 KiB
#include <bits/stdc++.h> using namespace std; const int Nmax = 1e6 + 5; int a[Nmax], b[Nmax], a0[Nmax], b0[Nmax], ones[Nmax], dp[Nmax]; int i, j, n; int nr_ones(int x, int y) { return ones[y] - ones[x-1]; } int main() { // freopen("input", "r", stdin); cin.sync_with_stdio(false); cin >> n; string A, B; cin >> A >> B; for(i=1; i<=n; ++i) a0[i] = A[i-1] - '0', b0[i] = B[i-1] - '0'; for(i=1; i<=n+1; ++i) a[i] = a0[i-1] ^ a0[i], b[i] = b0[i-1] ^ b0[i]; for(i=1; i<=n+1; ++i) ones[i] = ones[i-1] + b[i]; for(i=1; i<=n+1; ++i) { dp[i] = dp[i-1] + (a[i] ^ b[i]); for(j=1; j<i; ++j) /// flip cu schimbare j...i dp[i] = min(dp[i], dp[j-1] + 2 + (a[i] ^ b[i] ^ 1) + (a[j] ^ b[j] ^ 1) + nr_ones(j+1, i) ); } cout << (dp[n+1] + 1)/2 << '\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...