Submission #1059857

#TimeUsernameProblemLanguageResultExecution timeMemory
1059857Madhav_1608Bank (IZhO14_bank)C++17
100 / 100
106 ms16984 KiB
#include <iostream> #include <stack> #include <queue> #include <string> #include <algorithm> #include <vector> #include <map> #include <set> #include <climits> #include <cmath> #include <unordered_map> #include <unordered_set> #include <numeric> using namespace std; // #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template <class T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long ll; typedef vector<int> vi; typedef vector<string> vs; typedef vector<long long int> vll; typedef pair<ll,ll> pll; #define double long double const double eps = 1e-9; #define FOR(i,a,b) for(long long int i=a;i<b;i++) #define all(v) v.begin(),v.end() template <typename I> void print(vector<I> &v){ FOR(i,0,v.size()-1){cout << v[i] << " ";} cout << v.back() << "\n"; } ll gcd(ll a,ll b){ if(a==0){return b;} else if(b==0){return a;} else if(a<b){return gcd(b%a,a);} else{return gcd(a%b,b);} } ll lcm(ll a,ll b){ return (a/gcd(a,b))*b; } ll merge_sort(vector<ll> &a,ll left,ll right,ll n){ if(left==right){ return 0; } else{ ll mid = (left+right)/2; ll x = merge_sort(a,left,mid,n); ll y = merge_sort(a,mid+1,right,n); // Do the operations here ...... ll mad = left; ll hav = mid+1; vector<ll> to_be; while(mad<=mid && hav<=right){ if(a[mad]<=a[hav]){ to_be.push_back(a[mad]); mad++; } else{ to_be.push_back(a[hav]); hav++; } } FOR(i,mad,mid+1){ to_be.push_back(a[i]); } FOR(i,hav,right+1){ to_be.push_back(a[i]); } FOR(i,left,right+1){ a[i] = to_be[i-left]; } return 0; } } void setIO(string name = "") { freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output freopen((name + ".out").c_str(), "w", stdout); } int main(){ //setIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n,m; cin >> n >> m; vll a(n); FOR(i,0,n){ cin >> a[i]; } vll b(m); FOR(i,0,m){ cin >> b[i]; } vector<pll> dp((1ll<<m),{0,0}); FOR(i,1,(1ll<<m)){ FOR(j,0,m){ if(((i>>j)&1)==1){ pll curr = dp[i-(1ll<<j)]; ll target = a[curr.first]; ll present = curr.second+b[j]; if(present<target){ dp[i] = max(dp[i],{curr.first,present}); } else if(present==target){ dp[i] = max(dp[i],{curr.first+1,0}); } } } if(dp[i].first==n){ cout << "YES" << "\n"; return 0; } } cout << "NO" << "\n"; return 0; }

Compilation message (stderr)

bank.cpp: In function 'll merge_sort(std::vector<long long int>&, ll, ll, ll)':
bank.cpp:50:12: warning: unused variable 'x' [-Wunused-variable]
   50 |         ll x = merge_sort(a,left,mid,n);
      |            ^
bank.cpp:51:12: warning: unused variable 'y' [-Wunused-variable]
   51 |         ll y = merge_sort(a,mid+1,right,n);
      |            ^
bank.cpp: In function 'void setIO(std::string)':
bank.cpp:81:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |     freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:82:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |     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...