QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#873175#5446. 琪露诺的符卡交换fgx20 92ms5888kbC++144.4kb2025-01-26 10:10:032025-01-26 10:10:14

Judging History

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

  • [2025-01-26 10:10:14]
  • 评测
  • 测评结果:20
  • 用时:92ms
  • 内存:5888kb
  • [2025-01-26 10:10:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

struct FastIO {
	inline FastIO& operator >> (short& x) {
		x = 0;
		char f = 0, ch = getchar();
		while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
		while (ch <= '9' && ch >= '0') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
		return x = (f ? -x : x), *this;
	}
	inline FastIO& operator >> (int& x) {
		x = 0;
		char f = 0, ch = getchar();
		while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
		while (ch <= '9' && ch >= '0') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
		return x = (f ? -x : x), *this;
	}
	inline FastIO& operator >> (long long& x) {
		x = 0;
		char f = 0, ch = getchar();
		while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
		while (ch <= '9' && ch >= '0') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
		return x = (f ? -x : x), *this;
	}
	inline FastIO& operator >> (double& x) {
		x = 0;
		char f = 0, ch = getchar();
		double d = 0.1;
		while (ch > '9' || ch < '0') f |= (ch == '-'), ch = getchar();
		while (ch <= '9' && ch >= '0') x = x * 10 + (ch ^ 48), ch = getchar();
		if (ch == '.') {
			ch = getchar();
			while (ch <= '9' && ch >= '0') x += d * (ch ^ 48), d *= 0.1, ch = getchar();
		}
		return x = (f ? -x : x), *this;
	}
} rin;

#define endl "\n"

struct NetworkFlow {
	int n, m, s, t;
	int inf; 
	int tot;
	vector<int> head;
	vector<int> c;
	vector<int> ver, Next;
	vector<int> dis;
	vector<int> now;
	vector<bool> del;
	NetworkFlow* newNetworkFlow(int N, int M, int S, int T, int Inf) {
		n = N, m = M, s = S, t = T, inf = Inf, tot = 1;
		const int maxDirEdge = (M << 1) + 10, maxVer = N + 10;
		head.assign(maxVer, 0);
		c.assign(maxDirEdge, 0);
		ver.assign(maxDirEdge, 0);
		Next.assign(maxDirEdge, 0);
		del.assign(maxDirEdge, 0);
		now.assign(maxVer, 0);
		return this;
	}
	inline void addDir(int u, int v, int limFlow) {
		c[++tot] = limFlow;
		ver[tot] = v;
		Next[tot] = head[u];
		head[u] = tot;
	}
	inline void add(int u, int v, int limFlow) {
		addDir(u, v, limFlow);
		addDir(v, u, 0);
	}
	bool bfs() {
		dis.assign(n + 1, inf);
		
		queue<int> q;
		q.push(s), dis[s] = 0, now[s] = head[s];
		
		while (!q.empty()) {
			int u = q.front(); q.pop();
			for (int i = now[u]; i; i = Next[i]) {
				if (del[i]) continue;
				int v = ver[i];
				if (c[i] > 0 && dis[v] == inf) {
					q.push(v);
					now[v] = head[v];
					dis[v] = dis[u] + 1;
					if (v == t) return true;
				}
			}
		}
		return false;
	}
	inline int dfs(int u, int sum) {
		if (u == t) return sum;
		int k, res = 0;
		for (int i = now[u]; i && sum; i = Next[i]) {
			if (del[i]) continue;
			now[u] = i;
			int v = ver[i];
			if (c[i] > 0 && dis[v] == dis[u] + 1) {
				k = dfs(v, min(sum, c[i]));
				if (k == 0) dis[v] = inf;
				c[i] -= k;
				c[i ^ 1] += k;
				res += k;
				sum -= k;
			}
		}
		return res;
	}
	inline int maxFlow() {
		int ret = 0;
		while (bfs()) ret += dfs(s, inf);
		return ret;
	}
};

const int N = 210;
int n, crd[N][N], row[N], ele[N], mat[N][N];
bool chos[N][N];

inline void solve() {
	rin >> n;
	const int S = 1, T = 2;
	int cV = 2;
	NetworkFlow net;
	net.newNetworkFlow((n << 1) + 2, n * n * 3, S, T, 0x3f3f3f);
	for (int i = 1; i <= n; ++i) row[i] = ++cV;
	for (int i = 1; i <= n; ++i) ele[i] = ++cV;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) {
			rin >> crd[i][j], chos[i][j] = false;
			net.add(row[i], ele[crd[i][j]], 1);
		}
	for (int t = 1; t <= n; ++t) {
		for (int i = 1; i <= n; ++i) net.add(S, row[i], 1);
		for (int i = 1; i <= n; ++i) net.add(ele[i], T, 1);
		net.maxFlow();
		for (int i = 1; i <= n; ++i)
			for (int e = net.head[row[i]]; e; e = net.Next[e]) {
//					cout << row[i] << " -> " << net.ver[e] << " " << net.c[e] << endl;
					if (!net.del[e] && !net.c[e] && net.ver[e] != S) {
						int j = net.ver[e] - n - 2;
						for (int k = 1; k <= n; ++k)
							if (!chos[i][k] && crd[i][k] == j) {
								chos[i][k] = true;
								mat[i][t] = k;
								break;
							}
						break;
					}
				}
		for (int e = 1; e <= net.tot; ++e) if (!net.c[e]) net.del[e] = true;
//		for (int i = 1; i <= n; ++i) cout << mat[i][t] << " ";
//		cout << endl;
	}
	cout << n * (n - 1) / 2 << endl;
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
			cout << i << " " << mat[i][j] << " " << j << " " << mat[j][i] << endl;
}

