Submission #127194

#TimeUsernameProblemLanguageResultExecution timeMemory
127194dndhkLamps (JOI19_lamps)C++14
100 / 100
230 ms35928 KiB
#include <bits/stdc++.h> #define pb push_back #define all(v) ((v).begin(), (v).end()) #define sortv(v) sort(all(v)) #define sz(v) ((int)(v).size()) #define uniqv(v) (v).erase(unique(all(v)), (v).end()) #define umax(a, b) (a)=max((a), (b)) #define umin(a, b) (a)=min((a), (b)) #define FOR(i,a,b) for(int i = (a); i <= (b); i++) #define rep(i,n) FOR(i,1,n) #define rep0(i,n) FOR(i,0,(int)(n)-1) #define FI first #define SE second #define INF 1000000000 #define INFLL 1000000000000000000LL using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAX_N = 1000000; int N; string A, B; pii type[MAX_N+1]; int dp[MAX_N+10][2][3]; int main(){ scanf("%d", &N); cin>>A; cin>>B; for(int i=0; i<N; i++){ type[i+1] = {(A[i] - '0'), (B[i] - '0')}; } for(int i=0; i<2; i++){ for(int j=0; j<3; j++){ dp[0][i][j] = INF; } } dp[0][0][0] = 0; for(int n=1; n<=N; n++){ for(int i=0; i<2; i++){ for(int j=0; j<3; j++){ dp[n][i][j] = INF; for(int i2=0; i2<2; i2++){ for(int j2=0; j2<3; j2++){ int pl = 0; if(i==1 && i2==0) pl++; if(j!=j2 && j!=0) pl++; dp[n][i][j] = min(dp[n][i][j], dp[n-1][i2][j2] + pl); } } if(type[n].first==0){ if(type[n].second==0){ dp[n][0][2] = dp[n][1][0] = dp[n][1][1] = INF; }else{ dp[n][0][0] = dp[n][0][1] = dp[n][1][2] = INF; } }else{ if(type[n].second==0){ dp[n][0][0] = dp[n][0][2] = dp[n][1][1] = INF; }else{ dp[n][0][1] = dp[n][1][0] = dp[n][1][2] = INF; } } } } } int ans = INF; for(int i=0; i<2; i++){ for(int j=0; j<3; j++){ ans = min(ans, dp[N][i][j]); } } cout<<ans; return 0; }

Compilation message (stderr)

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