Submission #958371

# Submission time Handle Problem Language Result Execution time Memory
958371 2024-04-05T14:46:31 Z FanOfWilliamLin Bank (IZhO14_bank) C++14
19 / 100
79 ms 16872 KB
#include <bits/stdc++.h>
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long 
#define ll long long
#define ld long double
#define ar array
#define vt vector
#define pb push_back
#define bit(i, x) ((x>>i)&1ULL)
#define pf push_front
#define all(v) v.begin(), v.end()
#define lla(v) v.rbegin(), v.rend()

const ll INF=1e18;
const ll MOD=1e9+7;
const ll M=(1ll<<61)-1;
//const ll MOD=998244353; 

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const ll base=uniform_int_distribution<ll>(0, M-1)(rng);

ll bpow(ll a, ll b, ll DOMDOM) {
	a%=DOMDOM;
	ll res=1;
	while(b>0) {
		if(b&1)
			res=res*a%DOMDOM;
		a=a*a%DOMDOM;
		b>>=1;
	}
	return res;
}

ll floor_div(ll x, ll y) {
	assert(y!=0);
	if (y<0) {
		y=-y;
		x=-x;
	}
	if (x>=0) return x/y;
	return (x+1)/y-1;
}

ll ceil_div(ll x, ll y) {
	assert(y!=0);
	if (y<0) {
		y=-y;
		x=-x;
	}
	if (x<=0) {
		return x/y;
	}
	return (x-1)/y+1;
}

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

void tmw() {
	//solve here
	int n, m;
	cin >> n >> m;
	vt<int> a(n), b(m);
	for(auto& ele: a) {
		cin >> ele;
	}
	for(auto& ele: b) {
		cin >> ele;
	}
	vt<int> cover((1<<m)+1, -1);
	vt<int> left((1<<m)+1, -1);
	cover[0]=0;
	left[0]=0;
	for(int msk=1; msk<(1<<m); ++msk) {
		for(int i=0; i<m; ++i) {
			if(!bit(i, msk)) {
				continue;
			}
			int pre_msk=msk-(1<<i);
			int new_amt=left[pre_msk]+b[i];
			int target=a[cover[pre_msk]];
			if(new_amt<target) {
				cover[msk]=cover[pre_msk];
				left[msk]=new_amt;
			}
			else if(new_amt==target) {
				cover[msk]=cover[pre_msk]+1;
				left[msk]=0;
			}
		}
		if(cover[msk]==n) {
			cout << "YES\n";
			return;
		}
	}
	cout << "NO\n";
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("bank.in", "r", stdin);
	//freopen("bank.out", "w", stdout);	

	int TC=1;
	//cin >> TC;
	while(TC--) {
		tmw();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 79 ms 16872 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 4 ms 16732 KB Output is correct
9 Correct 73 ms 16872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 79 ms 16872 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 4 ms 16732 KB Output is correct
9 Correct 73 ms 16872 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Halted 0 ms 0 KB -