QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#47439 | #4376. Dragon slayer | Winner | RE | 0ms | 0kb | C++11 | 2.3kb | 2022-09-09 19:37:54 | 2022-09-09 19:37:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 20;
const int mod = 1e9 + 7;
int t, n, m, k;
int xs, ys, xt, yt, cnt[N];
struct node {
int x1, y1, x2, y2;
}a[20];
bool vis[20][20], wa1[20][20], wa2[20][20];
const int dir[][2] = {
-1, 0, 1, 0, 0, -1, 0, 1
};
pair<int,int> q[N];
int hh, tt;
bool inmap (int x, int y) {
return 0 <= x && x < n && 0 <= y && y < m;
}
void show (bool p[][20]) {
for (int i = 0; i <= n; i ++) {
for (int j = 0; j <= m; j ++) {
printf("%d ", p[i][j]);
}
printf("\n");
}
}
bool check (int st) {
for (int i = 0; i <= n; i ++)
for (int j = 0; j <= n; j ++)
wa1[i][j] = wa2[i][j] = vis[i][j] = false;
for (int i = 0; i < k; i ++)
if (st >> i & 1) {
if (a[i].x1 == a[i].x2) {
for (int j = a[i].y1; j <= a[i].y2; j ++)
wa1[a[i].x2][j] = true;
}else {
for (int j = a[i].x1; j <= a[i].x2; j ++)
wa2[j][a[i].y1] = true;
}
}
// printf("%d\n", st);
// show (wa1);
// printf("\n");
// show (wa2);
hh = 1, tt = 0;
q[++ tt] = {xs, ys};
while (hh <= tt) {
pair<int,int> u = q[hh ++];
int x = u.first, y = u.second;
vis[x][y] = true;
// printf("x = %d, y = %d\n", x, y);
if (x == xt && y == yt) return true;
for (int i = 0; i < 4; i ++) {
int dx = x + dir[i][0];
int dy = y + dir[i][1];
if (! inmap (dx, dy)) continue;
if (vis[dx][dy]) continue;
if (i == 0) {
if (wa1[x][y] && wa1[x][y + 1]) continue;
}else if (i == 1) {
if (wa1[x + 1][y] && wa1[x + 1][y + 1]) continue;
}else if (i == 2) {
if (wa2[x][y] && wa2[x + 1][y]) continue;
}else {
if (wa2[x][y + 1] && wa2[x + 1][y + 1]) continue;
}
q[++ tt] = {dx, dy};
}
}
return false;
}
int main(){
scanf("%d", &t);
for (int i = 1; i < (1 << 15); i ++) {
cnt[i] = cnt[i >> 1] + (i & 1);
}
while(t--){
scanf("%d%d%d", &n, &m, &k);
scanf("%d%d%d%d", &xs, &ys, &xt, &yt);
for (int i = 0; i < k; i ++) {
scanf ("%d%d%d%d", &a[i].x1, &a[i].y1, &a[i].x2, &a[i].y2);
if (a[i].x1 > a[i].x2) swap (a[i].x1, a[i].x2);
if (a[i].y1 > a[i].y2) swap (a[i].y1, a[i].y2);
}
int ans = k;
for(int i = 0; i < (1 << k); i ++){
if (check (i)) ans = min (ans, k - cnt[i]);
}
printf("%d\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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...