# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
527902 |
2022-02-18T16:44:46 Z |
aSSSd |
Kas (COCI17_kas) |
C++14 |
|
408 ms |
196888 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);
}
return ret = max({go(k+1, diff), go(k+1, diff+c[k])+c[k], go(k+1, abs(diff-c[k]))+c[k]});
}
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:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
35 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
196776 KB |
Output is correct |
2 |
Correct |
70 ms |
196680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
196736 KB |
Output is correct |
2 |
Correct |
70 ms |
196676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
196712 KB |
Output is correct |
2 |
Correct |
70 ms |
196764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
196888 KB |
Output is correct |
2 |
Correct |
69 ms |
196676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
196888 KB |
Output is correct |
2 |
Correct |
74 ms |
196724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
196740 KB |
Output is correct |
2 |
Correct |
68 ms |
196744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
196676 KB |
Output is correct |
2 |
Correct |
72 ms |
196740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
196740 KB |
Output is correct |
2 |
Correct |
93 ms |
196796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
196804 KB |
Output is correct |
2 |
Correct |
183 ms |
196708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
250 ms |
196820 KB |
Output is correct |
2 |
Correct |
408 ms |
196788 KB |
Output is correct |