QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858341#9802. Light Up the GridNana7#WA 45ms8936kbC++141.7kb2025-01-16 16:26:462025-01-16 16:27:12

Judging History

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

  • [2025-01-16 16:27:12]
  • 评测
  • 测评结果:WA
  • 用时:45ms
  • 内存:8936kb
  • [2025-01-16 16:26:46]
  • 提交

answer

#include<bits/stdc++.h>
#define I inline
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]);
			}
		}
	}
	//memset(f,0x1f,sizeof(f));
	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) {
				f[p][j|pw[p]]=min(f[p][j|pw[p]],f[i][j]-d[i][15]+d[i][p]+d[p][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;
	
}
/*
 2 1000 100 10 1
 4
 10
 00
 01
 00
 00
 10
 00
 01
 1
 11
 11

*/
int 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: 25ms
memory: 8588kb

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: 24ms
memory: 8936kb

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: 26ms
memory: 8360kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 45ms
memory: 8688kb

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:

48
48
51
46
61
54
78
54
66
67
51
75
43
46
62
48
46
56
51
66
59
58
62
54
42
53
43
55
49
55
48
65
55
64
67
59
72
45
60
48
53
59
56
56
75
50
64
61
65
59
54
49
61
74
60
72
71
57
78
50
62
61
47
46
53
67
50
54
68
71
45
46
49
48
51
62
54
71
53
53
59
66
58
51
45
50
58
65
43
51
63
71
62
65
53
44
52
62
58
47
...

result:

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