# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
994047 |
2024-06-07T05:03:29 Z |
vjudge1 |
Kas (COCI17_kas) |
C++17 |
|
1645 ms |
126148 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int S = 1e5 + 10;
int n, a[N];
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];
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());
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 sm : possible){
ite++;
if (sm > X) continue;
if (sm < a[i]) break;
poss[sm] |= poss[sm - a[i]];
}
}
if (poss[X]){
mx = X;
break;
}
for (int sm : possible){
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2908 KB |
Output is correct |
2 |
Correct |
1 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1454 ms |
32204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
24400 KB |
Output is correct |
2 |
Correct |
100 ms |
88268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1645 ms |
126148 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |