Submission #865943

#TimeUsernameProblemLanguageResultExecution timeMemory
865943yeediotLamps (JOI19_lamps)C++14
100 / 100
92 ms90608 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define F first #define S second #define all(x) x.begin(),x.end() #define pii pair<int,int> #define pb push_back #define sz(x) (int)(x.size()) #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) #define vi vector<int> #define vp vector<pii> #define vvi vector<vi> //Don't open the standings during contests. void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } signed main(){ ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int n; cin>>n; string a,b; cin>>a>>b; a="#"+a; b="#"+b; vector<vector<int>>dp(n+1,vector<int>(6,8e18)); dp[0][0]=0; for(int i=1;i<=n;i++){ if(a[i]==b[i]){ dp[i][0]=min({dp[i-1][0],dp[i-1][1],dp[i-1][2],dp[i-1][3],dp[i-1][4],dp[i-1][5]}); } else{ dp[i][3]=min({dp[i-1][0]+1,dp[i-1][1]+1,dp[i-1][2]+1,dp[i-1][3],dp[i-1][4],dp[i-1][5]}); } if(b[i]=='0'){ dp[i][1]=min({dp[i-1][0]+1,dp[i-1][1],dp[i-1][2]+1,dp[i-1][3]+1,dp[i-1][4],dp[i-1][5]+1}); dp[i][5]=min({dp[i-1][0]+2,dp[i-1][1]+2,dp[i-1][2]+1,dp[i-1][3]+1,dp[i-1][4]+1,dp[i-1][5]}); } else{ dp[i][2]=min({dp[i-1][0]+1,dp[i-1][1]+1,dp[i-1][2],dp[i-1][3]+1,dp[i-1][4]+1,dp[i-1][5]}); dp[i][4]=min({dp[i-1][0]+2,dp[i-1][1]+1,dp[i-1][2]+2,dp[i-1][3]+1,dp[i-1][4],dp[i-1][5]+1}); } //cout<<dp[i][0]<<' '<<dp[i][1]<<' '<<dp[i][2]<<' '<<dp[i][3]<<' '<<dp[i][4]<<' '<<dp[i][5]<<'\n'; } cout<<min({dp[n][0],dp[n][1],dp[n][2],dp[n][3],dp[n][4],dp[n][5]})<<'\n'; } /* input: 0 1 1 2 2 3 3 4 1 3 5 2 3 */

Compilation message (stderr)

lamp.cpp: In function 'void setIO(std::string)':
lamp.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen((s + ".out").c_str(), "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...