Submission #907450

#TimeUsernameProblemLanguageResultExecution timeMemory
907450zhasynBank (IZhO14_bank)C++14
0 / 100
3 ms2396 KiB
#include <bits/stdc++.h> #define pb push_back #define pf push_front using namespace std; #define F first #define S second typedef long long ll; #define pii pair <int, int> #define pll pair <ll, ll> typedef long double ld; const ll N = 1e6 + 1e5 + 10; const ll mod = 998244353; ll um(ll a, ll b){ return ((1LL * a * b) % mod + mod) % mod; } ll subr(ll a, ll b){ return ((1LL * a - b) % mod + mod) % mod; } int a[N], b[N], n, m; int dp[N], last[N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); freopen("bank.in", "r", stdin); freopen("bank.out", "w", stdout); cin >> n >> m; for(int i = 0; i < n; i++){ cin >> a[i]; } for(int i = 0; i < m; i++){ cin >> b[i]; } bool can = false; for(int mask = 0; mask < (1 << m); mask++){ dp[mask] = -1; } dp[0] = 0; for(int mask = 0; mask < (1 << m); mask++){ for(int dig = 0; dig < m; dig++){ if((mask & (1 << dig)) > 0){ int nw = mask ^ (1 << dig); int mx = dp[nw], rest = last[nw]; if(dp[nw] == -1) continue; if(last[nw] + b[dig] == a[dp[nw]]){ mx++; rest = 0; } else rest += b[dig]; if(mx >= dp[mask]){ dp[mask] = mx; last[mask] = rest; } } } if(dp[mask] == n){ can = true; break; } } if(can) cout << "YES\n"; else cout << "NO\n"; return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:25:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |    freopen("bank.in", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:26:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |    freopen("bank.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...