QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#122119#6570. Who Watches the Watchmen?tacorefWA 547ms17544kbC++176.1kb2023-07-09 14:59:332023-07-09 14:59:35

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-09 14:59:35]
  • 评测
  • 测评结果:WA
  • 用时:547ms
  • 内存:17544kb
  • [2023-07-09 14:59:33]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using P3 = array<lint, 3>;
using pi = array<lint, 2>;
const int MAXN = 1005;

struct mcmf {
	struct edg {
		int pos, cap, rev;
		lint cost;
	};
	vector<edg> gph[MAXN];
	void clear() {
		for (int i = 0; i < MAXN; i++)
			gph[i].clear();
	}
	void addEdge(int s, int e, int x, lint c) {
		gph[s].push_back({e, x, sz(gph[e]), c});
		gph[e].push_back({s, 0, sz(gph[s]) - 1, -c});
	}
	lint dist[MAXN];
	int pa[MAXN], pe[MAXN];
	bool inque[MAXN];
	bool spfa(int src, int sink) {
		memset(dist, 0x3f, sizeof(dist));
		memset(inque, 0, sizeof(inque));
		queue<int> que;
		dist[src] = 0;
		inque[src] = 1;
		que.push(src);
		bool ok = 0;
		while (sz(que)) {
			int x = que.front();
			que.pop();
			if (x == sink)
				ok = 1;
			inque[x] = 0;
			for (int i = 0; i < sz(gph[x]); i++) {
				edg e = gph[x][i];
				if (e.cap > 0 && dist[e.pos] > dist[x] + e.cost) {
					dist[e.pos] = dist[x] + e.cost;
					pa[e.pos] = x;
					pe[e.pos] = i;
					if (!inque[e.pos]) {
						inque[e.pos] = 1;
						que.push(e.pos);
					}
				}
			}
		}
		return ok;
	}
	lint match(int src, int sink) {
		lint ret = 0;
		while (spfa(src, sink)) {
			lint cap = 1e18;
			for (int pos = sink; pos != src; pos = pa[pos]) {
				cap = min(cap, (lint)gph[pa[pos]][pe[pos]].cap);
			}
			ret += cap * dist[sink];
			for (int pos = sink; pos != src; pos = pa[pos]) {
				int rev = gph[pa[pos]][pe[pos]].rev;
				gph[pa[pos]][pe[pos]].cap -= cap;
				gph[pos][rev].cap += cap;
			}
		}
		return ret;
	}
} mcmf;

int hung(vector<vector<int>> a) {
	int n = sz(a);
	for (int i = 0; i < n; i++) {
		mcmf.addEdge(0, i + 1, 1, 0);
		mcmf.addEdge(i + n + 1, n + n + 1, 1, 0);
		for (int j = 0; j < n; j++) {
			mcmf.addEdge(i + 1, j + n + 1, 1, a[i][j]);
		}
	}
	return mcmf.match(0, 2 * n + 1);
}

P3 operator-(P3 a, P3 b) {
	for (int i = 0; i < 3; i++)
		a[i] -= b[i];
	return a;
}

P3 norm(P3 a) {
	lint g = 0;
	for (int i = 0; i < 3; i++) {
		g = gcd(g, abs(a[i]));
	}
	assert(g > 0);
	for (int i = 0; i < 3; i++) {
		a[i] /= g;
	}
	return a;
}

P3 cross(const P3 &a, const P3 &b) { return P3{a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]}; }
P3 cross(const P3 &a, const P3 &b, const P3 &c) { return cross(b - a, c - a); }

bool isMult(const P3 &a, const P3 &b) {
	P3 c = cross(a, b);
	for (int i = 0; i < sz(c); i++) {
		if (c[i] != 0)
			return 0;
	}
	return 1;
}

bool collinear(const P3 &a, const P3 &b, const P3 &c) { return isMult(b - a, c - a); }

lint dist(P3 a, P3 b) {
	lint ans = 0;
	for (int i = 0; i < 3; i++)
		ans += (a[i] - b[i]) * (a[i] - b[i]);
	return ans;
}

lint dot(P3 a, P3 b) {
	lint ans = 0;
	for (int i = 0; i < 3; i++)
		ans += a[i] * b[i];
	return ans;
}

