QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142646 | #4414. Divide the Sweets | GeZhiyuan | WA | 5554ms | 244460kb | C++14 | 2.2kb | 2023-08-19 16:14:38 | 2023-08-19 16:14:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 20 + 5, S = (1 << 20) + 5, Inf = 0x3f3f3f3f3f3f3f3f;
class node{
public:
ll x, y;
inline node() {}
inline node(ll x_, ll y_){
x = x_, y = y_;
}
};
inline ll sqr(ll x){
return x * x;
}
ll n = 0, m = 0, A = 0, B = 0, w[N] = {}, sum[S] = {}, dp[N][S] = {};
vector<ll> sub[S] = {};
ll siz = 0, cur = 0;
node convex[S] = {};
inline bool cmp(ll x, ll y){
return sum[x] > sum[y];
}
inline bool check(node a, node b, node c){
return (b.y - a.y) * (c.x - b.x) >= (c.y - b.y) * (b.x - a.x);
}
inline void work(ll x, ll y){
if(siz && x == convex[siz].x){
convex[siz].y = min(convex[siz].y, y);
return;
}
while(siz > 1 && check(convex[siz - 1], convex[siz], node(x, y))) siz --;
convex[++ siz] = node(x, y);
}
inline void init(){
n = m = A = B = 0;
memset(w, 0, sizeof(w)), memset(sum, 0, sizeof(sum));
for(ll x = 0 ; x < S ; x ++) sub[x].clear();
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
}
inline void solve(){
scanf("%lld %lld", &n, &m); A = (1 << (n / 2)) - 1, B = (1 << n) - (1 << (n / 2));
for(ll i = 0 ; i < n ; i ++) scanf("%lld", &w[i]);
for(ll x = 0 ; x < (1 << n) ; x ++) if((x & A) == x || (x & B) == x){
for(ll i = 0 ; i < n ; i ++) if((x >> i) & 1) sum[x] += w[i];
for(ll y = x ; ; y = x & (y - 1)){
sub[x].push_back(y);
if(!y) break;
}
sort(sub[x].begin(), sub[x].end(), cmp);
}
for(ll i = 1 ; i <= m ; i ++) for(ll s : sub[A]) for(ll T : sub[B]){
siz = 0, cur = 1;
for(ll t : sub[T]) if(dp[i - 1][s + t] < Inf) work(sum[T - t], dp[i - 1][s + t] + sqr(sum[T - t]));
if(siz) for(ll x : sub[A - s]){
ll S = s + x;
while(cur < siz && 2 * sum[x] * convex[cur].x + convex[cur].y > 2 * sum[x] * convex[cur + 1].x + convex[cur + 1].y) cur ++;
dp[i][S + T] = min(dp[i][S + T], sqr(sum[x]) + 2 * sum[x] * convex[cur].x + convex[cur].y);
}
}
for(ll i = 1 ; i <= m ; i ++){
ll ans = 0;
for(ll x = 1 ; x < (1 << n) ; x ++) ans += dp[i][x];
printf("%lld\n", ans);
}
}
ll T = 0;
int main(){
scanf("%lld", &T);
for(ll i = 0 ; i < T ; i ++) init(), solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 5554ms
memory: 244460kb
input:
50 1 1 41157 2 2 42567 45459 3 3 18704 43514 6548 4 4 17662 19185 22570 28320 5 5 12535 20205 16505 10400 35580 6 6 35939 41496 10203 32740 30192 13030 7 7 30302 23454 8704 15004 27743 15952 25399 8 8 12327 33605 17303 14647 34972 28109 40172 49588 9 9 32280 30113 13060 40035 2051 45364 40615 40351 ...
output:
1693898649 11627046846 7756940340 14029893744 9389684048 9144736464 38756875752 20816544192 16609193092 15931502152 90237442400 47608100300 37763387500 35650802800 35390074800 512573380960 264020212040 193371094494 172589400072 168933932100 168668041920 797365691840 404346402108 283294514744 2369793...
result:
wrong answer 1st lines differ - expected: '695654296', found: '1693898649'