QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#429989 | #7793. 雷同 | kkkgjyismine4 | 5 | 2ms | 9940kb | C++14 | 996b | 2024-06-03 09:30:43 | 2024-06-03 09:30:43 |
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll inf=1e18;
int n;ll w[500050];
int g[500050];
ll f[103][103][103],sum[103];
void cmin(ll &x,const ll y){x=min(x,y);}
void solve(){
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%lld",&w[i]);
sort(w+1,w+n+1);
for(int i=1;i<=n;++i)
for(int j=i;j<=n;++j)
for(int k=0;k<=n;++k)f[i][j][k]=inf;
for(int i=1;i<=n;++i)f[i][i][0]=0,sum[i]=sum[i-1]+w[i];
for(int i=n-1;i>=1;--i)
for(int j=i+1;j<=n;++j)
for(int k=i;k<j;++k)
for(int lef=g[k-i+1];lef<=g[k-i+1]+1&&lef<=k-i+1;++lef)
for(int rig=g[j-k];rig<=g[j-k]+1&&rig<=j-k;++rig)
cmin(f[i][j][max(lef,rig)+1],f[i][k][lef]+f[k+1][j][rig]+sum[j]-sum[i-1]+(1ll<<min(lef,rig))-1ll);
ll ans=inf;
for(int i=0;i<=n;++i)cmin(ans,f[1][n][i]);
printf("%lld\n",ans);
}
int main(){
g[1]=0;
for(int i=2;i<=500000;++i)g[i]=max(g[i/2],g[i-i/2])+1;
int t;cin>>t;
while(t--)solve();
return 0;
}
詳細信息
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 2ms
memory: 8040kb
input:
4 6 1 3 5 7 9 11 6 2 4 6 8 10 12 6 100 1000 100 10 100 10 2 114514 1919810
output:
86 103 1981 2034324
result:
ok 4 tokens
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #2:
score: 0
Wrong Answer
time: 2ms
memory: 9940kb
input:
5 12 2 4 3 2 2 3 4 2 3 2 2 1 12 3 3 3 2 3 2 3 2 1 1 2 4 12 6 2 2 2 5 4 6 1 2 8 8 6 12 1 4 2 2 1 6 7 2 4 1 7 5 12 11 1 2 6 16 16 15 8 8 16 6 12
output:
114 110 183 147 404
result:
wrong answer 2nd words differ - expected: '109', found: '110'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Runtime Error
Test #39:
score: 0
Runtime Error
input:
2 2500 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #5:
0%