TLE 求调
查看原帖
TLE 求调
799877
AK_heaven楼主2024/4/20 10:30
#include <bits/stdc++.h>

using namespace std;

void FOI() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
}
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
#define int long long
#define rep(a, b, c) for(int c = a; c <= b; c++)
#define rer(a, b, c) for(int c = a; c >= b; c--)

const int maxn = 1000;

int h[maxn], cnt;

struct Edge {
	int v, last;
}e[maxn<<2];

void add(int u, int v) {
	e[++cnt] = {v, h[u]};
	h[u] = cnt;
}

struct info {
	int t, x, y, id;
	bool operator < (const info & T) 
	  const {
	    return t > T.t;
	  }
}pos[maxn];

struct lz {
	int x, y;
}Lz[maxn];

int n, p, is[101][101], r, v[maxn], vv[maxn], vvv[maxn][maxn];

int tar, sp, iid, seat[maxn], vis[maxn], ans[maxn];

void dfs(int x, int y, int t) {
//	cout << x << ' ' << y << '\n';		
	if(is[x][y] > 1)
		  add(iid, is[x][y]-1);
	if(t == tar) {
		return ;
	}
	int bx, by;
	for(int i = 0; i < 4; i++) {
		bx = x + dx[i], by = y + dy[i];
		if(vvv[bx][by]) continue;
		if(bx < 1 || by < 1 || bx > n || by > n) continue;
		vvv[bx][by] = 1;
		if(is[bx][by]) dfs(bx, by, t+1);
		vvv[bx][by] = 0;
	}
}

bool KM(int u) {
	for(int i = h[u]; i; i = e[i].last) {
		int v = e[i].v;
		if(vis[v]) continue;
		vis[v] = 1;
		if(!seat[v] || KM(seat[v])) {
			seat[v] = u;
			return 1;
		}
	}
	return 0;
}

signed main() {
	FOI();
	cin >> n;
	rep(1, n, i) {
		string s;
		cin >> s;
		rep(1, n, j)
		  is[i][j] = (s[j-1] == '.');
	}
	cin >> p;
	rep(1, p, i)
	  cin >> Lz[i].x >> Lz[i].y, is[Lz[i].x][Lz[i].y] = i+1;
	rep(1, p, i)
	  cin >> v[i];
	cin >> r;
	rep(1, r, i) 
	  cin >> pos[i].t >> pos[i].x >> pos[i].y >> pos[i].id;
	sort(pos+1, pos+r+1);
	rep(1, r, i) {
		iid = pos[i].id;
		if(!vv[pos[i].id])
		  vv[iid] = 1, tar = v[iid]*pos[i].t, dfs(pos[i].x, pos[i].y, 0);
	}
	rep(1, n, i) {
		memset(vis, 0, sizeof(vis));
		KM(i);
	}
	rep(1, p, i) {
		ans[seat[i]] = i;
	}
//	rep(1, p, i)
//	  if(!ans[i])
//	    rep(1, p, j)
//	      if(!seat[j])
//	        seat[j] = i, ans[i] = j;
	rep(1, p, i)
	  cout << i << ' ' << Lz[ans[i]].x << ' ' << Lz[ans[i]].y << '\n';
	return 0;
}

2024/4/20 10:30
加载中...