QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858428#9802. Light Up the GridNana7#WA 89ms13828kbC++141.8kb2025-01-16 17:14:112025-01-16 17:14:12

Judging History

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

  • [2025-01-16 17:14:12]
  • 评测
  • 测评结果:WA
  • 用时:89ms
  • 内存:13828kb
  • [2025-01-16 17:14:11]
  • 提交

answer

#include<bits/stdc++.h>
#define I inline
#define int long long
using namespace std;

int f[22][65540];
int d[22][22];
int pw[22];
int n,a[22];
char s[3][3];
int a0,a1,a2,a3;

I void init() {
	for(int i=0;i<16;++i) {
		for(int j=0;j<16;++j) {
			d[i][j]=1e9;
		}
	}
	for(int i=0;i<16;++i) d[i][i]=0;
	for(int i=0;i<16;++i) {
		for(int j=0;j<4;++j) {
			d[i][i^pw[j]]=min(d[i][i^pw[j]],a0);	
		}
	}
	for(int i=0;i<16;++i) {
		d[i][i^(1+2)]=min(d[i][i^(1+2)],a1);
		d[i][i^(4+8)]=min(d[i][i^(4+8)],a1);
	}
	for(int i=0;i<16;++i) {
		d[i][i^(1+4)]=min(d[i][i^(1+4)],a2);
		d[i][i^(2+8)]=min(d[i][i^(2+8)],a2);
	}
	for(int i=0;i<16;++i) d[i][i^15]=min(d[i][i^15],a3);
	for(int i=0;i<16;++i) {
		for(int j=0;j<16;++j) {
			for(int p=0;p<16;++p) {
				d[j][p]=min(d[j][p],d[j][i]+d[i][p]);
			}
		}
	}
	d[15][15]=min(2*a0,2*a1);
	d[15][15]=min(d[15][15],min(2*a2,2*a3));
	for(int i=0;i<16;++i) {
		for(int j=0;j<65536;++j) {
			f[i][j]=1e9;
		}
	}

	for(int i=0;i<16;++i) f[i][pw[i]]=d[i][15];
	
	for(int i=0;i<16;++i) {
		for(int j=0;j<pw[16];++j) {
			for(int p=0;p<16;++p) {
				if(j&pw[p]) continue;
				if(!(pw[i]&j)) continue;
				f[p][j|pw[p]]=min(f[p][j|pw[p]],f[i][j]+d[i^p^15][15]);
			}
		}
	}

}
I void solve() {
	
	cin>>n;
	for(int i=1;i<=n;++i) {
		a[i]=0;
		cin>>s[1];
		cin>>s[2];
		if(s[1][0]=='1') a[i]+=pw[0];
		if(s[1][1]=='1') a[i]+=pw[1];
		if(s[2][0]=='1') a[i]+=pw[2];
		if(s[2][1]=='1') a[i]+=pw[3];
	}		
	int ans=1e9,msk=0;
	for(int i=1;i<=n;++i) msk|=pw[a[i]];
	for(int j=0;j<16;++j) ans=min(ans,f[j][msk]);
	cout<<ans<<endl;
	
}
/*
 1 1000 100 10 1
 
 
 1
 11
 11

*/
 main()
{
	{
		pw[0]=1;
		for(int i=1;i<=16;++i) pw[i]=pw[i-1]<<1;
	}
	//cout<<pw[16]<<endl;
	int T; cin>>T>>a0>>a1>>a2>>a3;  init();
	while(T--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 64ms
memory: 12288kb

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: 63ms
memory: 13828kb

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: 64ms
memory: 13164kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 89ms
memory: 11884kb

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:

56
54
52
54
62
57
80
62
63
69
53
77
51
40
62
54
45
58
50
63
62
60
64
59
44
55
50
49
50
57
50
68
63
70
66
67
69
47
62
51
49
61
54
60
81
57
65
67
59
56
58
44
66
76
65
74
71
54
72
55
64
56
49
54
55
69
55
56
62
68
53
49
46
56
49
70
56
65
54
54
56
72
57
54
53
55
60
61
46
59
59
70
61
67
56
46
45
61
52
52
...

result:

wrong answer 1st numbers differ - expected: '34', found: '56'