QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#799838#9802. Light Up the GridyhdddWA 66ms23096kbC++142.3kb2024-12-05 18:41:132024-12-05 18:41:20

Judging History

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

  • [2024-12-05 18:41:20]
  • 评测
  • 测评结果:WA
  • 用时:66ms
  • 内存:23096kb
  • [2024-12-05 18:41:13]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mems(a,x) memset(a,x,sizeof(a))
using namespace std;
const int maxn=200010;
const int inf=1e18;
inline int read(){
	int x=0,fl=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')fl=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-'0');ch=getchar();}
	return x*fl;
}
inline char readc(){
	char ch=getchar();
	while(ch!='0'&&ch!='1')ch=getchar();
	return ch;
}
bool mbe;

int n,qq;
int a,b,c,d;
vector<pii> e[maxn];
int to[16][10];
int id(int i,int j,int p,int q){
	if(i&&j&&p&&q)return -1;
	return i*8+j*4+p*2+q;
}
priority_queue<pii> q;
int dis[1<<16];
bool vis[1<<16];
void work(){
	qq=read();a=read(),b=read(),c=read(),d=read();
	mems(to,-1);
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int p=0;p<2;p++){
				for(int q=0;q<2;q++){
					if(i&&j&&p&&q)continue;
					to[id(i,j,p,q)][0]=id(i^1,j,p,q);
					to[id(i,j,p,q)][1]=id(i,j^1,p,q);
					to[id(i,j,p,q)][2]=id(i,j,p^1,q);
					to[id(i,j,p,q)][3]=id(i,j,p,q^1);
					to[id(i,j,p,q)][4]=id(i^1,j,p^1,q);
					to[id(i,j,p,q)][5]=id(i,j^1,p,q^1);
					to[id(i,j,p,q)][6]=id(i^1,j^1,p,q);
					to[id(i,j,p,q)][7]=id(i,j,p^1,q^1);
					to[id(i,j,p,q)][8]=id(i^1,j^1,p^1,q^1);
				}
			}
		}
	}
	for(int s=0;s<(1<<16);s++){
		for(int i=0;i<=8;i++){
			int t=0;for(int j=0;j<16;j++)if(s&(1<<j)){
				t|=(to[j][i]==-1?0:(1<<to[j][i]));
			}
			// if(!t)cout<<s<<" "<<i<<" "<<t<<"\n";
			if(i<4)e[t].pb({s,a});
			else if(i<6)e[t].pb({s,b});
			else if(i<8)e[t].pb({s,c});
			else e[t].pb({s,d});
		}
	}
	mems(dis,0x3f);dis[0]=0;q.push({0,0});
	while(!q.empty()){
		int u=q.top().se;q.pop();
		if(vis[u])continue;vis[u]=1;
		// cout<<u<<" "<<dis[u]<<"\n";
		for(auto[v,w]:e[u]){
			if(dis[v]>dis[u]+w){
				dis[v]=dis[u]+w;
				q.push({-dis[v],v});
			}
		}
	}
	while(qq--){
		n=read();int s=0;
		while(n--){
			int t=id(readc()-'0',readc()-'0',readc()-'0',readc()-'0');
			s|=(t==-1?0:(1<<t));
		}
		if(!s)printf("%lld\n",2*min({a,b,c,d}));
		else printf("%lld\n",dis[s]);
	}
}

bool med;
int T;
signed main(){
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	
	// cerr<<(&mbe-&med)/1024.0/1024.0<<"\n";
	
	T=1;
	while(T--)work();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 62ms
memory: 23060kb

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: 57ms
memory: 22804kb

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: 60ms
memory: 22876kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 66ms
memory: 23096kb

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:

32
30
27
32
40
38
41
37
40
37
27
42
34
38
38
31
38
34
38
40
36
38
40
34
30
36
32
40
34
40
36
37
33
35
37
29
40
27
38
34
34
36
35
35
42
35
35
34
36
33
36
36
36
38
34
37
43
27
41
30
40
37
33
33
29
36
34
36
42
38
32
27
33
34
32
36
34
39
34
39
31
36
39
30
34
32
38
40
25
40
38
41
34
37
34
32
35
38
34
36
...

result:

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