QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#820766#9802. Light Up the GridXJK404WA 80ms16388kbC++142.2kb2024-12-19 01:04:442024-12-19 01:04:44

Judging History

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

  • [2024-12-19 01:04:44]
  • 评测
  • 测评结果:WA
  • 用时:80ms
  • 内存:16388kb
  • [2024-12-19 01:04:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define itn int
#define tin int
#define nit int
#define longlong long long
typedef long long ll;
typedef unsigned long long ull;
int a1, a2, a3, a4;
int dp[345141][20], n;
void solve() {
	cin >> n;
	int tot = 0;
	for(int i = 1; i <= n; i++) {
		char x1, x2, x3, x4;
		cin >> x1 >> x2 >> x3 >> x4;
		int sum = (x1 - '0') + (x2 - '0') * 2 + (x3 - '0') * 4 + (x4 - '0') * 8;
		tot += (1<<(sum));
	}
	int minx = 1e9; 
	for(int i = 0; i <= 15; i++) {
		minx = min(minx,dp[tot][i]);
	}
	cout << minx << '\n';
}
int cal(int x,int y) {
	if(x != -1) {
		for(int i = 0; i < 4; i++) {
			if(((x & (1<<i)))== 0) {
				if((y & (1<<i)) == 0) {
					y = y + (1<<i);
				}
				else {
					y = y - (1<<i);
				}
			}
		}
	}
		int cnt = 0;
		for(int i = 0;i < 4; i++) {
			if(y & (1<<i))
			cnt++;
		}
		if(cnt == 0) return a4;
		if(cnt == 4) return a4 * 2;
		if(cnt == 1) return min(min(a2, a3) * 2 + a1, a1 + a4);
		if(cnt == 3) return a1;
		if(y == 3 || y == 12) return a2;
		if(y == 5 || y == 10) return a3;
		return min(2 * a1, a2 + a3);
	
	
}
int h[1145141];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T;
	cin >> T >> a1 >> a2 >> a3 >> a4;
	a2 = min(a2, 2 * a1);
	a3 = min(a3, 2 * a1);
	a4 = min(min(a2 * 2, a3 * 2), a4);
	for(int i = 0;i <= (1<<17); i++) {
		for(int j = 0; j <= 15; j++) {
			dp[i][j]=1e9;
		}
	}
	queue<int> q;
	for(int i = 0; i <= 15 ; i++) {
		dp[(1<<i)][i] = cal(-1, i);
		for(int j = 0; j <= 15 ; j++) {
			if(i != j) {
				dp[(1<<i) + (1<<j)][j] = dp[(1<<i)][i] + cal(i, j);
				if(h[(1<<i) + (1<<j)] == 0)
				{
					h[(1<<i) + (1<<j)] = 1;
					q.push(((1<<i) + (1<<j)));	
				}
			}
		}
	}
	while(q.size())
	{
		int r = q.front();
	//	cout<<r<<endl;
		q.pop();
		for(int i = 0; i <= 15; i++) {
			if(r & (1<<i)) {
				continue;
			}
			int e = r + (1<<i);
			if(h[e] == 0) {
				h[e] = 1;
				q.push(e);
			}
			for(int j = 0; j <= 15; j++) {
				if(r & (1<<j))
				{
					dp[e][i] = min(dp[e][i], dp[r][j] + cal(j, i));
				}
			}
		}
	}
/*	cout<<-2<<dp[2][1]<<endl;
	cout<<-1<<dp[6][1]<<' '<<dp[6][2]<<' '<<dp[6][3]<<' '<<dp[6][4]<<' '<<dp[6][5]<<endl;*/
	while(T--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 76ms
memory: 16204kb

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: 78ms
memory: 16084kb

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: 73ms
memory: 16388kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 80ms
memory: 16208kb

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:

34
32
36
36
40
36
42
38
40
41
36
44
34
37
37
32
29
39
39
40
38
39
44
37
29
37
37
38
34
34
32
41
34
36
41
40
44
34
37
34
29
36
39
40
42
35
43
37
38
38
41
29
40
41
36
41
43
40
41
38
42
39
37
33
34
38
41
37
42
40
34
39
28
34
32
38
36
39
38
37
36
38
34
38
34
34
42
40
38
38
40
40
37
40
41
29
36
40
36
34
...

result:

wrong answer 47th numbers differ - expected: '39', found: '43'