QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#784604#9802. Light Up the GridsolunarWA 0ms4060kbC++141.4kb2024-11-26 15:29:042024-11-29 22:55:05

Judging History

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

  • [2024-11-29 22:55:05]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:0ms
  • 内存:4060kb
  • [2024-11-26 15:29:05]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:4116kb
  • [2024-11-26 15:29:04]
  • 提交

answer

// 2024ICPCShenyangE 
#include <iostream>
#include <algorithm>
using namespace std;
#include <math.h>
#include <memory.h>

int m;
int a1, a2, a3, a4;
char ope[9] = {1, 2, 4, 8, 3, 12, 5, 10, 15 };
long long a[9];
int grid;
long long dp[1<<16];

long long memoir(int s) {
	if (dp[s] >= 0)
		return dp[s];
	dp[s] = 2e9;
	for (int i = 0; i < 9; i++) {
		int newset = 0;
		for (int j = 0; j < 16; j++)
			if ((s & (1 << j)) && ((j ^ ope[i]) != 15))
				newset |= (1 << (j ^ ope[i]));
		long long suba = (dp[newset] >= 0) ? dp[newset] : memoir(newset);
		dp[s] = min(dp[s], a[i] + suba);
	}
	return dp[s];
}

int main() {
	int t;
	char ch;
	
	ios::sync_with_stdio(false);
	cin >> t >> a1 >> a2 >> a3 >> a4;
	a[0] = a[1] = a[2] = a[3] =  a1;
	a[4] = a[5] = a2;
	a[6] = a[7] = a3;
	a[8] = a4;
	for (int i = 0; i < (1 << 16); i++)
		dp[i] = -1;
	dp[0] = 0;
	while (t--) {
		cin >> m;
		int status = 0;
		for (int i = 0; i < m; i++) {
			grid = 0;
			for (int j = 0; j < 4; j++) {
				cin >> ch;
				if (ch == '1')
					grid |= (1 << j);
			}
			status |= (1 << grid);
		}
		long long ans = 2e9;
		for (int i = 0; i < 9; i++) {
			int newset = 0;
			for (int j = 0; j < 16; j++)
				if ((status & (1 << j)) && ((j ^ ope[i]) != 15))
					newset |= (1 << (j ^ ope[i]));
			ans = min(ans, a[i] + dp[newset]);
		}
		cout << ans << endl;
	}
	return 0;
}

详细

Test #1:

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

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

0
0

result:

wrong answer 1st numbers differ - expected: '1121', found: '0'