QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129144#5446. 琪露诺的符卡交换FISHER_0 20ms4300kbC++142.2kb2023-07-21 23:34:332023-07-21 23:34: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-21 23:34:35]
  • 评测
  • 测评结果:0
  • 用时:20ms
  • 内存:4300kb
  • [2023-07-21 23:34:33]
  • 提交

answer

#include <bits/stdc++.h>
#define PB push_back
#define EB emplace_back
using namespace std;
const int maxn = 200;
int a[maxn + 5][maxn + 5];
bool vis[maxn + 5][maxn + 5];
int id[maxn + 5][maxn + 5];
struct edge { int v, f; };
vector<edge> e;
vector<int> g[2 * maxn + 5];
inline void addE(int u, int v) {
	g[u].PB(e.size()), e.PB({v, 1});
	g[v].PB(e.size()), e.PB({u, 0});
}
int S, T;
int d[2 * maxn + 5], cur[2 * maxn + 5];
bool bfs(int s, int t) {
	memset(d + 1, 127, T * sizeof(int)), memset(cur + 1, 0, T * sizeof(int));
	queue<int> q;
	q.push(s), d[s] = 0;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (int eid : g[u]) {
			int v = e[eid].v, f = e[eid].f;
			if (f && d[v] > T) {
				q.push(v), d[v] = d[u] + 1;
				if (v == t) return 1;
			}
		}
	}
	return 0;
}
int dfs(int u, int fl, int t) {
	if (u == t) return fl;
	int rs = 0;
	for (int i = cur[u]; i < g[u].size(); i++) {
		cur[u] = i;
		int eid = g[u][i], v = e[eid].v, f = e[eid].f;
		if (f && d[v] == d[u] + 1) {
			int nf = dfs(v, min(fl, f), t);
			e[eid].f -= nf, e[eid ^ 1].f += nf;
			fl -= nf, rs += nf;
			if (!fl) break;
		}
	}
	return rs;
}
int dinic(int s, int t) {
	int rs = 0;
	while (bfs(s, t)) rs += dfs(s, INT_MAX, t);
	return rs;
}
int main() {
	int C;
	scanf("%d", &C);
	while (C--) {
		int n;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
		S = n * 2 + 1, T = S + 1;
		for (int t = 1; t <= n; t++) {
			fill(g + 1, g + T + 1, vector<int>());
			e.clear();
			for (int i = 1; i <= n; i++) addE(S, i), addE(i + n, T);
			for (int i = 1; i <= n; i++)
				for (int j = 1; j <= n; j++)
					if (!vis[i][j]) addE(i, n + a[i][j]);
			dinic(S, T);
			for (int i = 1; i <= n; i++)
				for (int eid : g[i]) {
					int j = e[eid].v, f = e[eid].f;
					if (j != S && !f) {
						for (int k = 1; k <= n; k++)
							if (!vis[i][k] && a[i][k] == j - n) {
								id[i][t] = k, vis[i][k] = 1;
								break;
							}
						break;
					}
				}
		}
		printf("%d\n", n * (n - 1) / 2);
		for (int i = 1; i <= n; i++)
			for (int j = i + 1; j <= n; j++) printf("%d %d %d %d\n", i, id[i][j], j, id[j][i]);
	}
} 

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 20ms
memory: 4300kb

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
Wrong Answer
time: 8ms
memory: 4020kb

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:

wrong answer you swapped a card not existed.

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%