Submission #1206894

#TimeUsernameProblemLanguageResultExecution timeMemory
1206894nguynLamps (JOI19_lamps)C++20
100 / 100
52 ms31676 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second #define pb push_back #define pii pair<int,int> const int N = 1e6 + 5; int n; int a[N], b[N]; int f[N][3][2]; signed main(){ ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ; if (fopen("INP.INP" ,"r")) { freopen("INP.INP" ,"r" , stdin) ; freopen("OUT.OUT" , "w" , stdout) ; } cin >> n; for (int i = 1; i <= n; i++) { char x; cin >> x; a[i] = (x == '1' ? 1 : 0); } for (int i = 1; i <= n; i++) { char x; cin >> x; b[i] = (x == '1' ? 1 : 0); } for (int i = 0; i <= n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 2; k++) { f[i][j][k] = 1e9; } } } f[0][0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 2; k++) { int cur = a[i]; if (j == 1) cur = 0; if (j == 2) cur = 1; if (k == 1) cur ^= 1; if (cur != b[i]) continue; for (int jj = 0; jj < 3; jj++) { for (int kk = 0; kk < 2; kk++) { f[i][j][k] = min(f[i][j][k], f[i - 1][jj][kk] + (j > 0 && j != jj) + (k > 0 && k != kk)); } } } } } int res = 1e9; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { res = min(res, f[n][i][j]); } } cout << res; }

Compilation message (stderr)

lamp.cpp: In function 'int main()':
lamp.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("INP.INP" ,"r" , stdin) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("OUT.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...