Submission #717657

#TimeUsernameProblemLanguageResultExecution timeMemory
717657Urvuk3Bank (IZhO14_bank)C++17
100 / 100
139 ms8532 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int INF=1e9,MOD=1e9+7; const ll LINF=1e18; #define fi first #define se second #define pii pair<int,int> #define mid ((l+r)/2) #define sz(a) (int((a).size())) #define all(a) a.begin(),a.end() #define endl "\n" #define pb push_back void PRINT(int x) {cerr << x;} void PRINT(ll x) {cerr << x;} void PRINT(double x) {cerr << x;} void PRINT(char x) {cerr << '\'' << x << '\'';} void PRINT(string x) {cerr << '\"' << x << '\"';} void PRINT(bool x) {cerr << (x ? "true" : "false");} template<typename T,typename V> void PRINT(pair<T,V>& x){ cerr<<"{"; PRINT(x.fi); cerr<<","; PRINT(x.se); cerr<<"}"; } template<typename T> void PRINT(T &x){ int id=0; cerr<<"{"; for(auto _i:x){ cerr<<(id++ ? "," : ""); PRINT(_i); } cerr<<"}"; } void _PRINT(){ cerr<<"]\n"; } template<typename Head,typename... Tail> void _PRINT(Head h,Tail... t){ PRINT(h); if(sizeof...(t)) cerr<<", "; _PRINT(t...); } #define Debug(x...) cerr<<"["<<#x<<"]=["; _PRINT(x) void Solve(){ int N,M; cin>>N>>M; vector<int> a(N+1),b(M); for(int i=1;i<=N;i++) cin>>a[i]; for(int i=0;i<M;i++) cin>>b[i]; vector<int> dp((1<<M),0),left((1<<M),0); for(int m=0;m<(1<<M);m++){ //string sm=""; for(int j=M-1;j>=0;j--) sm.pb('0'+(int)((m&(1<<j))>0)); //Debug(sm); for(int i=0;i<M;i++){ if(m&(1<<i)){ int m1=m^(1<<i); //string sm1=""; for(int j=M-1;j>=0;j--) sm1.pb('0'+(int)((m1&(1<<j))>0)); //Debug(sm1); int dp_new=dp[m1]+(dp[m1]==N ? 0 : (left[m1]+b[i]==a[dp[m1]+1])); if(dp_new>dp[m]){ dp[m]=dp_new; if(dp_new==dp[m1]+1) left[m]=0; else left[m]=left[m1]+b[i]; } } } if(dp[m]==0){ for(int i=0;i<M;i++){ if(m&(1<<i)){ left[m]+=b[i]; } } } //Debug(dp[m],left[m]); //cerr<<endl; } cout<<(dp[(1<<M)-1]==N ? "YES" : "NO")<<endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; t=1; //cin>>t; while(t--){ Solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...