Submission #972232

# Submission time Handle Problem Language Result Execution time Memory
972232 2024-04-30T09:05:54 Z hihihihaw Bank (IZhO14_bank) C++17
0 / 100
109 ms 262144 KB
#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

int main() {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
	int people_num;
	int note_num;
	std::cin >> people_num >> note_num;
	vector<int> people(people_num);
	vector<int> banknotes(note_num);
	for (int &p : people) { std::cin >> p; }
	for (int &b : banknotes) { std::cin >> b; }

	vector<int> leftover(1 << note_num, -1);
	vector<int> people_covered(1 << note_num, -1);
	leftover[0] = 0;
	people_covered[0] = 0;
	for (int s = 0; s < (1 << note_num); s++) {
        int y=0;
        int c=-1;
		for (int last = 0; last < note_num; last++) {
			if ((s & (1 << last)) == 0) { continue; }
			int prev = s & ~(1 << last);
			if (people_covered[prev] == -1) { continue; }

			int new_amt = leftover[prev] + banknotes[last];
			// the salary of the current person we're going to try to pay
			int curr_target = people[people_covered[prev]];
			// if it's still not enough, just increment the leftover pile
			if (new_amt < curr_target) {
				people_covered[s] = people_covered[prev];
				leftover[s] = new_amt;
                if (c==-1) c=new_amt;
                else {
                    if (c!=new_amt) cout<<"nuh uh"<<endl;
                }
                y|=1;
			}
			/*
			 * or it's exactly right, in which case reset the leftover count
			 * and increment the covered amount
			 */
			else if (new_amt == curr_target) {
				people_covered[s] = people_covered[prev] + 1;
				leftover[s] = 0;
                y|=2;
			}
		}
        if (y==3){
            cout<<s<<endl;
            cout<<-1<<endl;
        }
		// we've covered all the people!
		if (people_covered[s] == people_num) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

Compilation message

bank.cpp: In function 'int main()':
bank.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bank.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen("out.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 109 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 106 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -