Submission #706594

# Submission time Handle Problem Language Result Execution time Memory
706594 2023-03-07T06:24:22 Z YugiHacker Kas (COCI17_kas) C++14
100 / 100
202 ms 98692 KB
#include<bits/stdc++.h>
#define el cout<<"\n"
#define f0(i,n) for(int i=0;i<n;++i)
#define f1(i,n) for(int i=1;i<=n;++i)
#define maxn 100005
using namespace std;
int n, a[maxn], s;
int f[502][maxn/2];
int calc(int pos, int diff)
{
    if (diff > s/2) return -1e9;
    if (pos == n+1)
    {
        if (diff) return -1e9;
        return 0;
    }
    if (f[pos][diff]!=-1) return f[pos][diff];
    return f[pos][diff] = max({calc(pos+1, diff),
                              calc(pos+1, abs(diff-a[pos])) + min(a[pos], diff),
                              calc(pos+1, diff+a[pos])});
}
main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    f1 (i, n) cin >> a[i], s+=a[i];
    memset(f, -1, sizeof f);
    int ans = calc(1, 0);
    ans += s - 2*ans;
    cout << ans;
}

Compilation message

kas.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 98472 KB Output is correct
2 Correct 36 ms 98432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 98452 KB Output is correct
2 Correct 36 ms 98472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 98532 KB Output is correct
2 Correct 36 ms 98440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 98452 KB Output is correct
2 Correct 35 ms 98524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 98528 KB Output is correct
2 Correct 36 ms 98508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 98540 KB Output is correct
2 Correct 39 ms 98592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 98496 KB Output is correct
2 Correct 36 ms 98552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 98560 KB Output is correct
2 Correct 49 ms 98472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 98520 KB Output is correct
2 Correct 116 ms 98692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 98584 KB Output is correct
2 Correct 162 ms 98632 KB Output is correct