Submission #725057

#TimeUsernameProblemLanguageResultExecution timeMemory
725057theflessBank (IZhO14_bank)C++14
100 / 100
96 ms8640 KiB
#include<bits/stdc++.h> using namespace std; #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define Times cerr << "time: " << clock() / 1000.0 << endl #define fi first #define base 31 #define sz(x) (int)(x).size() #define se second #define ll long long #define mp make_pair #define pb push_back #define pii pair<int, int> #define all(x) (x).begin(), (x).end() #define task "name" const int oo = 1e9 + 7; const ll loo = (ll)1e18 + 7; const ll MOD = 1e9 + 7; const int MOD2 = 1e9 + 696969; const int N = 2e5 + 5; const int BASE = 10; template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;} template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;} int n,m,a[N],b[N],dp[(1 << 20) + 7],to[(1 << 20) + 7]; void Solve() { cin>>n>>m; for(int i = 1 ; i <= n ; i++) cin>>a[i]; for(int i = 0 ; i < m ; i++) cin>>b[i]; memset(dp,-1,sizeof dp); memset(to,-1,sizeof to); dp[0]=0; to[0]=1; for(int mask = 0 ; mask < (1 << m) ; mask++){ for(int cur = 0 ; cur < m ; cur++){ if(BIT(mask,cur) || dp[mask] == -1) continue; if(dp[mask] + b[cur] == a[to[mask]]){ dp[(mask | (1 << cur))] = 0; to[(mask | (1 << cur))] = to[mask]+1; } if(dp[mask] + b[cur] < a[to[mask]]){ dp[(mask | (1 << cur))] = dp[mask] + b[cur]; to[(mask | (1 << cur))] = to[mask]; } } if(to[mask] > n) return void(cout<<"YES"); } cout<<"NO"; } void file(){ if( fopen(task".inp","r")){ freopen(task".inp" , "r" , stdin); freopen(task".bug" , "w" , stderr); freopen(task".out" , "w" , stdout); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); file(); int T = 1; // cin >> T; while(T--) { Solve(); } return 0; }

Compilation message (stderr)

bank.cpp: In function 'void file()':
bank.cpp:55:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |        freopen(task".inp" , "r" , stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:56:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |        freopen(task".bug" , "w" , stderr);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:57:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |        freopen(task".out" , "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...