QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#117503#6397. Master of Both IIIinstallb#RE 47ms11760kbC++14725b2023-07-01 14:36:342023-07-01 14:36:35

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-01 14:36:35]
  • 评测
  • 测评结果:RE
  • 用时:47ms
  • 内存:11760kb
  • [2023-07-01 14:36:34]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);++i)
using namespace std;
typedef long long ll;
const int N=(1<<20)+10,P=998244353;
int n,a[30];
ll f[N],ans;
int move(int s,int i){
    return ((s<<i)&((1<<n)-1))|(s>>n-i);
}
int main(){
    scanf("%d",&n);
    rep(i,0,n-1) scanf("%d",a+i);reverse(a+1,a+n);
    rep(i,2,(1<<n)-1) f[i]=1e18;
    rep(i,1,(1<<n)-1) for(int j=0;j<n;++j){
        int k=i|move(i,j);
        f[k]=min(f[k],f[i]+a[j]);
    }
    rep(i,0,n-1) rep(j,0,(1<<n)-1) 
        if(j&(1<<i)) f[j^(1<<i)]=min(f[j],f[j^(1<<i)]);
    rep(i,0,(1<<n)-1)
        ans=(ans+(f[i]%P)*i)%P;
    printf("%lld\n",ans);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

3
2 1 2

output:

45

result:

ok 1 number(s): "45"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3576kb

input:

4
1919810 999999998 999999997 114114514

output:

152175989

result:

ok 1 number(s): "152175989"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3572kb

input:

3
842160586 705327547 868243944

output:

78597628

result:

ok 1 number(s): "78597628"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3568kb

input:

5
198327434 147392532 760837755 771109105 676721155

output:

751568230

result:

ok 1 number(s): "751568230"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3608kb

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: 3532kb

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: 2ms
memory: 3692kb

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: 0
Accepted
time: 47ms
memory: 11760kb

input:

20
627365465 726842612 947302944 649244156 293375951 318148820 237155023 981487641 688151803 844901013 430309799 733877736 520864483 720366437 28746495 143052089 306590290 18586578 662663479 375430013

output:

179404754

result:

ok 1 number(s): "179404754"

Test #9:

score: -100
Runtime Error

input:

21
805448889 595358753 391340394 525130530 272725205 157594893 261894302 29704333 909085958 127205196 104570238 495437480 458664573 599968678 690908307 220500006 735062204 172834136 241126905 814694254 294923292

output:


result: