Submission #637029

#TimeUsernameProblemLanguageResultExecution timeMemory
637029ghostwriterBank (IZhO14_bank)C++14
100 / 100
139 ms4460 KiB
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
    Tran The Bao
    CTL - Da Lat
    Cay ngay cay dem nhung deo duoc cong nhan
*/
const int N = 20;
int n, m, a[N], b[N], f[N], d[1 << N];
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // freopen(file".inp", "r", stdin);
    // freopen(file".out", "w", stdout);
    cin >> n >> m;
    FOR(i, 0, n - 1) cin >> a[i];
    FOR(i, 0, m - 1) cin >> b[i];
    FOR(i, 0, n - 1) f[i] = (i > 0? f[i - 1] : 0) + a[i];
    FOR(msk, 1, (1 << m) - 1) {
    	int sum = 0;
    	FOR(i, 0, m - 1) {
    		if (!(msk & (1 << i))) continue;
    		sum += b[i];
    	}
    	FOR(i, 0, m - 1) {
    		if (!(msk & (1 << i))) continue;
    		int pre = d[msk ^ (1 << i)];
    		d[msk] = max(d[msk], pre);
    	}
    	if (f[d[msk]] != sum) continue;
    	++d[msk];
    	if (d[msk] == n) {
    		cout << "YES";
    		return 0;
    	}
    }
    cout << "NO";
    return 0;
}

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bank.cpp:43:5: note: in expansion of macro 'FOR'
   43 |     FOR(i, 0, n - 1) cin >> a[i];
      |     ^~~
bank.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bank.cpp:44:5: note: in expansion of macro 'FOR'
   44 |     FOR(i, 0, m - 1) cin >> b[i];
      |     ^~~
bank.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bank.cpp:45:5: note: in expansion of macro 'FOR'
   45 |     FOR(i, 0, n - 1) f[i] = (i > 0? f[i - 1] : 0) + a[i];
      |     ^~~
bank.cpp:24:31: warning: unnecessary parentheses in declaration of 'msk' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bank.cpp:46:5: note: in expansion of macro 'FOR'
   46 |     FOR(msk, 1, (1 << m) - 1) {
      |     ^~~
bank.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bank.cpp:48:6: note: in expansion of macro 'FOR'
   48 |      FOR(i, 0, m - 1) {
      |      ^~~
bank.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
bank.cpp:52:6: note: in expansion of macro 'FOR'
   52 |      FOR(i, 0, m - 1) {
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...