Submission #427949

#TimeUsernameProblemLanguageResultExecution timeMemory
427949juggernautLamps (JOI19_lamps)C++17
0 / 100
55 ms9160 KiB
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} typedef long long ll; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef IOI2021SG #define printl(args...)printf(args) #else #define printl(args...)((void)0) #endif int n; int dp[200005]; int b[200005]; int c[200005]; string A,B; int main(){ cin>>n>>A>>B; A=" "+A; B=" "+B; for(int i=1;i<=n;i++){ b[i]=b[i-1]+(B[i]=='0'); c[i]=c[i-1]+(B[i]!=A[i]); } for(int i=1;i<=n;i++){ dp[i]=i; for(int j=1;j<=i;j++){ if(b[i]-b[j-1]==0||b[i]-b[j-1]==i-j+1)umin(dp[i],dp[j-1]+1); if(c[i]-c[j-1]==0)umin(dp[i],dp[j-1]); if(c[i]-c[j-1]==i-j+1)umin(dp[i],dp[j-1]+1); } } cout<<dp[n]; }

Compilation message (stderr)

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