Submission #796808

#TimeUsernameProblemLanguageResultExecution timeMemory
796808vjudge1Lamps (JOI19_lamps)C++17
100 / 100
94 ms3328 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 inf = 1e9; // first // memory optimization // second // 0 - all 0, // 1 - all 1 // 2 - no changes, // thrid // 0 not have xor // 1 have xor main() { #ifdef Home freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // Home ios_base::sync_with_stdio(0); cin.tie(0); int n, cr = 1, pr = 0; string a, b; cin >> n >> a >> b; vector < vector < vector < int > > > dp(2, vector < vector < int > > (3, vector < int > (2, inf))); dp[pr][2][0] = 0; for(int i = 0; i < n; ++ i) { dp[cr] = {{inf, inf}, {inf, inf}, {inf, inf}}; if(a[i] == b[i]) { dp[cr][2][0] = min({dp[pr][2][0], dp[pr][2][1], dp[pr][1][0], dp[pr][1][1], dp[pr][0][0], dp[pr][0][1]}); } else { dp[cr][2][1] = min({dp[pr][2][0] + 1, dp[pr][2][1], dp[pr][1][0] + 1, dp[pr][1][1], dp[pr][0][0] + 1, dp[pr][0][1]}); } if(b[i] == '0') { dp[cr][0][0] = min({dp[pr][0][0], dp[pr][2][0] + 1, dp[pr][2][1] + 1, dp[pr][0][1], dp[pr][1][0] + 1, dp[pr][1][1] + 1}); dp[cr][1][1] = min({dp[pr][1][1], dp[pr][1][0] + 1, dp[pr][2][1] + 1, dp[pr][0][1] + 1, dp[pr][2][0] + 2, dp[pr][0][0] + 2}); } else { dp[cr][1][0] = min({dp[pr][1][0], dp[pr][2][0] + 1, dp[pr][2][1] + 1, dp[pr][1][1], dp[pr][0][0] + 1, dp[pr][0][1] + 1}); dp[cr][0][1] = min({dp[pr][0][1], dp[pr][0][0] + 1, dp[pr][2][1] + 1, dp[pr][1][1] + 1, dp[pr][2][0] + 2, dp[pr][1][0] + 2}); } swap(cr, pr); } cout << min({dp[pr][0][0], dp[pr][0][1], dp[pr][1][0], dp[pr][1][1], dp[pr][2][0], dp[pr][2][1]}); }

Compilation message (stderr)

lamp.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   24 | 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...