Submission #527899

# Submission time Handle Problem Language Result Execution time Memory
527899 2022-02-18T16:43:01 Z aSSSd Kas (COCI17_kas) C++14
0 / 100
199 ms 196820 KB
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define fasty ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define forinc(x,a,b) for (int x=a;x<=b;x++)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f, x, sizeof(f))
#define getbit(x,i) ((x>>i)&1)
#define batbit(x,i) (x|(1ll<<i))
#define tatbit(x,i) (x&~(1<<i))
#define gg exit(0);

int n;
int c[502];

int g[502][100000 + 2];
int go(int k, int diff)
{
    if(diff > 100000) return g[k][diff] = -1e9;

    if(g[k][diff] != - 1) return g[k][diff];

    int &ret = g[k][diff];
    if(k == n+1)
    {
        return ret = (diff == 0 ? 0 : -1e9);
    }
    ret = max(ret  , go(k+1 , diff + c[k]) + c[k]);
    ret = max(ret , go(k+1 , abs(diff - c[k]) ) + c[k]);
    ret = max(ret , go(k+1 , diff));
    return ret;
}
main()
{
    fasty;
    cin >> n;
    int sum=0;
    forinc(i,1,n)
    {
        cin >> c[i];
        sum+=c[i];
    }

    memset(g , -1 , sizeof g);
    int split = go(1,0);
    cout << (sum - split) + split/2;
}

Compilation message

kas.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   37 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 70 ms 196676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 196724 KB Output is correct
2 Incorrect 70 ms 196684 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 70 ms 196684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 196696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 196748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 196820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 196660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 122 ms 196780 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 196792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 199 ms 196800 KB Output isn't correct
2 Halted 0 ms 0 KB -