QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#94716#5615. Two Charts Become OnePetroTarnavskyi#RE 0ms0kbC++172.2kb2023-04-07 16:20:112023-04-07 16:20:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-07 16:20:13]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-04-07 16:20:11]
  • 提交

answer

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

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int MAX = 107;
const int INF = 1e9;

int u[MAX];
int v[MAX];
int p[MAX];
int way[MAX];
int minv[MAX];
bool used[MAX];

int hungarian(const vector<vector<int>>& a) {
	int n = SZ(a), m = SZ(a[0]);
	FOR(i, 0, n + 1) {
		u[i] = 0;
	}
	FOR(j, 0, m + 1) {
		v[j] = 0;
		p[j] = n;
		way[j] = 0;
	}
	FOR(i, 0, n) {
		p[m] = i;
		int j0 = m;
		FOR(j, 0, m + 1) {
			minv[j] = INF;
			used[j] = 0;
		}
		while (p[j0] != n) {
			used[j0] = true;
			int i0 = p[j0];
			int j1 = -1;
			int delta = INF;
			FOR(j, 0, m) {
				if (!used[j]) {
					int cur = a[i0][j] - u[i0] - v[j];
					if (cur < minv[j]) {
						minv[j] = cur;
						way[j] = j0;
					}
					if (minv[j] < delta) {
						delta = minv[j];
						j1 = j;
					}
				}
			}
			FOR(j, 0, m + 1) {
				if (used[j]) {
					u[p[j]] += delta;
					v[j] -= delta;
				}
				else {
					minv[j] -= delta;
				}
			}
			assert(j1 != -1);
			j0 = j1;
		}
		while (j0 != m) {
			int j1 = way[j0];
			p[j0] = p[j1];
			j0 = j1;
		}
	}
	vector<int> ans(n + 1);
	FOR(j, 0, m) {
		ans[p[j]] = j;
	}
	int res = 0;
	FOR(i, 0, n) {
		res += a[i][ans[i]];
	}
	assert(res == -v[m]);
	return res;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector b(n, vector<int>(m));
	for (auto& bi : b) {
		for (int& bij : bi) {
			cin >> bij;
		}
	}
	vector d(n, vector<int>(n));
	for (auto& di : d) {
		for (int& dij : di) {
			cin >> dij;
			if (dij == -1) {
				dij = INF;
			}
		}
	}
	FOR(k, 0, n) {
		FOR(i, 0, n) {
			FOR(j, 0, n) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	vector a(m, vector<int>(n));
	FOR(i, 0, m) {
		FOR(j, 0, n) {
			FOR(k, 0, n) {
				a[i][j] += d[j][k] * b[j][i];
			}
		}
	}
	cout << hungarian(a) << "\n";
	return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

11 (10) (12 (13) (17) (28))
11 (12 (17) (28) (13)) (10)

output:


result: