QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630102#6397. Master of Both IIIMartian148WA 0ms36348kbC++20929b2024-10-11 16:29:582024-10-11 16:30:05

Judging History

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

  • [2024-10-11 16:30:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:36348kb
  • [2024-10-11 16:29:58]
  • 提交

answer

#include <bits/stdc++.h>

using llsi = long long signed int;

int n;

inline llsi shift(llsi s, int y) {
	s |= s << y | s >> (n - y);
	s &= (1 << n) - 1;
	return s;
}

llsi a[22];
llsi dp[1 << 22];

inline void chkmn(llsi &a, const llsi &b) {
	if(b < a) a = b;
}

int main () {
	std::ios::sync_with_stdio(false);
	std::cin >> n;
	for(int i = 0; i < n; ++i) std::cin >> a[i];
	memset(dp, 0x3f, sizeof(dp));
	dp[1] = 0;
	for(int i = 1; i < (1 << n); ++i) {
		llsi sta = i;
		for(int j = 1; j < n; ++j) {
			chkmn(dp[shift(sta, n - j)], dp[sta] + a[j]);
		}
		// std::cout << "dp[" << i << "] = " << dp[i] << char(10);
	}
	
	
	for(int i = 1; i < (1 << n); ++i) {
		// std::cout << "dp[" << i << "] = " << dp[i] << char(10);
	}
	
	llsi ans = 0;
	constexpr llsi mod = 998244353;
	
	for(int i = 1; i < (1 << n); ++i) ans = (ans + dp[i] * i) % mod;
	std::cout << ans << char(10);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 1 2

output:

828691675

result:

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