Submission #1229888

#TimeUsernameProblemLanguageResultExecution timeMemory
1229888hainam2k9Lamps (JOI19_lamps)C++20
4 / 100
18 ms6356 KiB
#include <bits/stdc++.h> #define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0) #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout) #define ll long long #define ull unsigned long long #define i128 __int128 #define db long double #define sz(a) ((int)(a).size()) #define pb emplace_back #define pf emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define ins emplace #define mp make_pair using namespace std; const int MOD = 1e9+7, MAXN = 1e6+5; const string NAME = ""; int n,dp[MAXN],prefon=0,prefoff=0; char a[MAXN],b[MAXN]; int main() { tt; if(fopen((NAME + ".INP").c_str(), "r")) fo; cin >> n; for(int i = 1; i<=n; ++i) cin >> a[i]; for(int i = 1; i<=n; ++i) cin >> b[i]; memset(dp,0x3f,sizeof(dp)); dp[0]=0; for(int i=1, j=0, MINoff=0, MINon=0; i<=n; ++i){ if(b[i]=='0'&&b[i-1]!=b[i]) ++prefoff; if(b[i]=='1'&&b[i-1]!=b[i]) ++prefon; if(a[i]==b[i]) j=i, dp[i]=dp[i-1]; else{ dp[i]=dp[j]+1; if(b[i]=='0') dp[i]=min(dp[i],prefon+MINon+1); else dp[i]=min(dp[i],prefoff+MINoff+1); } if(b[i]=='0') MINoff=min(MINoff,dp[i]-prefoff+(a[i]=='0'&&a[i]+1=='0')); else MINon=min(MINon,dp[i]-prefon+(a[i]=='1'&&a[i+1]=='1')); } cout << dp[n]; }

Compilation message (stderr)

lamp.cpp: In function 'int main()':
lamp.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:27:45: note: in expansion of macro 'fo'
   27 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
lamp.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:27:45: note: in expansion of macro 'fo'
   27 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...