Submission #792572

#TimeUsernameProblemLanguageResultExecution timeMemory
792572vjudge1Lamps (JOI19_lamps)C++17
0 / 100
32 ms64332 KiB
#ifdef Home #define _GLIBCXX_DEBUG #endif // Home #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int N = 2022; string a, b; int dp[N][N][4]; // 0 don't touched // 1 turn off all // 2 turn on all // 3 toggle all int change(int pr, int cr) { return cr == 3 ? 3 - pr : (cr ? cr : pr); } int recur(int l, int r, int sts) { int &ans = dp[l][r][sts]; if(ans != -1) { return ans; } if(l + 1 == r) { if(sts == 0) { return ans = (a[l] != b[l]); } if(sts == 1) { return ans = ('0' != b[l]); } if(sts == 2) { return ans = ('1' != b[l]); } return ans = (a[l] == b[l]); } ans = r - l; for(int m = l + 1; m < r; ++ m) { int ansl = recur(l, m, sts); for(int nwsts = 1; nwsts < 4; ++ nwsts) { ansl = min(ansl, recur(l, m, change(sts, nwsts)) + 1); } int ansr = recur(m, r, sts); for(int nwsts = 1; nwsts < 4; ++ nwsts) { ansr = min(ansr, recur(m, r, change(sts, nwsts)) + 1); } ans = min(ans, ansl + ansr); } return ans; } main() { #ifdef Home freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // Home ios_base::sync_with_stdio(0); cin.tie(0); memset(dp, -1, sizeof dp); int n; cin >> n >> a >> b; cout << recur(0, n, 0); }

Compilation message (stderr)

lamp.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...