Submission #887803

#TimeUsernameProblemLanguageResultExecution timeMemory
887803RequiemBank (IZhO14_bank)C++17
100 / 100
89 ms20712 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define MOD 1000000007 #define INF 1e18 #define fi first #define se second #define endl "\n" #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORD(i,a,b) for(int i=a;i>=b;i--) #define sz(a) ((int)(a).size()) #define pi 3.14159265359 #define TASKNAME "Bank" template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } using namespace std; typedef pair<int,int> ii; typedef pair<int,ii> iii; typedef vector<int> vi; const int MAXN = (1<<20) + 9; int leftover[MAXN]; int dp[MAXN]; int n, m, a[MAXN], b[MAXN]; main() { fast; if (fopen(TASKNAME".inp","r")){ freopen(TASKNAME".inp","r",stdin); freopen(TASKNAME".out","w",stdout); } memset(dp,-1,sizeof(dp)); dp[0] = 0; leftover[0] = 0; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=m;i++){ cin>>b[i]; } for(int i=1;i<(1<<m);i++){ for(int j=0;j<m;j++){ if (i & (1 << j)){ int prvmsk = i ^ (1<<j); int prvans = dp[prvmsk]; if (leftover[prvmsk] + b[j+1] == a[prvans+1]){ dp[i] = prvans+1; leftover[i] = 0; } else if (leftover[prvmsk] + b[j+1] < a[prvans+1]) { dp[i] = prvans; leftover[i] = leftover[prvmsk] + b[j+1]; } } } if (dp[i] == n) { cout<<"YES"<<endl; return 0; } } cout<<"NO"<<endl; }

Compilation message (stderr)

bank.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main()
      | ^~~~
bank.cpp: In function 'int main()':
bank.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen(TASKNAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen(TASKNAME".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...