QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#382788 | #6397. Master of Both III | 1677118046 | WA | 4ms | 42780kb | C++17 | 1.3kb | 2024-04-08 19:07:48 | 2024-04-08 19:07:49 |
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++){
ll ne=i|(1<<j);
dp[ne]=min(dp[ne],dp[i]+val[j]);
for(int k=0;k<n;k++){
if(k==j)continue;
if((i>>k)&1){
dp[ne]=min(dp[i]+val[((j-k+n)%n)],dp[ne]);
}
}
}
}
for(int i=(1<<n)-1;i>=1;i--){
for(int j=0;j<n;j++){
if(i>>j&1){
dp[i^(1<<j)]=min(dp[i],dp[i^(1<<j)]);
}
}
}
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;
}
dp[i]%=mod;
an%=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: 42716kb
input:
3 2 1 2
output:
45
result:
ok 1 number(s): "45"
Test #2:
score: 0
Accepted
time: 4ms
memory: 42716kb
input:
4 1919810 999999998 999999997 114114514
output:
152175989
result:
ok 1 number(s): "152175989"
Test #3:
score: 0
Accepted
time: 3ms
memory: 42780kb
input:
3 842160586 705327547 868243944
output:
78597628
result:
ok 1 number(s): "78597628"
Test #4:
score: 0
Accepted
time: 4ms
memory: 42748kb
input:
5 198327434 147392532 760837755 771109105 676721155
output:
751568230
result:
ok 1 number(s): "751568230"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 42744kb
input:
10 831766351 33417723 223739726 80131988 348810263 415437931 119999060 799356097 512022962 23197703
output:
458771697
result:
wrong answer 1st numbers differ - expected: '308170104', found: '458771697'