Submission #1281408

#TimeUsernameProblemLanguageResultExecution timeMemory
1281408vuquangsangLamps (JOI19_lamps)C++20
100 / 100
41 ms14144 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 2; const int inf = 1e9 + 2; int n; string a, b; int dp[N][3]; void solve() { cin >> n >> a >> b; a = ' ' + a; b = ' ' + b; dp[0][0] = dp[0][1] = inf; dp[0][2] = 0; for(int i = 1; i <= n; i++) { bool tar = b[i] - '0'; for(int j : {0, 1, 2}) dp[i][j] = inf; for(int j : {0, 1, 2}) if(dp[i - 1][j] != inf) { bool tog = 0; if(i > 1) { int cur = (j == 2 ? a[i - 1] - '0' : j); tog = (cur != (b[i - 1] - '0')); } for(int k : {0, 1, 2}) { if(j != k && max(j, k) < 2) continue; int cur = k; if(cur == 2) cur = a[i] - '0'; dp[i][k] = min({dp[i][k], dp[i - 1][j] + (j == 2 && k < 2) + (!tog && cur != tar)}); } } } cout << min({dp[n][0], dp[n][1], dp[n][2]}); } main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define TASK "lamps" if(fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } solve(); cerr << "\nTime" << 0.001 * clock() << "s "; return 0; }

Compilation message (stderr)

lamp.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main()
      | ^~~~
lamp.cpp: In function 'int main()':
lamp.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...