bool is_collinear(vector<P3> p) {
	for (int i = 2; i < sz(p); i++) {
		if (!collinear(p[0], p[1], p[i]))
			return false;
	}
	return true;
}

int haveSex(vector<P3> p, vector<P3> d, int n) {
	P3 arg = p[1] - p[0];
	int dap = 1557;
	for (int i = 0; i < 2; i++) {
		vector<int> ord(n);
		iota(all(ord), 0);
		sort(all(ord), [&](const int &x, const int &y) { return dot(p[x], arg) < dot(p[y], arg); });
		for (int i = 0; i < n; i++) {
			vector<int> remord = ord;
			remord.erase(remord.begin() + i);
			int isol = ord[i];
			vector<int> left(n - 1), right(n - 1);
			for (int i = 0; i < n - 1; i += 2) {
				int cnt = 0;
				if (norm(d[remord[i]]) != norm(p[remord[i + 1]] - p[remord[i]]))
					cnt++;
				if (norm(d[remord[i + 1]]) != norm(p[remord[i]] - p[remord[i + 1]]))
					cnt++;
				left[i + 1] += cnt;
				right[i] += cnt;
			}
			for (int i = 1; i < n - 1; i++)
				left[i] += left[i - 1];
			for (int i = n - 3; i >= 0; i--)
				right[i] += right[i + 1];
			vector<int> euhehe(n - 1);
			for (int i = 0; i < n - 2; i++) {
				P3 z = p[remord[i + 1]] - p[remord[i]];
				P3 head = d[remord[i]];
				if (norm(z) != norm(head))
					euhehe[i + 1] += 1;
				euhehe[i + 1] += euhehe[i];
			}
			for (int l = 0; l < n - 1; l += 2) {
				for (int r = l + 1; r < n - 1; r += 2) {
					int cost = 0;
					if (l > 0)
						cost += left[l - 1];
					if (r < n - 1)
						cost += right[r + 1];
					cost += euhehe[r] - euhehe[l];
					int isolCollinear = isMult(d[isol], arg);
					int backCollinear = isMult(d[remord[r]], arg);
					if (isolCollinear || backCollinear) {
						cost += isolCollinear;
						cost += backCollinear;
					} else {
						P3 a = arg;
						P3 b = d[remord[r]];
						P3 c = d[isol];
						if (isMult(b, c)) {
							cost++;
						} else {
							P3 cr1 = cross(a, b);
							P3 cr2 = cross(b, c);
							if (norm(cr1) != norm(cr2))
								cost++;
						}
					}
					dap = min(dap, cost);
				}
			}
		}
		for (int j = 0; j < 3; j++)
			arg[j] = -arg[j];
	}
	return 1000 + dap;
}

int main() {
	int n;
	cin >> n;
	if (n == 1) {
		cout << "-1\n";
		return 0;
	}
	vector<P3> p(n), d(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++)
			cin >> p[i][j];
		for (int j = 0; j < 3; j++)
			cin >> d[i][j];
	}
	if (n == 2) {
		int ans = 0;
		if (norm(d[0]) != norm(p[1] - p[0]))
			ans++;
		if (norm(d[1]) != norm(p[0] - p[1]))
			ans++;
		cout << ans << "\n";
		return 0;
	}
	if (is_collinear(p) && n % 2 == 1) {
		cout << haveSex(p, d, n) << "\n";
		return 0;
	}
	vector<vector<int>> mtrx(n, vector<int>(n, 1e6));
	for (int i = 0; i < n; i++) {
		pi ans{lint(1e18), -1};
		vector<int> ord;
		for (int j = 0; j < n; j++) {
			if (i == j)
				continue;
			ord.push_back(j);
			if (norm(p[j] - p[i]) == norm(d[i])) {
				ans = min(ans, pi{dist(p[i], p[j]), j});
			}
		}
		sort(all(ord), [&](const int &x, const int &y) { return dist(p[i], p[x]) < dist(p[i], p[y]); });
		if (ans[0] < 1e15) {
			mtrx[i][ans[1]] = 0;
		}
		set<P3> s;
		for (int j = 0; j < sz(ord); j++) {
			auto nrm = norm(p[ord[j]] - p[i]);
			if (s.count(nrm))
				continue;
			s.insert(nrm);
			mtrx[i][ord[j]] = min(1, mtrx[i][ord[j]]);
		}
	}
	cout << hung(mtrx) << "\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3492kb

