QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#190111#2346. Miniature Golfneko_nyaaAC ✓2279ms5336kbC++232.5kb2023-09-28 11:40:522023-09-28 11:40:53

Judging History

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

  • [2023-09-28 11:40:53]
  • 评测
  • 测评结果:AC
  • 用时:2279ms
  • 内存:5336kb
  • [2023-09-28 11:40:52]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

const int MAX = 1000000000;

void solve(vector<int> &a, vector<int> &b, vector<pair<int, int>> &evs) {
	// for which range of compressed values are the sum of a strictly less than the sum of b?
	long long asum = accumulate(a.begin(), a.end(), 0LL);
	long long bsum = accumulate(b.begin(), b.end(), 0LL);

	int aslope = 0, bslope = 0;
	int ap = a.size() - 1, bp = b.size() - 1;
	
	if (asum < bsum) {
		int mx = max(a.back(), b.back());
		evs.emplace_back(mx+1, 1);
		evs.emplace_back(MAX+10, -1);
	}

	while (ap >= 0 || bp >= 0) {
		int mx = 1;
		if (ap >= 0) mx = max(mx, a[ap]);
		if (bp >= 0) mx = max(mx, b[bp]);

		while (ap >= 0 && a[ap] == mx) {
			asum -= a[ap];
			aslope++;
			ap--;
		}

		while (bp >= 0 && b[bp] == mx){
			bsum -= b[bp];
			bslope++;
			bp--;
		}

		int mx2 = 0;
		if (ap >= 0) mx2 = max(mx2, a[ap]);
		if (bp >= 0) mx2 = max(mx2, b[bp]);
		mx2++;

		long long L, R;
		if (asum < bsum) {
			// starts beating b from 0, at which point is b equal or smaller than a?
			L = 1;
			// bsum + bslope*x <= asum + aslope*x
			// bsum - asum <= (aslope - bslope)*x
			// x >= (bsum - asum)/(aslope - bslope)

			if (aslope <= bslope) {
				R = MAX + 10;
			} else {
				long long dif1 = bsum - asum;
				int sldif = aslope - bslope;
				R = (dif1 + sldif - 1) / sldif;
			}
		} else {
			// at what point does a start becoming lower
			R = MAX + 10;

			// bsum + bslope*x > asum + aslope*x
			// (bslope - aslope)*x > (asum - bsum)
			// x > (asum - bsum)/(bslope - aslope)

			if (aslope >= bslope) {
				L = MAX + 10;
			} else {
				long long dif1 = asum - bsum;
				int sldif = bslope - aslope;
				L = dif1 / sldif + 1;
			}
		}

		// compress L, R within [mx2, mx]
		R = min(R, (long long)mx + 1);
		L = max(L, (long long)mx2);

		if (L < R) {
			evs.emplace_back(L, 1);
			evs.emplace_back(R, -1);
		}
	}
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);

	int n, m;
	cin >> n >> m;

	vector<vector<int>> s(n, vector<int>(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> s[i][j];
		}
		sort(s[i].begin(), s[i].end());
	}

	for (int i = 0; i < n; i++) {
		vector<pair<int, int>> evs;
		for (int j = 0; j < n; j++) {
			if (i == j) continue;
			solve(s[i], s[j], evs);
		}
		sort(evs.begin(), evs.end());

		int mx = 0, cur = 0;
		for (auto [u, v]: evs) {
			cur += v;
			mx = max(mx, cur);
		}
		cout << n - mx << '\n';
	}

	return 0;
}

Details

Test #1:

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

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

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

Test #8:

score: 0
Accepted
time: 2ms
memory: 3696kb

Test #9:

score: 0
Accepted
time: 7ms
memory: 3936kb

Test #10:

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

Test #11:

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

Test #12:

score: 0
Accepted
time: 13ms
memory: 3808kb

Test #13:

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

Test #14:

score: 0
Accepted
time: 2ms
memory: 3696kb

Test #15:

score: 0
Accepted
time: 12ms
memory: 3744kb

Test #16:

score: 0
Accepted
time: 15ms
memory: 3908kb

Test #17:

score: 0
Accepted
time: 2249ms
memory: 4924kb

Test #18:

score: 0
Accepted
time: 2279ms
memory: 4856kb

Test #19:

score: 0
Accepted
time: 2054ms
memory: 4936kb

Test #20:

score: 0
Accepted
time: 930ms
memory: 4864kb

Test #21:

score: 0
Accepted
time: 934ms
memory: 4936kb

Test #22:

score: 0
Accepted
time: 931ms
memory: 4840kb

Test #23:

score: 0
Accepted
time: 1405ms
memory: 5124kb

Test #24:

score: 0
Accepted
time: 1436ms
memory: 5132kb

Test #25:

score: 0
Accepted
time: 1403ms
memory: 5336kb

Test #26:

score: 0
Accepted
time: 1395ms
memory: 5300kb

Test #27:

score: 0
Accepted
time: 1402ms
memory: 5184kb