# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
17916 | 2016-01-13T07:55:31 Z | Adilkhan | Bank (IZhO14_bank) | C++ | 81 ms | 4676 KB |
#include <bits/stdc++.h> #define pb push_back #define endl "\n" #define mp make_pair #define fi first #define se second #define all(x) x.begin(), x.end() #define fname "" #define sz(x) (int)(x.size()) typedef long long ll; using namespace std; const ll N = (ll)(5e5) + 322; const ll INF = (ll)(1e9); const ll mod = (ll)(1e9) + 7; const double eps = 1e-9; int n, m, x, nz, sum, q[1248576], suff[33]; vector <int> a, b; void calc(int pmsk, int x) { if (x == n) { puts("YES"); exit(0); } for (int mask = 0; mask < (1 << m); ++mask) { if ((mask & pmsk)) {continue;} if (m - (__builtin_popcount(mask) + __builtin_popcount(pmsk)) < (n - x - 1)) {continue;} if (q[((1 << m) - 1) ^ (pmsk ^ mask)] < suff[x + 1]) {continue;} if (q[mask] == a[x]) { calc(pmsk ^ mask, x + 1); } } } void precalc() { for (int mask = 0; mask < (1 << m); ++mask) { sum = 0; for (int i = 0; i < m; ++i) { if ((1 << i) & mask) { sum += b[i]; } } q[mask] = sum; } } int main () { //ios_base :: sync_with_stdio (false); cin.tie(0); //freopen(fname".in", "r", stdin); //freopen(fname".out", "w", stdout); scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%d", &x); a.pb(x); } for (int i = 1; i <= m; ++i) { scanf("%d", &x); b.pb(x); } for (int i = n - 1; i >= 0; --i) {suff[i] = suff[i + 1] + a[i];} precalc(); if (n > m) { puts("NO"); return 0; } if (n == m) { sort(all(a)); sort(all(b)); if (a == b) { puts("YES"); }else { puts("NO"); } return 0; } sort(all(a)); reverse(all(a)); calc(0, 0); puts("NO"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | Output is correct |
2 | Correct | 2 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 4 ms | 544 KB | Output is correct |
5 | Correct | 79 ms | 4444 KB | Output is correct |
6 | Correct | 2 ms | 4444 KB | Output is correct |
7 | Correct | 2 ms | 4444 KB | Output is correct |
8 | Correct | 69 ms | 4676 KB | Output is correct |
9 | Correct | 81 ms | 4676 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4676 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 4676 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | Output is correct |
2 | Correct | 2 ms | 488 KB | Output is correct |
3 | Correct | 2 ms | 488 KB | Output is correct |
4 | Correct | 4 ms | 544 KB | Output is correct |
5 | Correct | 79 ms | 4444 KB | Output is correct |
6 | Correct | 2 ms | 4444 KB | Output is correct |
7 | Correct | 2 ms | 4444 KB | Output is correct |
8 | Correct | 69 ms | 4676 KB | Output is correct |
9 | Correct | 81 ms | 4676 KB | Output is correct |
10 | Incorrect | 2 ms | 4676 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |