Submission #716504

#TimeUsernameProblemLanguageResultExecution timeMemory
716504lukameladzeLamps (JOI19_lamps)C++14
100 / 100
47 ms16056 KiB
// 1. SET 2. switches // dp[i][j] ---> j = 1 set 0; j = 2 set 1; j = 0 X # include <bits/stdc++.h> using namespace std; #define f first #define s second // #define int long long #define pii pair <int, int> #define pb push_back const int N = 1e6 + 5, inf = 1e9; int t,n,a[N],dp[N][3]; string s,s1; main() { std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n>>s>>s1; s = "@" + s; s1 = "@" + s1; for (int i = 0; i <= n; i++) for (int j = 0; j <= 2; j++) dp[i][j] = inf; dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { int cur, pre; if (j) cur = j - 1; else cur = (int)(s[i] - '0'); if (k) pre = k - 1; else pre = (int)(s[i - 1] - '0'); dp[i][j] = min(dp[i][j], dp[i - 1][k] + (j && j != k) + (pre == (int)(s1[i - 1] - '0') && cur != (int)(s1[i] - '0'))); } } } cout<<min(dp[n][0], min(dp[n][1], dp[n][2]))<<"\n"; }

Compilation message (stderr)

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