QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#177275 | #6194. Knapsack Problem | PhantomThreshold# | WA | 1ms | 3460kb | C++20 | 999b | 2023-09-12 19:39:08 | 2023-09-12 19:39:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll c[100050];
ll a[100050];
ll x[100050];
int main(){
ios_base::sync_with_stdio(false);
int Tcase;
cin >> Tcase;
for (;Tcase--;){
ll K;
cin >> K;
ll N=(1<<K);
for (int i=1;i<N;i++) cin >> c[i];
for (int i=0;i<K;i++) cin >> a[i];
for (int i=1;i<N;i++){
for (int j=1;j<i;j++){
if ((i&j)!=j) continue;
c[i]=max(c[i],c[j]+c[i^j]);
}
}
for (int i=0;i<N;i++) x[i]=0;
x[1]=a[0];
for (int t=1;t<K;t++){
int st=1<<t;
int ed=st*2;
x[st]=a[t];
vector<int> List;
for (int i=st+1;i<ed;i++) List.push_back(i);
sort(
List.begin(),List.end(),
[&](int u,int v){
return (c[u]-c[u-st])>(c[v]-c[v-st]);
}
);
for (auto u:List){
ll mn=min(x[u-st],x[st]);
x[u-st]-=mn;
x[st]-=mn;
x[u]+=mn;
}
}
ll ans=0;
for (int i=1;i<N;i++) ans=ans+x[i]*c[i];
cout << ans << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3460kb
input:
3 2 1 2 4 4 5 3 3226252 19270256 2430652 1187613 12496062 10286165 17494834 24 85 34 4 901133 6693218 13245489 14740234 16186210 11382783 19277321 3855635 16523184 10168517 16195031 971041 10303441 8395899 11618555 529321239 218214127 92942310 207467810
output:
18 1949753378 7832404777567179
result:
ok 3 number(s): "18 1949753378 7832404777567179"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3452kb
input:
100 4 4488409 9842893 14331290 11289097 15777479 21131954 25620334 6146092 10634508 15988956 20477387 17435190 21923584 27278027 31766493 200477197 258791439 590664017 982949628 4 5484152 19851747 25335961 6555937 12039831 26407861 31891996 10897184 16381166 30749333 36233145 17453055 22937114 37304...
output:
16156444119606224 24565535429631234 29418802996321901 30685727712782520 21026118053726857 27272339796311010 28831028447377015 34577176478351368 9058893580144422 21525077460670341 6657186892229297 16750628911275484 11217846865301187 12674710083061158 33873234230125448 3890237279573366 319038755950156...
result:
wrong answer 1st numbers differ - expected: '16156444320083421', found: '16156444119606224'