signed main() {
	int T;
	rin >> T;
	while (T--) solve();
	return 0;
}

詳細信息

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 40ms
memory: 4864kb

input:

7
132
96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 ...

output:

8646
1 2 2 1
1 3 3 1
1 4 4 1
1 5 5 1
1 6 6 1
1 7 7 1
1 8 8 1
1 9 9 1
1 10 10 1
1 11 11 1
1 12 12 1
1 13 13 1
1 14 14 1
1 15 15 1
1 16 16 1
1 17 17 1
1 18 18 1
1 19 19 1
1 20 20 1
1 21 21 1
1 22 22 1
1 23 23 1
1 24 24 1
1 25 25 1
1 26 26 1
1 27 27 1
1 28 28 1
1 29 29 1
1 30 30 1
1 31 31 1
1 32 32 1
1...

result:

ok your solution is correct.

Test #2:

score: 20
Accepted
time: 14ms
memory: 4224kb

input:

8
14
13 13 13 13 13 13 13 13 13 13 13 13 13 13
7 7 7 7 7 7 7 7 7 7 7 7 7 7
8 8 8 8 8 8 8 8 8 8 8 8 8 8
14 14 14 14 14 14 14 14 14 14 14 14 14 14
5 5 5 5 5 5 5 5 5 5 5 5 5 5
4 4 4 4 4 4 4 4 4 4 4 4 4 4
1 1 1 1 1 1 1 1 1 1 1 1 1 1
10 10 10 10 10 10 10 10 10 10 10 10 10 10
2 2 2 2 2 2 2 2 2 2 2 2 2 2
9...

output:

91
1 2 2 1
1 3 3 1
1 4 4 1
1 5 5 1
1 6 6 1
1 7 7 1
1 8 8 1
1 9 9 1
1 10 10 1
1 11 11 1
1 12 12 1
1 13 13 1
1 14 14 1
2 3 3 2
2 4 4 2
2 5 5 2
2 6 6 2
2 7 7 2
2 8 8 2
2 9 9 2
2 10 10 2
2 11 11 2
2 12 12 2
2 13 13 2
2 14 14 2
3 4 4 3
3 5 5 3
3 6 6 3
3 7 7 3
3 8 8 3
3 9 9 3
3 10 10 3
3 11 11 3
3 12 12 3...

result:

ok your solution is correct.

Test #3:

score: 20
Accepted
time: 24ms
memory: 4044kb

input:

4
82
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1...

output:

3321
1 2 2 1
1 3 3 1
1 4 4 1
1 5 5 1
1 6 6 1
1 7 7 1
1 8 8 1
1 9 9 1
1 10 10 1
1 11 11 1
1 12 12 1
1 13 13 1
1 14 14 1
1 15 15 1
1 16 16 1
1 17 17 1
1 18 18 1
1 19 19 1
1 20 20 1
1 21 21 1
1 22 22 1
1 23 23 1
1 24 24 1
1 25 25 1
1 26 26 1
1 27 27 1
1 28 28 1
1 29 29 1
1 30 30 1
1 31 31 1
1 32 32 1
1...

result:

ok your solution is correct.

Test #4:

score: 20
Accepted
time: 92ms
memory: 5888kb

input:

8
3
1 1 1
3 3 3
2 2 2
3
1 1 1
3 3 3
2 2 2
1
1
11
5 5 5 5 5 5 5 5 5 5 5
3 3 3 3 3 3 3 3 3 3 3
1 1 1 1 1 1 1 1 1 1 1
9 9 9 9 9 9 9 9 9 9 9
4 4 4 4 4 4 4 4 4 4 4
11 11 11 11 11 11 11 11 11 11 11
2 2 2 2 2 2 2 2 2 2 2
6 6 6 6 6 6 6 6 6 6 6
8 8 8 8 8 8 8 8 8 8 8
10 10 10 10 10 10 10 10 10 10 10
7 7 7 7 7...

output:

3
1 2 2 1
1 3 3 1
2 3 3 2
3
1 2 2 1
1 3 3 1
2 3 3 2
0
55
1 2 2 1
1 3 3 1
1 4 4 1
1 5 5 1
1 6 6 1
1 7 7 1
1 8 8 1
1 9 9 1
1 10 10 1
1 11 11 1
2 3 3 2
2 4 4 2
2 5 5 2
2 6 6 2
2 7 7 2
2 8 8 2
2 9 9 2
2 10 10 2
2 11 11 2
3 4 4 3
3 5 5 3
3 6 6 3
3 7 7 3
3 8 8 3
3 9 9 3
3 10 10 3
3 11 11 3
4 5 5 4
4 6 6 4...

result:

ok your solution is correct.

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #5:

score: 0
Wrong Answer
time: 63ms
memory: 5376kb

input:

5
17
9 9 9 9 9 9 9 9 9 9 9 9 9 2 9 9 9
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6
2 2 2 2 2 2 2 2 2 2 2 2 11 2 2 2 2
4 4 4 4 4 4 10 4 4 4 4 4 4 4 4 4 4
10 10 10 10 10 10 8 10 10 10 10 10 10 10 10 10 10
12 12 12 12 12 12 12 12 12 12 12 12 14 12 12 12 12
14 14 14 14 14 14 14 14 14 14 14 12 14 14 14 14 14
16 16...

output:

136
1 2 2 1
1 3 3 1
1 4 4 1
1 5 5 1
1 6 6 1
1 7 7 1
1 8 8 1
1 9 9 1
1 10 10 1
1 11 11 1
1 12 12 1
1 13 13 1
1 15 14 1
1 16 15 1
1 17 16 1
1 0 17 1
2 2 3 2
2 3 4 7
2 4 5 2
2 5 6 2
2 6 7 2
2 7 8 2
2 8 9 3
2 9 10 2
2 10 11 3
2 11 12 3
2 12 13 2
2 13 14 17
2 14 15 2
2 15 16 2
2 0 17 2
3 4 4 2
3 5 5 3
3 ...

result:

wrong answer you swapped a card not existed.

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%