input:

7
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 1 0 0
5 0 0 1 0 0
6 0 0 -1 0 0

output:

1002

result:

ok single line: '1002'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3436kb

input:

4
66 45 10 73 39 36
95 14 26 47 84 59
14 66 89 89 36 78
16 27 94 79 24 24

output:

4

result:

ok single line: '4'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3424kb

input:

3
0 0 0 1 0 0
1 1 1 1 0 0
2 2 2 1 0 0

output:

1002

result:

ok single line: '1002'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3424kb

input:

3
0 0 0 1 1 1
1 1 1 1 0 0
2 2 2 1 0 0

output:

1001

result:

ok single line: '1001'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3492kb

input:

3
0 0 0 1 0 0
1 1 1 1 0 0
2 2 2 -1 -1 -1

output:

1001

result:

ok single line: '1001'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3452kb

input:

3
0 0 0 1 0 0
1 1 1 1 2 2
2 2 2 -1 -1 -1

output:

1000

result:

ok single line: '1000'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3416kb

input:

3
0 0 0 1 0 0
1 1 1 1 2 2
2 2 2 1 1 1

output:

1001

result:

ok single line: '1001'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3416kb

input:

1
0 0 0 3 1 4

output:

-1

result:

ok single line: '-1'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3440kb

input:

4
0 0 0 1 1 1
1 0 0 -1 0 0
1 1 1 0 -1 0
1 0 1 0 1 0

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 545ms
memory: 17492kb

input:

500
0 0 0 1 0 0
1 0 0 1 0 0
2 0 0 -1 0 0
3 0 0 1 0 0
4 0 0 1 0 0
5 0 0 1 0 0
6 0 0 1 0 0
7 0 0 1 0 0
8 0 0 1 0 0
9 0 0 1 0 0
10 0 0 -1 0 0
11 0 0 -1 0 0
12 0 0 1 0 0
13 0 0 -1 0 0
14 0 0 1 0 0
15 0 0 1 0 0
16 0 0 1 0 0
17 0 0 -1 0 0
18 0 0 -1 0 0
19 0 0 -1 0 0
20 0 0 -1 0 0
21 0 0 1 0 0
22 0 0 1 0 0...

output:

250

result:

ok single line: '250'

Test #11:

score: 0
Accepted
time: 538ms
memory: 17544kb

input:

500
0 0 0 0 1 0
0 1 0 0 1 0
0 2 0 0 -1 0
0 3 0 0 1 0
0 4 0 0 1 0
0 5 0 0 1 0
0 6 0 0 1 0
0 7 0 0 1 0
0 8 0 0 1 0
0 9 0 0 1 0
0 10 0 0 -1 0
0 11 0 0 -1 0
0 12 0 0 1 0
0 13 0 0 -1 0
0 14 0 0 1 0
0 15 0 0 1 0
0 16 0 0 1 0
0 17 0 0 -1 0
0 18 0 0 -1 0
0 19 0 0 -1 0
0 20 0 0 -1 0
0 21 0 0 1 0
0 22 0 0 1 0...

output:

250

result:

ok single line: '250'

Test #12:

score: 0
Accepted
time: 547ms
memory: 17496kb

input:

500
0 0 0 0 0 1
0 0 1 0 0 1
0 0 2 0 0 -1
0 0 3 0 0 1
0 0 4 0 0 1
0 0 5 0 0 1
0 0 6 0 0 1
0 0 7 0 0 1
0 0 8 0 0 1
0 0 9 0 0 1
0 0 10 0 0 -1
0 0 11 0 0 -1
0 0 12 0 0 1
0 0 13 0 0 -1
0 0 14 0 0 1
0 0 15 0 0 1
0 0 16 0 0 1
0 0 17 0 0 -1
0 0 18 0 0 -1
0 0 19 0 0 -1
0 0 20 0 0 -1
0 0 21 0 0 1
0 0 22 0 0 1...

output:

250

result:

ok single line: '250'

Test #13:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

5
1 0 0 1 -1 0
2 0 0 0 1 0
3 0 0 -1 0 0
4 0 0 -1 0 0
5 0 0 -1 0 0

