Submission #527903

# Submission time Handle Problem Language Result Execution time Memory
527903 2022-02-18T16:45:52 Z aSSSd Kas (COCI17_kas) C++14
0 / 100
216 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 + 10];
int go(int k, int diff)
{
    if(diff >= 100000+5) return  -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));
    ret = max(ret , go(k+1, diff+c[k])+c[k]);
    ret = max(ret , go(k+1, abs(diff-c[k]))+c[k]);
  //      return ret = max({go(k+1, diff), go(k+1, diff+c[k])+c[k], go(k+1, abs(diff-c[k]))+c[k]});
    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:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 196736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 196760 KB Output is correct
2 Incorrect 71 ms 196764 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 196720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 196720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 196752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 196776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 196696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 196804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 133 ms 196804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 216 ms 196820 KB Output isn't correct
2 Halted 0 ms 0 KB -