QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#782263#9802. Light Up the GridsolunarTL 1ms3700kbC++141.9kb2024-11-25 19:32:372024-11-29 22:53:10

Judging History

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

  • [2024-11-29 22:53:10]
  • 管理员手动重测本题所有提交记录
  • 测评结果:TL
  • 用时:1ms
  • 内存:3700kb
  • [2024-11-25 19:32:57]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3628kb
  • [2024-11-25 19:32:37]
  • 提交

answer

// 2024ICPCShenyangE 
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int m;
int a1, a2, a3, a4;
char ope[9] = {1, 2, 4, 8, 3, 12, 5, 10, 15 };
int a[9];
char b[16];
int x[9];
int cCost, cOK;
int bestCost;

void dfs(int t) {
	if (cOK == (1 << m) - 1) {
		if (cCost < bestCost)
			bestCost = cCost;
		return;
	}
	if (t >= 9)
		return;
	for (int i = t; i < 9; i++) {
		if (cCost >= bestCost)
			continue;
		swap(x[t], x[i]);
		int oldOK = cOK;
		for (int j = 0; j < m; j++) {
			b[j] ^= ope[x[t]];
			if (b[j] == 15)
				cOK |= (1 << j);
		}
		cCost += a[x[t]];
		dfs(t + 1);
		cCost -= a[x[t]];
		cOK = oldOK;
		for (int j = 0; j < m; j++)
			b[j] ^= ope[x[t]];
		swap(x[t], x[i]);
	}
}

int main() {
	int t, init15;
	char ch;
	
	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;
	while (t--) {
		cin >> m;
		init15 = false;
		for (int i = 0; i < m; i++) {
			b[i] = 0;
			for (int j = 0; j < 4; j++) {
				cin >> ch;
				if (ch == '1')
					b[i] |= (1 << j);
			}
			if (b[i] == 15)
				init15 = true;	
		}
		if (init15) {
			int ans = 0x7fffffff;
			for (int j = 0; j < 9; j++) {
				cOK = 0;
				for (int i = 0; i < m; i++) {
					b[i] ^= ope[j];
					if (b[i] == 15)
						cOK |= (1 << i);
				}
				cCost = a[j];
				bestCost = 0x7fffffff;
				for (int i = 0; i < 9; i++)
					x[i] = i;
				dfs(0);
				for (int i = 0; i < m; i++)
					b[i] ^= ope[j];
				if (bestCost < ans)
					ans = bestCost;
			}
			cout << ans << endl;
		} else {
			cOK = 0;
			cCost = 0;
			bestCost = 0x7fffffff;
			for (int i = 0; i < 9; i++)
				x[i] = i;
			dfs(0);
			cout << bestCost << endl;
		}
	}
	return 0;
}
/*
1 1000 100 10 1
1
11
11
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3640kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
2

result:

ok 2 number(s): "1121 2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

2 1 1 1 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

5
2

result:

ok 2 number(s): "5 2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3700kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Time Limit Exceeded

input:

10000 8 2 7 8
8
00
01

00
11

00
10

11
11

10
10

01
10

01
00

10
11
8
11
01

11
00

01
10

11
11

00
01

01
01

01
00

11
10
9
00
00

01
01

10
11

00
01

11
10

11
00

11
11

00
11

01
10
9
11
11

10
00

11
00

11
01

00
10

01
11

00
01

01
01

10
01
11
00
01

01
01

10
10

00
11

11
11

11
10
...

output:

44
45
52
52
2147483647
2147483647
2147483647
2147483647
2147483647
2147483647
52

result: