QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#787206 | #9802. Light Up the Grid | ucup-team059 | WA | 47ms | 5224kb | C++20 | 3.0kb | 2024-11-27 10:23:23 | 2024-11-29 22:56:23 |
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) + 5, INT32_MAX);
vector<int> st((1 << 4) + 5);
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 + 5), val(M + 5, 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> aa(m);
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
if (x == 11) x = 3;
else if (x == 10) x = 2;
if (y == 11) y = 3;
else if (y == 10) y = 2;
aa.push_back((x << 2) | y);
}
int res = INT32_MAX;
for (auto [x, y]: op) {
auto b = aa;
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: 19ms
memory: 5224kb
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: 4656kb
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: 13ms
memory: 4616kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 47ms
memory: 4788kb
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:
38 36 36 40 42 40 42 38 40 41 36 44 37 37 37 36 29 39 39 40 38 39 44 41 29 37 41 38 34 34 36 41 36 38 41 43 44 34 37 37 29 40 39 40 44 36 43 41 38 38 41 29 44 41 39 41 43 40 41 38 42 39 37 34 38 38 42 37 42 40 37 40 28 36 32 42 36 39 38 37 36 42 34 38 38 36 42 40 38 42 40 40 37 40 42 29 36 40 36 37 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '38'