Submission #994050

#TimeUsernameProblemLanguageResultExecution timeMemory
994050vjudge1Kas (COCI17_kas)C++17
50 / 100
1455 ms234884 KiB
#include <bits/stdc++.h> using namespace std; const int N = 505; const int S = 1e5 + 10; int n, a[N], ind[S]; vector<int> dp[S], possible; bool mark[S], poss[S]; int main(){ cin >> n; int total = 0; for (int i = 0; i < n; i ++) cin >> a[i], total += a[i]; sort(a, a + n); dp[0] = {-1}; for (int i = 0; i < n; i ++){ for (int sm = total; sm >= a[i]; sm--){ if (dp[sm - a[i]].size() == 0 or dp[sm].size()) continue; dp[sm] = dp[sm - a[i]]; dp[sm].push_back(i); possible.push_back(sm); } } sort(possible.begin(), possible.end()); reverse(possible.begin(), possible.end()); for (int i = 0; i < possible.size(); i ++) ind[possible[i]] = i; int ite = 0; int mx = -1; for (int X : possible){ if (ite >= 2e9) break; if (X > (total / 2) or dp[2 * X].size() == 0) continue; // cout << "Starting to check " << X << endl; for (int i : dp[X]){ // cout << "marking index = " << i << endl; ite++; if (~i) mark[i] = 1; } poss[0] = 1; for (int i = 0; i < n; i ++){ if (mark[i]){ mark[i] = 0; ite++; continue; } for (int j = ind[X]; j < possible.size(); j ++){ int sm = possible[j]; ite++; if (sm < a[i]) break; poss[sm] |= poss[sm - a[i]]; } } if (poss[X]){ mx = X; break; } for (int j = ind[X]; j < possible.size(); j ++){ int sm = possible[j]; ite++; poss[sm] = 0; } } if (~mx){ cout << total - mx << endl; return 0; } for (int x = 0; 2 * x < S; x ++) if (dp[x].size() and dp[2 * x].size()) mx = max(mx, x); cout << mx + (total - 2 * mx) << endl; }

Compilation message (stderr)

kas.cpp: In function 'int main()':
kas.cpp:29:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i = 0; i < possible.size(); i ++)
      |                     ~~^~~~~~~~~~~~~~~~~
kas.cpp:52:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             for (int j = ind[X]; j < possible.size(); j ++){
      |                                  ~~^~~~~~~~~~~~~~~~~
kas.cpp:65:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for (int j = ind[X]; j < possible.size(); j ++){
      |                              ~~^~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...