QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#310283#6397. Master of Both IIIPlentyOfPenalty#WA 1ms3672kbC++20716b2024-01-21 10:15:582024-01-21 10:15:59

Judging History

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

  • [2024-01-21 10:15:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3672kb
  • [2024-01-21 10:15:58]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=22,mod=998244353;
const ll INF=1e15;
int n,w[N+10],t,ans;
ll f[(1<<N)+10];
int Lsh(int x,int y){
	return((x<<y)+(x>>(n-y)))&((1<<n)-1);
}
int main(){
	cin.sync_with_stdio(0),cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i)cin>>w[n-i];
	for(int i=2;i<(1<<n);++i)f[i]=INF;
	for(int i=1;i<n;++i){
		for(int j=1;j<(1<<n);++j)t=(j|Lsh(j,i)),f[t]=min(f[t],f[j]+w[i]);
	}
	for(int i=(1<<n)-1;i>0;--i){
		for(int j=0;j<n;++j)if(!(j&(1<<i)))f[i]=min(f[i],f[i|(1<<j)]);
		//cout<<"F "<<i<<"="<<f[i]<<"\n";
		ans=(ans+f[i]%mod*i)%mod;
	}
	cout<<ans;
	return 0;
}
/*
3
2 1 2
*/
/*
4
1919810 999999998 999999997 114114514
*/

详细

Test #1:

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

input:

3
2 1 2

output:

45

result:

ok 1 number(s): "45"

Test #2:

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

input:

4
1919810 999999998 999999997 114114514

output:

152175989

result:

ok 1 number(s): "152175989"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

3
842160586 705327547 868243944

output:

78597628

result:

ok 1 number(s): "78597628"

Test #4:

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

input:

5
198327434 147392532 760837755 771109105 676721155

output:

751568230

result:

ok 1 number(s): "751568230"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3628kb

input:

10
831766351 33417723 223739726 80131988 348810263 415437931 119999060 799356097 512022962 23197703

output:

336774987

result:

wrong answer 1st numbers differ - expected: '308170104', found: '336774987'