QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#210223#4376. Dragon slayerhazeTL 0ms0kbC++202.6kb2023-10-11 09:33:262023-10-11 09:33:26

Judging History

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

  • [2023-10-11 09:33:26]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-10-11 09:33:26]
  • 提交

answer

#include<bits/stdc++.h>
#define irep(i,l,r) for(int i = l; i <= r; ++i)
#define drep(i,r,l) for(int i = r; i >= l; --i)
#define ceil(pp,qq) (((pp)>0)^((qq)>0)?-Abs(pp)/Abs(qq):(pp)%(qq)?(pp)/(qq)+1:(pp)/(qq))
#define floor(pp,qq) (((pp)>0)^((qq)>0)?-ceil(Abs(pp),Abs(qq)):(pp)/(qq))
#define ll long long
#define LL __int128
using namespace std;
ll Abs(ll x){return x > 0 ? x : - x;}
inline ll read(){
	char ch = getchar();
	ll s = 0; bool w = 0;
	while(!isdigit(ch)){if(ch == '-')w = 1;ch = getchar();}
	while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
	return w ? - s : s;
}

const int inf = 1e9;
const ll llinf = 4e18;
const int mod = 1000000007;
const int N = 500009;

inline int mul(int nma, int nmb){
	return ((1ll * nma * nmb % mod) + mod) % mod;
}
int dis[16][16][16][16];
vector<array<int, 4>>arr;

int popcnt(int x){
	return x ? 1 + popcnt(x - (x & -x)) : 0;
}

bool solve(int n, int  m, int K, int x1, int y1, int x2, int y2, int state){
	memset(dis, 0x3f, sizeof(dis));
	
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			dis[i][j][i][j] = 0;
			if(i + 1 < n)dis[i][j][i + 1][j] = dis[i + 1][j][i][j] = 0;
			if(j + 1 < m)dis[i][j][i][j + 1] = dis[i][j + 1][i][j] = 0;
		}
	}
	array<int,2> S, T;
	S = {x1, y1}, T = {x2, y2};
	for(int i = 0; i < K; ++ i){
		if( (state & (1 << i)))continue;
		x1 = arr[i][0], y1 = arr[i][1], x2 = arr[i][2], y2 = arr[i][3];
		if(x1 == x2){
			if(x1 == 0)continue;
			if(y1 > y2)swap(y1, y2);
			while(y1 < y2){
				dis[x1 - 1][y1][x1][y1] = inf;
				dis[x1][y1][x1 - 1][y1] = inf;
				++ y1;
			}
		}
		if(y1 == y2){
			if(y1 == 0)continue;
			if(x1 > x2)swap(x1, x2);
			while(x1 < x2){
				dis[x1][y1 - 1][x1][y1] = inf;
				dis[x1][y1][x1][y1 - 1] = inf;
				++ x1;
			}
		}
	}

	irep(kx,0,n-1){
		irep(ky,0,m-1){
			irep(ix,0,n-1){
				irep(iy,0,m-1){
					irep(jx,0,n-1){
						irep(jy,0,m-1){
							dis[ix][iy][jx][jy] = min(dis[ix][iy][jx][jy],
							dis[ix][iy][kx][ky] + dis[kx][ky][jx][jy]);
							if(dis[S[0]][S[1]][T[0]][T[1]] == 0)return 1;
						}
					}
				}
			}
		}
	}
	return 0;
}

int main(){
	int T = read();
	while(T --){
		int n = read(), m = read(), k = read(), ans = mod;
		int x1 = read(), y1 = read(), x2 = read(), y2 = read();
		arr.clear();
		irep(i,0,k - 1){
			int xa = read(), ya = read() ,xb = read(), yb = read();
			arr.push_back({xa, ya, xb, yb});
		}
		for(int S = 0; S < (1 << k); ++ S){
			if(popcnt(S) >= ans)continue;
			if(solve(n, m, k, x1, y1, x2, y2, S)){
				ans = min(ans, popcnt(S));
			}
		}
			
		printf("%d\n", ans);
	}
	return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

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:


result: