QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#787178 | #9802. Light Up the Grid | ucup-team059 | WA | 52ms | 5152kb | C++20 | 2.9kb | 2024-11-27 10:16:23 | 2024-11-27 10:16:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
//#define ll long long
#define int long long
#define PII pair<int, int>
//constexpr ll P = 998244353;
//const int N = 1e5, MOD = 1;
void solve() {
int T;
cin >> T;
vector<int> a(4);
for (int i = 0; i < 4; ++i) cin >> a[i];
vector<PII> op;
//01
//23
op.push_back({1, a[0]});
op.push_back({1 << 1, a[0]});
op.push_back({1 << 2, a[0]});
op.push_back({1 << 3, a[0]});
op.push_back({3, a[1]});
op.push_back({(1 << 3) | (1 << 2), a[1]});
op.push_back({1 | (1 << 2), a[2]});
op.push_back({(1 << 1) | (1 << 3), a[2]});
op.push_back({(1 << 4) - 1, a[3]});
vector<int> to1(1 << 4, INT32_MAX);
vector<int> st(1 << 4);
int N = (1 << 4) - 1;
to1[N] = 0;
priority_queue<PII, vector<PII>, greater<PII> > q;
q.push({to1[N], N});
while (q.size()) {
auto [dis, sta] = q.top();
q.pop();
if (st[sta]) continue;
st[sta] = 1;
for (auto [did, cost]: op) {
int now = sta ^ did;
if (st[now]) continue;
if (to1[now] > dis + cost) {
to1[now] = dis + cost;
q.push({to1[now], now});
}
}
}
int M = (1 << 16) - 1;
vector<int> vis(M + 1), val(M + 1, INT32_MAX);
val[0] = 0;
q.push({val[0], 0});
while (q.size()) {
auto [va, sta] = q.top();
q.pop();
if (vis[sta]) continue;
vis[sta] = 1;
vector<int> is, no;
for (int i = 0; i < 16; ++i) {
if ((sta >> i) & 1) is.push_back(i);
else no.push_back(i);
}
for (auto x: no) {
int p = x ^ N;
int now = 1 << (x ^ p);
for (auto y: is) {
now |= 1 << (y ^ p);
}
if (vis[now]) continue;
if (val[now] > va + to1[x]) {
val[now] = va + to1[x];
q.push({val[now], now});
}
}
}
while (T --) {
int m;
cin >> m;
vector<int> a(m);
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
if (x == 11) x = 3;
if (y == 11) y = 3;
a.push_back((x << 2) | y);
}
int res = INT32_MAX;
for (auto [x, y]: op) {
auto b = a;
for (auto& v: b) {
v ^= x;
}
for (auto v: b) {
int p = v ^ N, sta = 0;
for (auto u: b) {
sta |= (1 << (u ^ p));
}
res = min(res, val[sta] + y + to1[v]);
}
}
cout << res << '\n';
}
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 20ms
memory: 5152kb
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: 14ms
memory: 4580kb
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: 14ms
memory: 4800kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 52ms
memory: 4852kb
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 34 38 40 38 44 39 37 38 32 40 34 36 39 32 36 34 35 42 37 38 40 36 34 34 34 39 25 38 32 36 32 36 36 40 40 30 37 36 30 36 32 38 40 35 36 36 34 34 38 25 38 38 36 34 43 38 39 33 40 34 33 34 34 35 39 29 39 41 38 38 28 32 32 41 35 34 36 36 40 36 27 36 38 32 39 37 29 40 34 40 34 32 39 27 30 39 36 36 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '36'