QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858214#9802. Light Up the GridzzxuuWA 7ms3584kbC++202.3kb2025-01-16 15:02:162025-01-16 15:02:42

Judging History

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

  • [2025-01-16 15:02:42]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3584kb
  • [2025-01-16 15:02:16]
  • 提交

answer

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

ll markk[40], a1, a2, a3, a4, m, ans;
vector <ll> last;
ll arr_dfs[5];
ll does()
{
	ll op = 0;
	if(arr_dfs[1] == 1)
	{
		op += 1;
	}
	if(arr_dfs[2] == 1)
	{
		op += 2;
	}
	if(arr_dfs[3] == 1)
	{
		op += 10;
	}
	if(arr_dfs[4] == 1)
	{
		op += 20;
	}
	return op;
}
bool L_check()
{
	for(auto &x : last)
	{
		if(markk[x] == 0)
		{
			return false;
		}
	}
	return true;
}
void dfs(ll cost)
{
	if(cost > ans)
	{
		return ;
	}
	for(ll i = 1; i <= 9; i ++)
	{
		// cout << i << '\n';
		ll cost1 = cost;
		ll tool[5];
		for(ll l = 1; l <= 4; l ++)
		{
			tool[l] = arr_dfs[l];
		}
		if(i >= 1 && i <= 4)
		{
			arr_dfs[i] = (arr_dfs[i] + 1) % 2;
			cost1 += a1;
		}
		if(i == 5)
		{
			arr_dfs[1] = (arr_dfs[1] + 1) % 2;
			arr_dfs[2] = (arr_dfs[2] + 1) % 2;
			cost1 += a2;
		}
		if(i == 6)
		{
			arr_dfs[3] = (arr_dfs[3] + 1) % 2;
			arr_dfs[4] = (arr_dfs[4] + 1) % 2;
			cost1 += a2;
		}
		if(i == 7)
		{
			arr_dfs[1] = (arr_dfs[1] + 1) % 2;
			arr_dfs[3] = (arr_dfs[3] + 1) % 2;
			cost1 += a3;
		}
		if(i == 8)
		{
			arr_dfs[2] = (arr_dfs[2] + 1) % 2;
			arr_dfs[4] = (arr_dfs[4] + 1) % 2;
			cost1 += a3;
		}
		if(i == 9)
		{
			for(ll l = 1; l <= 4; l ++)
			{
				arr_dfs[l] = (arr_dfs[l] + 1) % 2;
			}
			cost1 += a4;
		}
		ll num = does();
		if(markk[num] == 1)
		{
			for(ll l = 1; l <= 4; l ++)
			{
				arr_dfs[l] = tool[l];
			}
			continue ;
		}
		markk[num] = 1;
		if(L_check())
		{
			ans = min(ans, cost1);
		}
		dfs(cost1);
		markk[num] = 0;
		for(ll l = 1; l <= 4; l ++)
		{
			arr_dfs[l] = tool[l];
		}
	}
}
void solve()
{
	last.clear();
	cin >> m;
	for(ll i = 1; i <= m; i ++)
	{
		char tool[2][2];
		for(auto & l : tool)
		{
			cin >> l;
		}
		ll op = 0;
		if(tool[0][0] == '1')
		{
			op += 1;
		}
		if(tool[0][1] == '1')
		{
			op += 2;
		}
		if(tool[1][0] == '1')
		{
			op += 10;
		}
		if(tool[1][1] == '1')
		{
			op += 20;
		}
		last.push_back(op);
	}
	for(ll i = 1; i <= 4; i ++)
	{
		arr_dfs[i] = 1;
	}
	memset(markk, 0, sizeof(markk));
	dfs(0);
	cout << ans << '\n';
}
int main()
{
	ll t = 1;
	cin >> t;
	cin >> a1 >> a2 >> a3 >> a4;
	while(t --)
	{
		ans = 998244353;
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 3584kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1011
1

result:

wrong answer 1st numbers differ - expected: '1121', found: '1011'