QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#135501#6394. Turn on the LightUrgantTeam#RE 0ms0kbC++231.9kb2023-08-05 16:35:372023-08-05 16:35:40

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 16:35:40]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-08-05 16:35:37]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long double ld;
typedef long long ll;

const int MOD = 998244353;
const ll INF = (ll) 1e18;

int cost[25], subsum[(1 << 22) + 7];
ll dp[(1 << 22) + 7];

int main()
{
 	freopen("input.txt", "r", stdin);
 	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0); cin.tie(0);

	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> cost[i - 1];

	subsum[0] = 1;
	for (int mask = 1; mask < (1 << n); mask++)
	{
		int pos = -1;
		for (int bit = 0; bit < n; bit++)
			if ((mask >> bit) & 1) {pos = bit; break;}

		int mask1 = subsum[mask ^ (1 << pos)];
		int mask2 = 0;

		for (int bit = 0; bit < n; bit++)
		{
		 	if ((mask1 >> bit) & 1)
		 	{
		 	 	int need = (bit + pos) % n;
		 	 	mask2 += (1 << need);
		 	}
		}
		subsum[mask] = (mask1 | mask2);
	}

	for (int mask = 0; mask < (1 << n); mask++) dp[mask] = INF;

	for (int mask = 0; mask < (1 << n); mask++)
	{
	 	ll sum = 0;
	 	for (int bit = 0; bit < n; bit++)
	 		if ((mask >> bit) & 1) sum += cost[bit];
	 	dp[subsum[mask]] = min(dp[subsum[mask]], sum);
	}

	for (int mask = (1 << n) - 1; mask >= 0; mask--)
	{
	 	for (int bit = 0; bit < n; bit++)
	 		if (((mask >> bit) & 1) == 0) dp[mask] = min(dp[mask], dp[mask ^ (1 << bit)]);
	}

	for (int i = 0; i < (1 << n); i++) cout << dp[i] << ' ';
	cout << '\n';

	int ans = 0;
	for (int mask = 1; mask < (1 << n); mask++)
	{
	 	int revmask = 0;
	 	for (int bit = 0; bit < n; bit++)
	 		if (bit == 0) revmask += (mask & 1);
	 		else revmask += (((mask >> bit) & 1) << (n - bit));

	 	cout << mask << ' ' << revmask << '\n';
	 	int s = dp[revmask] % MOD;
	 	int t = 0;
	 	for (int bit = 0; bit < n; bit++)
	 		if ((mask >> bit) & 1) t = (t + (1 << bit)) % MOD;
	 	ans = (ans + (ll) s * t) % MOD;
	}
	cout << ans << '\n';
	return 0;
}

详细

Test #1:

score: 0
Dangerous Syscalls

input:


output:


result: