QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#828801#9802. Light Up the GridXJK404WA 807ms4380kbC++142.2kb2024-12-23 20:47:432024-12-23 20:47:44

Judging History

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

  • [2024-12-23 20:47:44]
  • 评测
  • 测评结果:WA
  • 用时:807ms
  • 内存:4380kb
  • [2024-12-23 20:47:43]
  • 提交

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], n, a[17];
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));
	}
	cout << dp[tot] << '\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 min(a1,min(a2,min(a3,a4))) * 2;
		if(cnt == 1) return min(min(a2, a3) + 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);
}
ll deal()
{
	ll u = 0, v = 0;
	for(int i=1;i<=16;i++)
	{
		v = u + (1<<a[i]);
		int q = cal(a[i - 1], a[i]);
		if(i == 1) 
		q = cal(-1, a[1]);
		dp[v] = min(dp[v],dp[u] + q);
		u = v;
	}
	return dp[v];
}
void sa(double T)
{
	ll now = 1e9;
	while(T>1e-3)
	{
		int x=rand()%16+1,y=rand()%16+1;
		if(x==y)continue;
		swap(a[x],a[y]);
		ll nw=deal();
		if(nw<now||exp((now-nw) * 1.0 / now)/T>double(rand())/RAND_MAX) now = nw;
		else 
		swap(a[x],a[y]);
		T=T*0.99;
	}
	for(int i=1;i<=16;i++)
	{
		for(int j=1;j<i;j++)
		{
			swap(a[i],a[j]);
			deal();
			swap(a[i],a[j]);
		}
	}
}
double Time(){return (double)clock()/CLOCKS_PER_SEC;}
int main() {
//	freopen("a.in","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	srand(time(0));
	int T;
	for(int i = 1; i <= 16; i++) {
		a[i] = i - 1;
	}
	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++) {
			dp[i] = 1e9;
	}
	dp[0] = 0;
	while(Time()<0.8)sa(114514);
	while(T--) {
		solve();
	}
//	cout << cal(0,1);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 803ms
memory: 4284kb

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: 800ms
memory: 4276kb

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: 799ms
memory: 4320kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 807ms
memory: 4380kb

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
38
36
42
38
40
38
36
44
34
34
36
32
29
36
38
40
36
38
42
36
27
34
36
36
32
33
32
40
34
36
38
40
42
34
36
32
29
36
38
40
40
35
39
36
38
36
40
29
38
40
36
38
42
40
40
34
41
38
34
32
34
38
36
36
40
38
34
34
27
34
32
38
36
38
36
36
36
36
31
34
34
34
38
38
38
38
40
40
36
36
36
27
34
38
36
34
...

result:

wrong answer 5th numbers differ - expected: '40', found: '38'