QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#177038#6397. Master of Both IIImendicillin2#WA 0ms3676kbC++171.4kb2023-09-12 14:38:462023-09-12 14:38:46

Judging History

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

  • [2023-09-12 14:38:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3676kb
  • [2023-09-12 14:38:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

template <class T> int sz(T&& a) { return int(size(forward<T>(a))); }

template <class T> using vc = vector<T>;
template <class T> using vvc = vc<vc<T>>;

using ll = int64_t;
using vi = vc<int>;

template <class F>
struct ycr {
	F f;
	
	template <class T>
	explicit ycr(T&& f_) : f(forward<T>(f_)) {}

	template <class... Args>
	decltype(auto) operator()(Args&&... args) {
		return f(ref(*this), forward<Args>(args)...);
	}
};
template <class F>
decltype(auto) yc(F&& f) {
	return ycr<decay_t<F>>(forward<F>(f));
}

int n,w[25];
long long f[(1<<22)+5];
inline int ask(int s,int k)
{
	int w1=s/(1<<(n-k)), w2=s%(1<<(n-k));
	return (w1+(w2<<k))|s;
}

const int mod=998244353;
int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	cout << fixed << setprecision(20);
	cin>>n;
	cout<<ask(3,2)<<endl;
	//cout<<ask(5,1)<<" "<<"yes"<<endl;
	for(int i=0;i<n;i++) cin>>w[i];
	for(int s=0;s<(1<<n);s++) f[s]=1e18;
	f[1]=0;
	for(int s=1;s<(1<<n);s++)
		for(int i=0;i<n;i++)
		{
			int nex=ask(s,i);
			f[nex]=min(f[nex],f[s]+w[i]);
		}
	int ans=0;
	for(int s=(1<<n)-1;s>=1;s--) 
		for(int i=0;i<n;i++)
			if(!((s>>i)&1))
				f[s]=min(f[s],f[s|(1<<i)]);
	for(int s=1;s<(1<<n);s++) f[s]%=mod;
	for(int s=1;s<(1<<n);s++)
	{
		int now=0;
		for(int i=1;i<n;i++)
			if((s>>i)&1)
				now+=(1<<(n-i));
		now|=1;
		ans=(ans+1LL*f[now]*s%mod)%mod;
	}
	cout<<ans<<endl;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3676kb

input:

3
2 1 2

output:

7
45

result:

wrong answer 1st numbers differ - expected: '45', found: '7'