QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#185674 | #6397. Master of Both III | UESTC_Guest_WiFi# | WA | 91ms | 12128kb | C++14 | 1.1kb | 2023-09-22 14:50:34 | 2023-09-22 14:50:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=24;
int n,a[N];
#define ll long long
ll f[1<<22];
const ll inf=1e12;
const int mod=998244353;
int main()
{
scanf("%d",&n);
for (int i=0;i<n;++i)
scanf("%d",&a[i]);
for (int i=2;i<(1<<n);++i)
f[i]=inf;
int musk=(1<<n)-1;
for (int i=1;i<(1<<n);++i)
for (int j=1;j<n;++j)
{
int to=(i|(i<<j)|((i<<j)>>n))&musk;
f[to]=min(f[to],f[i]+a[j]);
}
// for (int i=1;i<(1<<n);++i)
// cout<<f[i]<<' ';
// cout<<endl;
for (int i=0;i<n;++i)
for (int j=0;j<(1<<n);j+=(1<<i)<<1)
for (int k=0;k<(1<<i);++k)
{
f[j+k]=min(f[j+k],f[j+k+(1<<i)]);
}
ll ans=0;
for (int i=1;i<(1<<n);++i)
{
ll sum=0;
for (int j=1;j<n;++j)
if (i&(1<<j))
sum+=(1<<(n-j));
if (i%2==1)
++sum;
// cout<<i<<' '<<f[i]<<' '<<sum<<endl;
(ans+=f[i]%mod*sum%mod)%=mod;
}
cout<<ans<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3672kb
input:
3 2 1 2
output:
45
result:
ok 1 number(s): "45"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
4 1919810 999999998 999999997 114114514
output:
152175989
result:
ok 1 number(s): "152175989"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
3 842160586 705327547 868243944
output:
78597628
result:
ok 1 number(s): "78597628"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
5 198327434 147392532 760837755 771109105 676721155
output:
751568230
result:
ok 1 number(s): "751568230"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
10 831766351 33417723 223739726 80131988 348810263 415437931 119999060 799356097 512022962 23197703
output:
308170104
result:
ok 1 number(s): "308170104"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
12 892965903 35291219 261557729 131390943 457251874 944586973 724767219 190756777 658923976 587806068 793999675 378390067
output:
964920873
result:
ok 1 number(s): "964920873"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3948kb
input:
14 249132751 477356204 594343028 32906794 270726189 883801423 329535378 877124753 100792287 152414432 142520554 196476850 924736849 383197276
output:
796031217
result:
ok 1 number(s): "796031217"
Test #8:
score: -100
Wrong Answer
time: 91ms
memory: 12128kb
input:
20 627365465 726842612 947302944 649244156 293375951 318148820 237155023 981487641 688151803 844901013 430309799 733877736 520864483 720366437 28746495 143052089 306590290 18586578 662663479 375430013
output:
358320226
result:
wrong answer 1st numbers differ - expected: '179404754', found: '358320226'