QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#379320 | #6397. Master of Both III | innovation | WA | 0ms | 43800kb | C++14 | 1.3kb | 2024-04-06 17:03:57 | 2024-04-06 17:03:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nn=5e6+10;
ll n;
ll dp[nn];
ll w[30];
ll val[30];
ll AN[nn];
ll val2[30];
const ll mod=998244353;
void dfs(ll x, ll cost)
{
if(val[x]<=cost)
{
return ;
}
val[x] = cost;
for(int i=0;i<=n-1;++i)
{
dfs((x+i)%n, (cost+w[i]));
}
}
void solve(){
cin>>n;
for(int i=0;i<=n-1;i++){
cin>>w[i];
}
memset(val,0x3f,sizeof val);
dfs(0, 0);
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];
}
for(int i=0;i<=n;i++)val[i]%=mod;
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%mod;
dd%=mod;
}
cout<<dd<<"\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
solve();
}
/*
1
514 2 10
0 1 2 3 %4
4
1919810 999999998 999999997 114114514
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 43132kb
input:
3 2 1 2
output:
45
result:
ok 1 number(s): "45"
Test #2:
score: 0
Accepted
time: 0ms
memory: 43800kb
input:
4 1919810 999999998 999999997 114114514
output:
152175989
result:
ok 1 number(s): "152175989"
Test #3:
score: 0
Accepted
time: 0ms
memory: 43124kb
input:
3 842160586 705327547 868243944
output:
78597628
result:
ok 1 number(s): "78597628"
Test #4:
score: 0
Accepted
time: 0ms
memory: 43776kb
input:
5 198327434 147392532 760837755 771109105 676721155
output:
751568230
result:
ok 1 number(s): "751568230"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 43384kb
input:
10 831766351 33417723 223739726 80131988 348810263 415437931 119999060 799356097 512022962 23197703
output:
458771697
result:
wrong answer 1st numbers differ - expected: '308170104', found: '458771697'