Submission #167661

#TimeUsernameProblemLanguageResultExecution timeMemory
167661RakhmandBootfall (IZhO17_bootfall)C++14
100 / 100
724 ms243956 KiB
// // ROIGold.cpp // Main calisma // // Created by Rakhman on 05/02/2019. // Copyright © 2019 Rakhman. All rights reserved. // #include <cstring> #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <queue> #include <cmath> #include <cstdlib> #include <ctime> #include <cassert> #include <iterator> #define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0); #define S second #define F first #define pb push_back #define nl '\n' #define NL cout << '\n'; #define EX exit(0) #define all(s) s.begin(), s.end() #define no_answer return cout << 0, 0; #define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k) const int MXN = 4e5 + 200; const long long MNN = 4e2 + 200; const long long MOD = 1e9 + 7; const long long INF = 1e18; const int OO = 1e9 + 500; typedef long long llong; typedef unsigned long long ullong; using namespace std; int n, k, a[MXN], cnt, dp[260000], del[510][126000]; int sum = 0; vector<int> v; void precalc(){ dp[0] = 1; for(int i = 1; i <= n; i++){ for(int j = sum; j >= 0; j--){ if(j - a[i] >= 0){ dp[j] += dp[j - a[i]]; } } } } void add(){ for(int i = 1; i <= n; i++){ for(int j = 0; j <= sum / 2; j++){ del[i][j] = dp[j]; if(j - a[i] >= 0){ del[i][j] -= del[i][j - a[i]]; } } } } int main () { ios; cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; sum += a[i]; cnt += a[i] % 2; } if(sum % 2 == 1) no_answer; if(cnt != 0 && cnt != n) no_answer; precalc(); if(dp[sum / 2] == 0) no_answer; add(); for(int j = a[1] % 2; j <= sum; j += 2){ int cnt = 0; for(int i = 1; i <= n; i++){ int left = (sum - a[i] - j) / 2; if(del[i][left]) cnt++; } if(cnt == n) v.pb(j); } cout << v.size() << nl; for(int i = 0; i < v.size(); i++){ cout << v[i] << ' '; } }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:102:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v.size(); i++){
                    ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...