QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#379287 | #6397. Master of Both III | 1677118046# | WA | 0ms | 44136kb | C++17 | 1.2kb | 2024-04-06 16:55:58 | 2024-04-06 16:55:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nn=5e6+10;
ll dp[nn];
ll w[30];
ll val[30];
ll AN[nn];
ll val2[30];
const ll mod=998244353;
void solve(){
int n;cin>>n;
for(int i=0;i<n;i++){
cin>>w[i];
}
memset(val,0x3f,sizeof val);
val[0]=0;
for(int k=0;k<=n;k++){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
val[(i+j)%n]=min(val[i]+w[j],val[(i+j)%n]);
}
}
}
for(int i=1;i<=n-1;i++){
val2[n-i]=val[i];
}
for(int i=1;i<=n-1;i++){
val[i]=val2[i];
}
memset(dp,0x3f,sizeof dp);
dp[0]=0;
for(int i=0;i<(1<<n);i++){
for(int j=0;j<n;j++){
if((i>>j)&1){
ll ne=i^(1<<j);
dp[i]=min(dp[i],dp[ne]+val[j]);
for(int k=0;k<n;k++){
if(k==j)continue;
if((i>>k)&1){
dp[i]=min(dp[i],dp[ne]+val[(j-k+n)%n]);
}
}
}
}
}
ll dd=0;
for(int i=1;i<(1<<n);i++){
ll bas=1;
ll an=0;
for(int j=0;j<n;j++){
if((i>>j)&1){
an+=bas;
an%=mod;
}
bas*=2;
bas%=mod;
}
dd+=dp[i]*an;
dd%=mod;
}
cout<<dd%mod<<"\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
solve();
}
/*
1
514 2 10
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 42700kb
input:
3 2 1 2
output:
45
result:
ok 1 number(s): "45"
Test #2:
score: 0
Accepted
time: 0ms
memory: 44052kb
input:
4 1919810 999999998 999999997 114114514
output:
152175989
result:
ok 1 number(s): "152175989"
Test #3:
score: 0
Accepted
time: 0ms
memory: 42928kb
input:
3 842160586 705327547 868243944
output:
78597628
result:
ok 1 number(s): "78597628"
Test #4:
score: 0
Accepted
time: 0ms
memory: 44136kb
input:
5 198327434 147392532 760837755 771109105 676721155
output:
751568230
result:
ok 1 number(s): "751568230"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 42940kb
input:
10 831766351 33417723 223739726 80131988 348810263 415437931 119999060 799356097 512022962 23197703
output:
458771697
result:
wrong answer 1st numbers differ - expected: '308170104', found: '458771697'