QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#223446#3588. Hamilton - The MusicalatoizWA 17ms5680kbC++142.0kb2023-10-22 07:23:332023-10-22 07:23:34

Judging History

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

  • [2023-10-22 07:23:34]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:5680kb
  • [2023-10-22 07:23:33]
  • 提交

answer

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <numeric>
#include <functional>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int nl; cin >> nl;
	vector<vector<int64_t>> pl(nl, vector<int64_t>(nl));
	for (int i = 0; i < nl; ++i) {
		for (int j = 0; j < nl; ++j) {
			cin >> pl[i][j];
		}
	}
	
	int n = (nl + 1) / 2;
	vector<vector<int64_t>> c(n, vector<int64_t>(n, 0));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (2*j > 0) c[i][j] += pl[2*i][2*j-1];
			if (2*j < nl-1) c[i][j] += pl[2*i][2*j+1];
		}
	}

	vector<int64_t> wx(n, 2e9), wy(n, 0), slk(n);
	vector<int> mx(n, -1), my(n, -1), vis(n), par(n), q;

	const auto bfs = [&](int s) {
		fill(slk.begin(), slk.end(), 2e9);
		fill(vis.begin(), vis.end(), 0);
		q.clear();
		vis[s] = 1;
		q.push_back(s);
		int qi = 0;

		while (true) {
			for (; qi < (int) q.size(); ++qi) {
				int x = q[qi];
				for (int y = 0; y < n; ++y) if (my[y] == -1 or !vis[my[y]]) {
					int64_t k = wx[x] + wy[y] - c[x][y];
					if (k == 0) {
						par[y] = x;
						if (my[y] == -1) {
							for (int i = y; i != -1; swap(mx[my[i] = par[i]], i));
							return;
						} else {
							vis[my[y]] = 1;
							q.push_back(my[y]);
						}
					} else if (slk[y] > k) {
						par[y] = x;
						slk[y] = k;
					}
				}
			}

			int y = -1; int64_t minslk = 2e9;
			for (int i = 0; i < n; ++i) if (my[i] == -1 or !vis[my[i]]) {
				if (slk[i] < minslk) minslk = slk[y = i];
			}
			for (int x = 0; x < n; ++x) if (vis[x]) {
				wx[x] -= minslk;
				if (mx[x] != -1) wy[mx[x]] += minslk;
			}
			if (my[y] == -1) {
				for (int i = y; i != -1; swap(mx[my[i] = par[i]], i));
				return;
			} else {
				vis[my[y]] = 1;
				q.push_back(my[y]);
			}
		}
	};

	for (int s = 0; s < n; ++s) bfs(s);
	cout << accumulate(wx.begin(), wx.end(), accumulate(wy.begin(), wy.end(), int64_t(0))) << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3760kb

input:

4
0 3 2 13
3 0 8 9
2 8 0 5
13 9 5 0

output:

16

result:

ok single line: '16'

Test #2:

score: -100
Wrong Answer
time: 17ms
memory: 5680kb

input:

455
0 71154840 37432199 724743679 761809953 949789082 725973225 28455138 924138757 574256423 297516452 223475432 693485895 699629134 731875885 697643903 595490098 206757530 965177624 178416136 103223719 474785234 322984824 510200285 656185874 993023494 973542087 511171280 465648799 836547414 8145240...

output:

1030302249054668108

result:

wrong answer 1st lines differ - expected: '25287020967', found: '1030302249054668108'