QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#780125 | #9802. Light Up the Grid | TosakaUCW | WA | 43ms | 4300kb | C++20 | 2.2kb | 2024-11-25 01:35:28 | 2024-11-29 22:50:59 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
// #define int i64
#define pb push_back
#define ep emplace
#define eb emplace_back
using std::cerr;
using std::max, std::min, std::swap, std::array;
using std::cin, std::cout, std::string, std::vector;
int read(int x = 0, int f = 0, char ch = getchar()) {
while (ch < 48 or 57 < ch) f = ch == 45, ch = getchar();
while(48 <= ch and ch <= 57) x = x * 10 + ch - 48, ch = getchar();
return f ? -x : x;
}
const int inf = 1e9;
using pii = std::pair<int, int>;
#define fi first
#define se second
int a[4];
struct Node {
int dis, sta;
bool friend operator < (Node a, Node b) {
return a.dis > b.dis;
}
};
signed main() {
int T = read();
for (int i = 0; i < 4; i++) a[i] = read();
const int opt[] = {1, 2, 4, 8, 12, 3, 10, 5, 15};
const int val[] = {a[0], a[0], a[0], a[0], a[1], a[1], a[2], a[2], a[3]};
int N = 1 << 16;
vector<int> dis(N, inf);
vector<int> vis(N, 0);
int st = 1 << 15;
std::priority_queue<Node> q;
q.ep(0, st);
while (!q.empty()) {
int u = q.top().sta;
int w = q.top().dis;
q.pop();
// cout << "u : " << u << '\n';
if (vis[u]) continue;
vis[u] = 1;
for (int i = 0; i < 9; i++) {
int v = 0;
for (int j = 0; j < 16; j++) {
if (u >> j & 1) {
v |= (1 << (j ^ opt[i]));
}
}
// cout << "v: " << v << "\n";
if (dis[v] > w + val[i]) {
dis[v] = w + val[i];
q.ep(dis[v], v);
}
v |= (1 << 15);
if (dis[v] > w + val[i]) {
dis[v] = w + val[i];
q.ep(dis[v], v);
}
}
}
while (T--) {
int n = read();
int sta = 0;
for (int i = 0; i < n; i++) {
string s, t;
cin >> s >> t;
int x = (s[0] - '0') * 8 + (s[1] - '0') * 4
+ (t[0] - '0') * 2 + (t[1] - '0');
sta |= (1 << x);
}
// cout << sta << '\n';
cout << dis[sta] << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 21ms
memory: 4300kb
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: 21ms
memory: 3916kb
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: 21ms
memory: 4000kb
input:
1 1000000 1000000 1000000 1000000 1 11 11
output:
2000000
result:
ok 1 number(s): "2000000"
Test #4:
score: -100
Wrong Answer
time: 43ms
memory: 4276kb
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 41 38 40 37 34 42 34 37 37 31 29 35 39 40 38 36 40 34 25 34 34 38 34 31 32 37 34 36 37 40 40 34 37 34 29 35 35 36 42 35 35 34 38 34 37 29 38 38 36 37 43 36 41 30 40 39 33 33 34 36 34 34 42 40 34 32 28 34 32 37 34 39 34 37 32 36 30 30 32 34 38 40 34 36 40 39 34 36 34 25 36 40 36 34 ...
result:
wrong answer 1st numbers differ - expected: '34', found: '32'