QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#815652 | #9802. Light Up the Grid | ucup-team1769# | TL | 3ms | 4044kb | C++14 | 3.3kb | 2024-12-15 16:10:19 | 2024-12-15 16:10:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// #define int long long
vector<int> c(5);
void solve()
{
int n;
cin >> n;
set<vector<vector<int>>> st;
for (int i = 0; i < n; i++)
{
char ch;
cin >> ch;
vector<vector<int>> tmp(2, vector<int>(2));
tmp[0][0] = ch - '0';
cin >> ch;
tmp[0][1] = ch - '0';
cin >> ch;
tmp[1][0] = ch - '0';
cin >> ch;
tmp[1][1] = ch - '0';
st.insert(tmp);
}
int ans = 0x3f3f3f3f;
priority_queue<pair<int, set<vector<vector<int>>>>> pq;
pq.push({0, st});
set<set<vector<vector<int>>>> vis;
while (!pq.empty())
{
auto [cost, s] = pq.top();
pq.pop();
if (s.size() == 0)
{
ans = min(ans, -cost);
break;
}
// for (auto v : s)
// {
// for (int i = 0; i < 2; i++)
// {
// for (int j = 0; j < 2; j++)
// {
// cout << v[i][j] << ' ';
// }
// cout << '\n';
// }
// cout << '\n';
// }
if (vis.count(s))
continue;
vis.insert(s);
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
set<vector<vector<int>>> tmp;
for (auto v : s)
{
vector<vector<int>> t = v;
t[i][j] ^= 1;
if (t != vector<vector<int>>(2, vector<int>(2, 1)))
tmp.insert(t);
}
pq.push({cost - c[1], tmp});
}
}
for (int i = 0; i < 2; i++)
{
set<vector<vector<int>>> tmp;
for (auto v : s)
{
vector<vector<int>> t = v;
for (int j = 0; j < 2; j++)
t[i][j] ^= 1;
if (t != vector<vector<int>>(2, vector<int>(2, 1)))
tmp.insert(t);
}
pq.push({cost - c[3], tmp});
}
for (int i = 0; i < 2; i++)
{
set<vector<vector<int>>> tmp;
for (auto v : s)
{
vector<vector<int>> t = v;
for (int j = 0; j < 2; j++)
t[j][i] ^= 1;
if (t != vector<vector<int>>(2, vector<int>(2, 1)))
tmp.insert(t);
}
pq.push({cost - c[2], tmp});
}
set<vector<vector<int>>> tmp;
for (auto v : s)
{
vector<vector<int>> t = v;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
t[i][j] ^= 1;
}
}
if (t != vector<vector<int>>(2, vector<int>(2, 1)))
tmp.insert(t);
}
pq.push({cost - c[4], tmp});
}
cout << ans << '\n';
}
signed main()
{
// cin.tie(0)->ios::sync_with_stdio(false);
int t = 1;
cin >> t;
for (int i = 1; i <= 4; i++)
cin >> c[i];
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3796kb
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: 3ms
memory: 4044kb
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: 3668kb
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:
34 32 31 34