Submission #566503

#TimeUsernameProblemLanguageResultExecution timeMemory
5665031zaid1Bootfall (IZhO17_bootfall)C++14
13 / 100
1083 ms324 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' typedef long long ll; #define int long long #pragma GCC diagnostic ignored "-Wunused-result" void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(15); if (name.size()) { freopen((name+".in").c_str(), "r", stdin); freopen((name+".out").c_str(), "w", stdout); } } const int M = 5e2+5, MOD = 1e6+7; int sum; bool check(vector<int>& v) { if (sum%2) return 0; vector<bool> can(2*sum+10, 0); can[0] = 1; for (int i = 0; i < v.size(); i++) { for (int k = sum/2; k >= v[i]; k--) { if (can[k-v[i]]) can[k] = 1; } } return can[sum/2]; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); srand(time(0)); // setIO("citystate"); int n; cin >> n; vector<int> v(n); for (int&i:v) cin >> i; for (int i:v) sum += i; if (!check(v)) { cout << 0 << endl; return 0; } vector<int> ans; for (int i = 1; i <= sum; i++) { bool ok = 1; for (int j = 0; j < n; j++) { sum += i-v[j]; swap(v[j], i); ok &= check(v); swap(v[j], i); sum -= i-v[j]; } if (ok) ans.push_back(i); } cout << ans.size() << endl; for (int i:ans) cout << i << ' '; cout << endl; return 0; } /* 4 1 3 1 5 */

Compilation message (stderr)

bootfall.cpp: In function 'bool check(std::vector<long long int>&)':
bootfall.cpp:24:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:63:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   63 |     for (int i:ans) cout << i << ' '; cout << endl;
      |     ^~~
bootfall.cpp:63:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   63 |     for (int i:ans) cout << i << ' '; cout << endl;
      |                                       ^~~~
#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...