QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#177887 | #4376. Dragon slayer | jrjyy# | AC ✓ | 279ms | 3592kb | C++20 | 2.0kb | 2023-09-13 15:13:55 | 2023-09-13 15:13:57 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr int P = 1e9 + 7;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
void solve() {
int n, m, k;
std::cin >> n >> m >> k;
int xs, ys, xt, yt;
std::cin >> xs >> ys >> xt >> yt;
std::vector f(n, std::vector<std::array<int, 4>>(m));
for (int i = 0; i < k; ++i) {
int c1, r1, c2, r2;
std::cin >> c1 >> r1 >> c2 >> r2;
if (c1 > c2) {
std::swap(c1, c2);
}
if (r1 > r2) {
std::swap(r1, r2);
}
if (c1 == c2) {
if (0 < c1 && c1 < n) {
for (int j = r1; j < r2; ++j) {
f[c1 - 1][j][0] |= 1 << i;
f[c1][j][1] |= 1 << i;
}
}
} else {
if (0 < r1 && r1 < m) {
for (int j = c1; j < c2; ++j) {
f[j][r1 - 1][2] |= 1 << i;
f[j][r1][3] |= 1 << i;
}
}
}
}
int ans = 0;
for (int s = 1; s < 1 << k; ++s) {
std::vector vis(n, std::vector<bool>(m));
std::vector<std::pair<int, int>> q;
vis[xs][ys] = true;
q.emplace_back(xs, ys);
for (int i = 0; i < int(q.size()); ++i) {
auto [x, y] = q[i];
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i], ny = y + dy[i];
if (0 <= nx && nx < n && 0 <= ny && ny < m && !vis[nx][ny]) {
if ((f[x][y][i] & s) == 0) {
vis[nx][ny] = true;
q.emplace_back(nx, ny);
}
}
}
}
if (vis[xt][yt]) {
ans = std::max(ans, __builtin_popcount(s));
}
}
std::cout << k - ans << "\n";
}
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 279ms
memory: 3592kb
input:
10 4 4 4 0 2 3 3 0 2 4 2 1 3 1 0 2 4 2 1 3 1 3 4 3 2 2 0 0 2 1 0 1 3 1 1 0 1 2 3 2 2 0 0 2 1 2 1 2 2 1 0 1 1 15 15 15 3 12 4 1 8 0 8 15 1 11 15 11 1 1 1 15 3 1 3 15 0 10 14 10 14 1 14 14 8 1 8 15 1 5 14 5 0 15 14 15 0 4 14 4 0 2 15 2 11 0 11 15 4 1 4 15 1 11 15 11 1 12 14 12 15 15 15 8 5 14 0 0 12 1...
output:
1 2 0 5 3 5 1 4 1 0
result:
ok 10 lines