QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#46991 | #4376. Dragon slayer | AsukaKyle# | AC ✓ | 483ms | 3636kb | C++ | 2.1kb | 2022-09-03 13:28:05 | 2022-09-03 13:28:07 |
Judging History
answer
// Author: HolyK
// Created: Sat Sep 3 13:14:36 2022
#include <bits/stdc++.h>
template <class T, class U>
inline bool smin(T &x, const U &y) {
return y < x ? x = y, 1 : 0;
}
template <class T, class U>
inline bool smax(T &x, const U &y) {
return x < y ? x = y, 1 : 0;
}
using LL = long long;
using PII = std::pair<int, int>;
using namespace std;
const int N = 20;
struct node {
int x1, y1, x2, y2;
} a[N];
bool v1[N][N], v2[N][N];
int fa[N * N];
int findfa(int x) {
if(fa[x] == x) return x;
return fa[x] = findfa(fa[x]);
}
void solve() {
int n, m, K; cin >> n >> m >> K;
int sx, sy, ex, ey;
cin >> sx >> sy >> ex >> ey;
for(int i = 1; i <= K; i++) {
cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
}
int ans = K;
for(int i = 1; i < (1 << K); i++) {
int s = 0;
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) {
v1[i][j] = v2[i][j] = 0;
fa[i * m + j] = i * m + j;
}
for(int j = 1; j <= K; j++) {
if(i >> j - 1 & 1) {
s++;
if(a[j].x1 == a[j].x2) {
if(a[j].x1 == 0) continue;
if(a[j].y1 > a[j].y2) swap(a[j].y1, a[j].y2);
for(int k = a[j].y1; k < a[j].y2; k++) v1[a[j].x1 - 1][k] = 1;
}
else {
if(a[j].y1 == 0) continue;
if(a[j].x1 > a[j].x2) swap(a[j].x1, a[j].x2);
for(int k = a[j].x1; k < a[j].x2; k++) v2[k][a[j].y1 - 1] = 1;
}
}
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(i < n - 1 && !v1[i][j]) {
int fx = findfa(i * m + j), fy = findfa((i + 1) * m + j);
fa[fx] = fy;
}
if(j < m - 1 && !v2[i][j]) {
int fx = findfa(i * m + j), fy = findfa(i * m + j + 1);
fa[fx] = fy;
}
}
}
if(findfa(sx * m + sy) == findfa(ex * m + ey)) ans = min(ans, K - s);
}
cout << ans << '\n';
}
int main() {
// freopen("t.in", "r", stdin);
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 483ms
memory: 3636kb
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