Submission #1158779

#TimeUsernameProblemLanguageResultExecution timeMemory
1158779AgentPengin은행 (IZhO14_bank)C++20
100 / 100
97 ms8660 KiB
/**
 *    author:  AgentPengin ( Độc cô cầu bại )
 *    created: 23.12.2022 10:08:02
 *    too lazy to update time
**/
#include<bits/stdc++.h>

#define EL '\n'
#define fi first
#define se second
#define NAME "TASK"
#define ll long long
#define lcm(a,b) (a/gcd(a,b))*b
#define db(val) "["#val" = " << (val) << "] "
#define bend(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
#define ex exit(0)

using namespace std;

const ll mod = 1e9 + 7;
const int inf = 0x1FFFFFFF;
const int MAXN = 1e5 + 5;

int n, m;

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    if (ifstream(NAME".inp")) {
        freopen(NAME".inp","r",stdin);
        freopen(NAME".out","w",stdout);
    }
    cin >> n >> m;
    vector<int> person(n);
    vector<int> notes(m);	
    vector<int> dp, left;
    dp.resize((1 << m), -1);
    left.resize((1 << m), -1);
    for (auto &x : person) cin >> x;
    for (auto &x : notes) cin >> x;
    dp[0] = left[0] = 0;
    for (int mask = 0;mask < (1 << m);mask++) {
    	for (int i = 0;i < m;i++) {
    		if (!(mask >> i & 1)) continue;
    		int last_state = mask &~ (1 << i);
    		if (dp[last_state] == -1) continue;
    		
    		int money_need = person[dp[last_state]];
    		int cur_money_left = left[last_state] + notes[i];
    		
    		if (cur_money_left < money_need) {
    			dp[mask] = dp[last_state];
    			left[mask] = cur_money_left;
    		} else if (cur_money_left == money_need) {
    			dp[mask] = dp[last_state] + 1;
    			left[mask] = 0;
    		}
    	}
    	if (dp[mask] == n) {
    		return cout << "YES", 0;
    	}
    }
    cout << "NO";
    
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
// agent pengin wants to take apio (with anya-san)

Compilation message (stderr)

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