Submission #671852

#TimeUsernameProblemLanguageResultExecution timeMemory
671852BaytoroBank (IZhO14_bank)C++17
71 / 100
1088 ms17368 KiB
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define int long long #define endl '\n' void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const int INF=1e9,mod=1e9+7; int dp[(1ll<<20)+5],ok[(1ll<<20)+5]; void get(int x){ for(int i=0;i<20;i++) cout<<((x&(1<<i))?1:0); cout<<endl; } set<int> f(vector<int> a, vector<int> b){ int n=a.size(); int m=b.size(); set<int> ans; dp[0]=0; for(int i=0;i<n;i++){ for(int mask=1;mask<(1<<(m-1));mask++){ for(int j=0;j<m;j++){ if(mask&(1<<j)){ if(ok[mask^(1<<j)]!=i-1) continue; if((dp[mask^(1<<j)])+b[j]>a[i]) continue; dp[mask]=(dp[mask^(1<<j)])+b[j]; ok[mask]=i-1; //cout<<(1<<m)<<' '; //cout<<mask<<endl; if(dp[mask]==a[i]){ dp[mask]=0; ok[mask]=i; if(i==n-1){ //get(mask); ans.insert(mask); } } break; } } } } return ans; } int n,m; void solve(){ memset(ok,-1,sizeof(ok)); memset(dp,0x3f3f3f3f,sizeof(dp)); cin>>n>>m; vector<int> a(n+1),b(m+1); for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<m;i++) cin>>b[i]; vector<int> tmp; for(int i=0;i<n/2;i++) tmp.pb(a[i]); set<int> ans1=f(tmp,b); tmp.clear(); for(int i=n/2;i<n;i++) tmp.pb(a[i]); memset(ok,-1,sizeof(ok)); memset(dp,0x3f3f3f3f,sizeof(dp)); set<int> ans2=f(tmp,b); //cout<<ans2.size()<<endl; if(n==1){ if(ans2.size()>0) cout<<"YES\n"; else cout<<"NO\n"; return; } for(auto i: ans1){ if(ans2.size()==0) continue; for(auto j: ans2){ if(!(i&j)){ cout<<"YES\n"; return; } } } cout<<"NO\n"; } main(){ ios; int T=1; //cin>>T; while(T--){ solve(); } }

Compilation message (stderr)

bank.cpp:90:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   90 | main(){
      | ^~~~
bank.cpp: In function 'void fopn(std::string)':
bank.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".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...