Submission #261533

#TimeUsernameProblemLanguageResultExecution timeMemory
261533mjkocijanLamps (JOI19_lamps)C++14
100 / 100
202 ms27772 KiB
#include <bits/stdc++.h> using namespace std; #define X first #define Y second #define pb push_back typedef long long ll; typedef pair<ll, ll> ii; #define MAXN 1001001 int n; char a[MAXN], b[MAXN]; int dp[MAXN][3][2], reza = MAXN; int main() { scanf("%d", &n); scanf("%s", a); scanf("%s", b); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 2; k++) { dp[i][j][k] = MAXN; for (int l = 0; l < 3; l++) { for (int m = 0; m < 2; m++) {//cout << i <<' '<<j<<' '<<k<<'.'<<l<<' '<<m<<','<<dp[i][j][k]<<endl; if (i == 0 && (l || m)) continue;//cout<<'.'; int bk; if (j) bk = (j - 1) ^ k; else bk = (a[i] - '0') ^ k; if (bk != b[i] - '0') continue;//cout<<'/'; dp[i][j][k] = min(dp[i][j][k], (i ? dp[i - 1][l][m] : 0) + (j != l && j) * 2 + (k != m)); if (i == n - 1) reza = min(reza, dp[i][j][k]); } } //cout << i << ' ' <<j <<' ' << k <<'.'<<dp[i][j][k]<<endl; } } } //cout << ceil(double(reza) / 2.0) << endl; printf("%d\n", (int)ceil(double(reza) / 2.0)); return 0; }

Compilation message (stderr)

lamp.cpp: In function 'int main()':
lamp.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
lamp.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", a);
  ~~~~~^~~~~~~~~
lamp.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", b);
  ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...