output:

1000

result:

ok single line: '1000'

Test #14:

score: 0
Accepted
time: 1ms
memory: 3440kb

input:

5
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 0 1 0
5 0 0 -1 -1 0

output:

1000

result:

ok single line: '1000'

Test #15:

score: 0
Accepted
time: 1ms
memory: 3520kb

input:

6
0 1 0 1 0 0
0 2 0 0 2 0
0 3 0 0 3 0
0 4 0 0 4 0
0 5 0 0 5 0
0 6 0 0 6 0

output:

4

result:

ok single line: '4'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

9
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
0 1 0 0 1 0
0 2 0 0 1 0
0 3 0 0 1 0
0 0 1 0 0 1
0 0 2 0 0 1
0 0 3 0 0 1

output:

3

result:

ok single line: '3'

Test #17:

score: 0
Accepted
time: 118ms
memory: 3488kb

input:

499
0 0 0 1 0 0
1 0 0 1 0 0
2 0 0 -1 0 0
3 0 0 1 0 0
4 0 0 1 0 0
5 0 0 1 0 0
6 0 0 1 0 0
7 0 0 1 0 0
8 0 0 1 0 0
9 0 0 1 0 0
10 0 0 -1 0 0
11 0 0 -1 0 0
12 0 0 1 0 0
13 0 0 -1 0 0
14 0 0 1 0 0
15 0 0 1 0 0
16 0 0 1 0 0
17 0 0 -1 0 0
18 0 0 -1 0 0
19 0 0 -1 0 0
20 0 0 -1 0 0
21 0 0 1 0 0
22 0 0 1 0 0...

output:

1220

result:

ok single line: '1220'

Test #18:

score: 0
Accepted
time: 118ms
memory: 3524kb

input:

499
0 0 0 0 1 0
0 1 0 0 1 0
0 2 0 0 -1 0
0 3 0 0 1 0
0 4 0 0 1 0
0 5 0 0 1 0
0 6 0 0 1 0
0 7 0 0 1 0
0 8 0 0 1 0
0 9 0 0 1 0
0 10 0 0 -1 0
0 11 0 0 -1 0
0 12 0 0 1 0
0 13 0 0 -1 0
0 14 0 0 1 0
0 15 0 0 1 0
0 16 0 0 1 0
0 17 0 0 -1 0
0 18 0 0 -1 0
0 19 0 0 -1 0
0 20 0 0 -1 0
0 21 0 0 1 0
0 22 0 0 1 0...

output:

1220

result:

ok single line: '1220'

Test #19:

score: 0
Accepted
time: 118ms
memory: 3480kb

input:

499
0 0 0 0 0 1
0 0 1 0 0 1
0 0 2 0 0 -1
0 0 3 0 0 1
0 0 4 0 0 1
0 0 5 0 0 1
0 0 6 0 0 1
0 0 7 0 0 1
0 0 8 0 0 1
0 0 9 0 0 1
0 0 10 0 0 -1
0 0 11 0 0 -1
0 0 12 0 0 1
0 0 13 0 0 -1
0 0 14 0 0 1
0 0 15 0 0 1
0 0 16 0 0 1
0 0 17 0 0 -1
0 0 18 0 0 -1
0 0 19 0 0 -1
0 0 20 0 0 -1
0 0 21 0 0 1
0 0 22 0 0 1...

output:

1220

result:

ok single line: '1220'

Test #20:

score: 0
Accepted
time: 1ms
memory: 3424kb

input:

5
0 0 0 0 -1 0
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 1 0 0

output:

1001

result:

ok single line: '1001'

Test #21:

score: 0
Accepted
time: 1ms
memory: 3456kb

input:

5
0 0 0 1 0 0
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 0 1 0

output:

1001

result:

ok single line: '1001'

Test #22:

score: 0
Accepted
time: 1ms
memory: 3456kb

input:

5
0 0 0 1 0 0
1 0 0 1 0 0
2 0 0 0 -1 0
3 0 0 1 0 0
4 0 0 -1 0 0

output:

1001

result:

ok single line: '1001'

Test #23:

score: 0
Accepted
time: 1ms
memory: 3532kb

input:

5
0 0 0 1 0 0
1 0 0 -1 0 0
2 0 0 1 0 0
3 0 0 0 -1 0
4 0 0 1 0 0

