QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#583910#6397. Master of Both IIIwsxcbWA 3ms36400kbC++17861b2024-09-22 23:54:072024-09-22 23:54:07

Judging History

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

  • [2024-09-22 23:54:07]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:36400kb
  • [2024-09-22 23:54:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first 
#define se second
#define ll long long
const int N=5e5+5,mod=998244353,P=998244353,inf=1e9,M=22;
const ll INF=1e18;
int n;
ll shift(ll x,int y)
{
	x|=(x<<y)|(x>>(n-y));
	x&=(1<<n)-1;
	return x;
}
void chmin(ll &x,ll y)
{
	if(x>y)
	x=y;
}
ll w[25],dp[1<<22];
void solve()
{
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>w[i];
	memset(dp,0x3f,sizeof(dp));
	dp[1]=0;
	for(ll i=1;i<(1<<n);i++)
	{
		for(ll j=1;j<n;j++)
		chmin(dp[shift(i,n-j)],dp[i]+w[j]);
	}
	ll ans=0;
	for(ll i=(1<<n)-1;i;i--)
	{
		for(ll j=0;j<n;j++)
		if(!(i>>j&1))
		chmin(dp[i],dp[(1<<j)|i]);
		dp[i]%=mod;
		ans=(ans+dp[i]*i)%mod;
	}
	cout<<ans<<'\n';
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	solve();
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 36324kb

input:

3
2 1 2

output:

45

result:

ok 1 number(s): "45"

Test #2:

score: 0
Accepted
time: 3ms
memory: 36400kb

input:

4
1919810 999999998 999999997 114114514

output:

152175989

result:

ok 1 number(s): "152175989"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 36340kb

input:

3
842160586 705327547 868243944

output:

154402124

result:

wrong answer 1st numbers differ - expected: '78597628', found: '154402124'