Submission #624069

#TimeUsernameProblemLanguageResultExecution timeMemory
624069Loki_NguyenLamps (JOI19_lamps)C++14
100 / 100
74 ms16176 KiB
#include <bits/stdc++.h> #define pll pair<ll, ll> #define fi first #define se second #define pb push_back #define task "tesddt" #define pii pair<ll, pll> using namespace std; using ll = long long; const int N = 1e6 + 2; const ll mod = 998244353; const ll base = 350; const ll inf = 1e15; int m, n, t, k, a[N], ans, dp[N][3]; void add(int& x, int y) { if(x == -1 || x > y)x = y; } void sol() { string A, B; cin >> n >> A >> B; memset(dp, -1, sizeof(dp)); dp[0][0] = 0; ans = -1; for(int i = 0; i < n; i ++) { for(int l = 0; l < 3; l ++) { if(dp[i][l] == -1)continue; //cout << i <<" "<<l<<" "<<dp[i][l] << '\n'; for(int r = 0; r < 3; r ++) { int cost = 0; if(l != r && r > 0)++cost; int vl, vr; if(r > 0)vr = r-1; else vr = A[i]-'0'; if(vr != B[i]-'0') { if(!i)++cost; else { if(l > 0)vl = l-1; else vl = A[i-1]-'0'; if(vl == B[i-1]-'0')++cost; } } //cout << r <<" "<<cost << '\n'; add(dp[i+1][r], dp[i][l]+cost); } } } for(int i = 0; i < 3; i ++)if(dp[n][i] != -1)add(ans, dp[n][i]); cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } int ntest = 1; // cin >> ntest; while (ntest-- > 0) sol(); }

Compilation message (stderr)

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