output:

1001

result:

ok single line: '1001'

Test #24:

score: 0
Accepted
time: 1ms
memory: 3420kb

input:

5
0 0 0 1 1 0
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 -1 -1 0

output:

1001

result:

ok single line: '1001'

Test #25:

score: 0
Accepted
time: 1ms
memory: 3420kb

input:

5
0 0 0 1 1 0
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 1 1 0

output:

1001

result:

ok single line: '1001'

Test #26:

score: 0
Accepted
time: 1ms
memory: 3472kb

input:

5
0 0 0 5 -1 0
1 0 0 1 0 0
2 0 0 1 0 0
3 0 0 1 0 0
4 0 0 1 -1 0

output:

1001

result:

ok single line: '1001'

Test #27:

score: 0
Accepted
time: 1ms
memory: 3480kb

input:

17
0 0 0 0 0 1
0 1 0 0 0 1
0 2 0 0 0 1
0 3 0 0 0 1
0 4 0 0 0 1
0 -1 0 0 0 1
0 -2 0 0 0 1
0 -3 0 0 0 1
0 -4 0 0 0 1
1 3 0 0 0 1
2 3 0 0 0 1
-1 3 0 0 0 1
-2 3 0 0 0 1
1 -3 0 0 0 1
2 -3 0 0 0 1
-1 -3 0 0 0 1
-2 -3 0 0 0 1

output:

17

result:

ok single line: '17'

Test #28:

score: 0
Accepted
time: 1ms
memory: 3528kb

input:

17
0 0 0 0 4 0
0 1 0 0 -1 0
0 2 0 0 -2 0
0 3 0 0 -3 0
0 4 0 0 -4 0
0 -1 0 0 1 0
0 -2 0 0 2 0
0 -3 0 0 3 0
0 -4 0 0 4 0
1 3 0 -1 -3 0
2 3 0 -1 -2 0
-1 3 0 1 -3 0
-2 3 0 2 -3 0
1 -3 0 -1 3 0
2 -3 0 -2 3 0
-1 -3 0 1 3 0
-2 -3 0 2 3 0

output:

10

result:

ok single line: '10'

Test #29:

score: 0
Accepted
time: 1ms
memory: 3576kb

input:

17
0 0 0 0 1 0
0 1 0 0 1 0
0 2 0 0 1 0
0 3 0 0 1 0
0 4 0 2 -1 0
0 -1 0 0 1 0
0 -2 0 0 1 0
0 -3 0 0 1 0
0 -4 0 0 1 0
1 3 0 -1 0 0
2 3 0 -1 0 0
-1 3 0 -1 0 0
-2 3 0 4 -6 0
1 -3 0 -1 0 0
2 -3 0 -1 0 0
-1 -3 0 -1 0 0
-2 -3 0 2 -1 0

output:

3

result:

ok single line: '3'

Test #30:

score: 0
Accepted
time: 0ms
memory: 3428kb

input:

5
0 0 0 1 1 1
0 0 1 0 0 1
0 0 2 0 0 1
0 0 3 0 0 1
0 0 4 0 -1 1

output:

1001

result:

ok single line: '1001'

Test #31:

score: 0
Accepted
time: 474ms
memory: 17544kb

input:

500
-455212 958307 274912 -88656 390687 881409
-498879 -623821 322766 -916023 347922 541726
-594515 -554311 -413504 -881701 -506880 -144667
658945 -503396 791805 314816 -830920 -769486
-200847 845218 468338 -166468 -49854 -287877
-820402 914874 916800 258029 -210000 -296727
702016 -389491 -31529 -52...

output:

499

result:

ok single line: '499'

Test #32:

score: 0
Accepted
time: 0ms
memory: 3476kb

input:

3
1000000 -1 -1 -1000000 -999999 -999999
-1 1000000 -1 101 -101 0
100 999899 -1 999999 1000000 999999

output:

1000

result:

ok single line: '1000'

Test #33:

score: -100
Wrong Answer
time: 1ms
memory: 3428kb

input:

3
1000000 -1 -1 1000000 999999 999999
-1 1000000 -1 101 -101 0
100 999899 -1 999999 1000000 999999

output:

1000

result:

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