# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199926 | 2020-02-04T06:15:59 Z | quocnguyen1012 | Bootfall (IZhO17_bootfall) | C++14 | 91 ms | 13424 KB |
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; typedef long long ll; const int maxn = 505, mod = 1e9 + 7; int N, a[maxn]; int f[maxn * maxn]; set<int> ret; signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("A.INP", "r")){ freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); } cin >> N; int sum = 0; f[0] = 1; for (int i = 1; i <= N; ++i){ cin >> a[i]; sum += a[i]; for (int j = sum; j >= a[i]; --j){ f[j] += f[j - a[i]]; f[j] %= mod; } } if (sum & 1 || f[sum / 2] == 0){ cout << "NO"; return 0; } for (int i = 1; i < maxn * maxn; ++i){ ret.insert(i); } for (int i = 1; i <= N; ++i){ for (int j = a[i]; j <= sum; ++j){ f[j] -= f[j - a[i]]; if (f[j] < 0) f[j] += mod; } vector<int> vi; for (auto & all : ret){ int val = sum - a[i] + all; if (val < 0 || val % 2 == 1 || f[val / 2] == 0){ vi.pb(all); } } for (auto & it : vi) ret.erase(it); for (int j = sum; j >= a[i]; --j){ f[j] += f[j - a[i]]; f[j] %= mod; } } cout << ret.size() << '\n'; for (auto & it : ret) cout << it; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 85 ms | 13424 KB | Output is correct |
2 | Incorrect | 91 ms | 13420 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 85 ms | 13424 KB | Output is correct |
2 | Incorrect | 91 ms | 13420 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 85 ms | 13424 KB | Output is correct |
2 | Incorrect | 91 ms | 13420 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 85 ms | 13424 KB | Output is correct |
2 | Incorrect | 91 ms | 13420 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 85 ms | 13424 KB | Output is correct |
2 | Incorrect | 91 ms | 13420 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 85 ms | 13424 KB | Output is correct |
2 | Incorrect | 91 ms | 13420 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |