Submission #173387

#TimeUsernameProblemLanguageResultExecution timeMemory
173387ZwariowanyMarcinLamps (JOI19_lamps)C++14
100 / 100
35 ms16040 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define ss(x) (int) x.size() #define pb push_back #define ll long long #define cat(x) cerr << #x << " = " << x << endl #define FOR(i, n) for(int i = 0; i < n; ++i) using namespace std; const int nax = 1e6 + 111; void mini(int &a, int b) { a = min(a, b); } int n; char a[nax]; char b[nax]; int t[nax][3]; int main() { a[0] = b[0] = '#'; scanf("%d", &n); scanf("%s", a + 1); scanf("%s", b + 1); t[0][0] = 0; t[0][1] = n; t[0][2] = n; for(int i = 1; i <= n; ++i) { t[i][0] = t[i][1] = t[i][2] = n; // 0 mini(t[i][0], t[i - 1][0] + (a[i] != b[i] && a[i - 1] == b[i - 1])); mini(t[i][0], t[i - 1][1] + (a[i] != b[i] && b[i - 1] == '1')); mini(t[i][0], t[i - 1][2] + (a[i] != b[i] && b[i - 1] == '0')); // 1 mini(t[i][1], t[i - 1][0] + 1 + (b[i] == '0' && a[i - 1] == b[i - 1])); mini(t[i][1], t[i - 1][1] + (b[i] == '0' && b[i - 1] == '1')); // 2 mini(t[i][2], t[i - 1][0] + 1 + (b[i] == '1' && a[i - 1] == b[i - 1])); mini(t[i][2], t[i - 1][2] + (b[i] == '1' && b[i - 1] == '0')); //printf("%d %d %d %d\n", i, t[i][0], t[i][1], t[i][2]); } printf("%d", min({t[n][0], t[n][1], t[n][2]})); return 0; }

Compilation message (stderr)

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