QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#821209 | #9802. Light Up the Grid | ucup-team3548# | WA | 20ms | 11756kb | C++20 | 3.3kb | 2024-12-19 14:21:41 | 2024-12-19 14:21:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e16;
vector<ll> ans;
void init() {
vector<ll> a(4);
for (int i = 0; i < 4; ++i) {
cin >> a[i];
}
int m = 16;
auto trans = [&](array<array<int, 2>, 2> &s) {
int res = 0;
res += s[0][0] + (s[0][1]) * 2 + (s[1][0]) * 4 + (s[1][1]) * 8;
return res;
};
vector<ll> dis(m, inf);
array<array<int, 2>, 2> ar;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
ar[i][j] = 1;
}
}
priority_queue<pair<ll, array<array<int, 2>, 2> > > heap;
heap.push({0, ar});
while (heap.size()) {
auto [d, u] = heap.top();
heap.pop();
d = -d;
if (d > dis[trans(u)]) continue;
auto v = u;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
v[i][j] ^= 1;
int iv = trans(v);
if (dis[iv] > d + a[0]) {
dis[iv] = d + a[0];
heap.push({-dis[iv], v});
}
v[i][j] ^= 1;
}
v[i][0] ^= 1, v[i][1] ^= 1;
int iv = trans(v);
if (dis[iv] > d + a[1]) {
dis[iv] = d + a[1];
heap.push({-dis[iv], v});
}
v[i][0] ^= 1, v[i][1] ^= 1;
v[0][i] ^= 1, v[1][i] ^= 1;
iv = trans(v);
if (dis[iv] > d + a[2]) {
dis[iv] = d + a[2];
heap.push({-dis[iv], v});
}
v[0][i] ^= 1, v[1][i] ^= 1;
}
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
v[i][j] ^= 1;
}
}
int iv = trans(v);
if (dis[iv] > d + a[3]) {
dis[iv] = d + a[3];
heap.push({-dis[iv], v});
}
}
vector<vector<ll> > f(m, vector<ll> (1 << m, inf));
for (int i = 0; i < m; ++i) {
f[i][1 << i] = dis[i];
}
for (int i = 1; i < (1 << m); ++i) {
for (int j = 0; j < m; ++j) {
if (!(i >> j & 1)) continue;
int k = i ^ (1 << j);
for (int l = 0; l < m; ++l) {
f[j][i] = min(f[j][i], f[l][k] + dis[j ^ l]);
}
}
}
ans.resize(1 << m, inf);
for (int i = 0; i < (1 << m); ++i) {
for (int j = 0; j < m; ++j) {
ans[i] = min(ans[i], f[j][i]);
}
}
}
void Solve()
{
int m;
cin >> m;
auto trans = [&](array<array<int, 2>, 2> &s) {
int res = 0;
res += s[0][0] + (s[0][1]) * 2 + (s[1][0]) * 4 + (s[1][1]) * 8;
return res;
};
array<string, 2> s;
int id = 0;
for (int i = 0; i < m; ++i) {
cin >> s[0] >> s[1];
array<array<int, 2>, 2> ar;
for (int j = 0; j < 2; ++j) {
for (int k = 0; k < 2; ++k) {
ar[j][k] = s[j][k] - '0';
}
}
id |= 1 << trans(ar);
}
cout << ans[id] << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
init();
while(t--)
{
Solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 14ms
memory: 11724kb
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: 13ms
memory: 11756kb
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: 10ms
memory: 11728kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 20ms
memory: 11756kb
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 36 36 40 36 42 38 40 41 36 44 34 37 37 32 29 39 39 40 38 39 44 37 29 36 37 38 34 34 32 41 35 36 41 40 44 34 37 34 29 36 39 40 42 35 39 37 38 38 41 29 40 41 36 41 43 40 41 34 42 39 37 33 34 38 38 37 42 40 34 36 28 34 32 38 36 39 38 37 36 38 34 34 34 34 42 40 38 38 40 40 37 40 38 29 36 40 36 34 ...
result:
wrong answer 26th numbers differ - expected: '37', found: '36'