QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#47443#4376. Dragon slayerWinnerWA 398ms7840kbC++112.3kb2022-09-09 19:51:332022-09-09 19:51:34

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-09 19:51:34]
  • 评测
  • 测评结果:WA
  • 用时:398ms
  • 内存:7840kb
  • [2022-09-09 19:51:33]
  • 提交

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 <= m; 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 ++];
		if (hh > n * m) return false;
		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]) continue;
			}else if (i == 1) {
				if (wa1[x + 1][y]) continue;
			}else if (i == 2) {
				if (wa2[x][y]) continue;
			}else {
				if (wa2[x][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
Wrong Answer
time: 398ms
memory: 7840kb

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:

2
2
1
7
3
15
1
4
1
0

result:

wrong answer 1st lines differ - expected: '1', found: '2'