Submission #427241

#TimeUsernameProblemLanguageResultExecution timeMemory
427241cpp219Lamps (JOI19_lamps)C++14
100 / 100
214 ms145200 KiB
#pragma GCC optimization "O2" #pragma GCC optimization "unroll-loop" #pragma GCC target ("avx2") #include <bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second using namespace std; const ll N = 1e6 + 9; const ll inf = 1e9 + 7; const ll Log2 = 20; typedef pair<ll,ll> LL; string s,p; ll n,dp[N][3][2]; ll convert(ll now,ll zo,ll flip){ if (zo == 1) now = 0; if (zo == 2) now = 1; if (flip) now = 1 - now; return now; } ll f(ll pos,ll zo,ll flip){ if (pos > n) return 0; if (dp[pos][zo][flip] != -1) return dp[pos][zo][flip]; ll now = s[pos] - '0',ans = inf; for (ll i = 0;i < 3;i++) for (ll j = 0;j < 2;j++){ ll cur = convert(now,i,j),cost = 0; if (i && i != zo) cost++; if (j && j != flip) cost++; if (cur == p[pos] - '0') ans = min(ans,cost + f(pos + 1,i,j)); } return dp[pos][zo][flip] = ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "tst" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); } cin>>n>>s>>p; s = " " + s; p = " " + p; memset(dp,-1,sizeof(dp)); cout<<f(1,0,0); }

Compilation message (stderr)

lamp.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
lamp.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
lamp.cpp: In function 'int main()':
lamp.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...