QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#815506 | #9802. Light Up the Grid | ucup-team1769# | TL | 1ms | 3764kb | C++14 | 2.4kb | 2024-12-15 15:05:55 | 2024-12-15 15:05:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define max_len ((1 << (4)) + 10)
#define status_map(i1, i2, i3, i4) (((i1) * 0x1) | ((i2) * 0x2) | ((i3) * 0x4) | ((i4) * 0x8))
int min_cost[max_len];
int a1, a2, a3, a4;
void init_cost()
{
memset(min_cost, 0x3f, sizeof(min_cost));
}
void bfs()
{
// cost, status
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
que.push({0, status_map(1, 1, 1, 1)});
while (que.size() != 0)
{
auto [co, st] = que.top();
que.pop();
if(min_cost[st] != 0x3f3f3f3f)
{
continue;
}
min_cost[st] = co;
auto mask_status = [&] (int mask_s, int cost_use){
int new_st = st ^ mask_s;
que.push({co + cost_use, new_st});
};
mask_status(status_map(1, 1, 1, 1), a4);
mask_status(status_map(1, 0, 1, 0), a3);
mask_status(status_map(0, 1, 0, 1), a3);
mask_status(status_map(1, 1, 0, 0), a2);
mask_status(status_map(0, 0, 1, 1), a2);
mask_status(status_map(1, 0, 0, 0), a1);
mask_status(status_map(0, 1, 0, 0), a1);
mask_status(status_map(0, 0, 1, 0), a1);
mask_status(status_map(0, 0, 0, 1), a1);
}
}
int can_stauts[max_len];
int N;
int get_ans()
{
sort(can_stauts, can_stauts + N);
int ans = 0x3f3f3f3f;
do
{
int tans = 0;
int all_mask = 0;
for (int i = 0; i < N; i++)
{
tans += min_cost[all_mask ^ can_stauts[i]];
all_mask ^= ((all_mask ^ can_stauts[i]) ^ status_map(1, 1, 1, 1));
}
ans = min(ans, tans);
} while (next_permutation(can_stauts, can_stauts + N));
return ans;
}
#define ch2int(ch) ((ch) - '0')
void sol()
{
cin >> N;
for (int i = 0; i < N; i++)
{
string s1, s2;
cin >> s1 >> s2;
can_stauts[i] = status_map(ch2int(s1[0]), ch2int(s1[1]), ch2int(s2[0]), ch2int(s2[1]));
}
if(N == 1 && can_stauts[0] == 0x0f)
{
cout << min(2 * a4, min(2 * a3, min(2 * a2, 2 * a1))) << "\n";
return;
}
init_cost();
bfs();
int ans = get_ans();
cout << ans << "\n";
}
int main()
{
// cout << status_map(1, 1, 1, 1) << endl;
int T;
cin >> T >> a1 >> a2 >> a3 >> a4;
while (T--)
{
sol();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3600kb
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: 0ms
memory: 3536kb
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: 0ms
memory: 3764kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Time Limit Exceeded
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 34 34 40 36