Submission #479036

#TimeUsernameProblemLanguageResultExecution timeMemory
479036uroskBank (IZhO14_bank)C++14
100 / 100
155 ms31628 KiB
// __builtin_popcount(x) broj bitova // __builtin_popcountll(x) long long #define here cerr<<"---------------------------\n" #include "bits/stdc++.h" #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #define ld double #define ll long long #define ull unsigned long long #define llinf 100000000000000000LL // 10^17 #define iinf 2000000000 // 2*10^9 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pii pair<int,int> #define pll pair<ll,ll> #define pld pair<ld,ld> #define sz(a) int(a.size()) #define all(a) a.begin(),a.end() #define rall(a) a.begin(),a.end(),greater<int>() #define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());} using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; void setIO(string inoutname) { freopen((inoutname+".in").c_str(),"r",stdin); freopen((inoutname+".out").c_str(),"w",stdout); } #define mod 1 ll gcd(ll a, ll b) { if(b==0) return a; if(a==0) return b; if(a>=b) return gcd(a%b,b); return gcd(a,b%a); } ll lcm(ll a,ll b){ return (a/gcd(a,b))*b; } ll add(ll a,ll b){ a+=b; a+=mod; if(a>=mod) a%=mod; return a; } ll mul(ll a,ll b){return(a*b)%mod;} #define maxn 25 #define maxx 2000005 ll n,m; ll a[maxn]; ll b[maxn]; pll dp[maxx]; pll get(pll a,pll b){ if(a.fi>b.fi) return a; if(b.fi>a.fi) return b; if(a.sc>b.sc) return a; return b; } void tc(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); cin >> m >> n; for(ll i = 0;i<m;i++) cin >> a[i]; for(ll i = 0;i<n;i++) cin >> b[i]; for(ll i = 0;i<maxx;i++) dp[i] = {-1,-1}; dp[0] = {0,0}; for(ll mask = 1;mask<(1<<n);mask++){ for(ll i = 0;i<n;i++){ if(((1<<i)&mask)==0) continue; if(dp[mask^(1<<i)].fi==-1) continue; ll c = dp[mask^(1<<i)].sc + b[i]; ll j = a[dp[mask^(1<<i)].fi]; ll nf=-1,ns=-1; if(c<j){ nf = dp[mask^(1<<i)].fi; ns = c; if(dp[mask].fi==-1) dp[mask] = {nf,ns}; else dp[mask] = get(dp[mask],{nf,ns}); }else if(c==j){ nf = dp[mask^(1<<i)].fi+1; ns = 0; if(dp[mask].fi==-1) dp[mask] = {nf,ns}; else dp[mask] = get(dp[mask],{nf,ns}); } } if(dp[mask].fi==m){ cout<<"YES"<<endl; return; } } cout<<"NO"<<endl; return; } int main(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); //setIO("lol"); int t; t = 1; while(t--){ tc(); } return 0; } /* 1 5 8 4 2 5 1 3 */

Compilation message (stderr)

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