QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#782418#9802. Light Up the Gridwallcrack#WA 204ms3796kbC++202.4kb2024-11-25 20:02:132024-11-25 20:02:15

Judging History

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

  • [2024-11-25 20:02:15]
  • 评测
  • 测评结果:WA
  • 用时:204ms
  • 内存:3796kb
  • [2024-11-25 20:02:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int a0,a1,a2,a3;

int f[16][512];
int cst[512];

int dp[(1<<16)+10];



void cal(int &u,int p)
{
	if(p<4)
	{
		int now=(u>>p)&1;
		if(now==0)
		{
			u+=1<<p;
		}
		else {
			u-=1<<p;
		}
	}
	else if(p<6)
	{
		if(p==4)
		{
			cal(u,0);
			cal(u,1);
		}
		else if(p==5)
		{
			cal(u,2);
			cal(u,3);
		}
	}
	else if(p<8)
	{
		if(p==6)
		{
			cal(u,0);
			cal(u,2);
		}
		else {
			cal(u,1);
			cal(u,3);
		}
	}
	else {
		cal(u,0);
		cal(u,2);
		cal(u,1);
		cal(u,3);
	}
	return;
}

void init()
{
	a1=min(a1,2*a0);
	a2=min(a2,2*a0);
	a3=min(a3,4*a0);
	a3=min(a3,a1+a1);
	a3=min(a3,a2+a2);
	for(int i=0;i<15;i++)
	{
		for(int j=0;j<(1<<9);j++)
		{
			int ans=i;
			for(int k=0;k<9;k++)
			{
				if((j>>k)&1)
				{
					cal(ans,k);
				}
			}
			f[i][j]=ans;
		}
	}
	for(int j=0;j<(1<<9);j++)
		{
			int ans=0;
			for(int k=0;k<9;k++)
			{
				if((j>>k)&1)
				{
					if(k<4)
					{
						ans+=a0;
					}
					else if(k<6)
					{
						ans+=a1;
					}
					else if(k<8)
					{
						ans+=a2;
					}
					else ans+=a3;
				}
			
			}
			
			cst[j]=ans;
		}
}

int dfs(int i)
{
	if(dp[i])
	{
		return dp[i];
	}
	vector<int>tep;
	for(int k=0;k<15;k++)
		{
			if((i>>k)&1)
			{
					for(int j=0;j<(1<<9);j++)
					{
						if(f[k][j]==15)
						{
							tep.push_back(j);
						}
					}
			}
		}
	
		for(auto &v:tep)
		{
			int ans=0;
			for(int k=0;k<15;k++)
			{
				if((i>>k)&1)
				{
					if(f[k][v]==15)
					{
						continue;
					}
					else {
						ans+=1<<(f[k][v]);
					}
				}
			}
			
			if(dp[i]==0)
			{
				dp[i]=dfs(ans)+cst[v];
			}
			else {
				dp[i]=min(dp[i],dfs(ans)+cst[v]);
			}
		}
	return dp[i];
}

void solve()
{
	int m;
	cin>>m;
	int res=0;
	int tot=0;
	string a,b;
	for(int i=1;i<=m;i++)
	{
		int u=0;
		cin>>a>>b;
		if(a[0]=='1')
		{
			u+=1<<0;
		}
		if(a[1]=='1')
		{
			u+=1<<1;
		}
		if(b[0]=='1')
		{
			u+=1<<2;
		}
		if(b[1]=='1')
		{
			u+=1<<3;
		}
		if(u==15)
		{
			tot+=min({2*a0,2*a1,2*a2,2*a3});
		}
		else 
		res+=1<<u;
	}
	cout<<dfs(res)+tot<<'\n';
}


signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	cin>>t>>a0>>a1>>a2>>a3;
	init();
	while(t--)
	{
		solve();
	}
	return 0;
}

/*
1 1000 100 10 1
4
10
00
01
00
00
10
00
01
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3660kb

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: 1ms
memory: 3628kb

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: 1ms
memory: 3640kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 204ms
memory: 3796kb

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:

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

result:

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