Submission #150237

# Submission time Handle Problem Language Result Execution time Memory
150237 2019-09-01T07:57:34 Z 1 WA = 5 Push Up(#3624, BaaaaaaaaaaaaaaaarkingDog, IohcEjnim, 0xrgb) Wine Tasting (FXCUP4_wine) C++17
0 / 100
9 ms 772 KB
// K = 11
#include <vector>

#include "bartender.h"

std::vector<int> BlendWines(int K, std::vector<int> R) {
	const int N = R.size();
	std::vector<int> v(N, 1);

	constexpr int DATA[] = {
		0,
		1, 10, 1, 10, 1, 10,
		2, 9, 2, 9, 2, 9,
		3, 8, 3, 8, 3, 8,
		4, 7, 4, 7, 4, 7,
		5, 6, 5, 6, 5, 6,
	};

	if (K < 11) return v; // lol
	for (int i = 0; i < N; ++i) v[i] = DATA[R[i]];
	return v;
}
// K = 11
#include <algorithm>
#include <vector>

#include "taster.h"

static std::vector<int> chk2(int a, int b) {
	if (Compare(a, b) < 0) return { a, b };
	return { b, a };
}

static std::vector<int> chk3(int a, int b, int c) {
	const int r1 = Compare(a, b);
	const int r2 = Compare(b, c);
	const int r3 = Compare(c, a);

	if (r1 < 0 && r2 < 0) return { a, b, c };
	if (r2 < 0 && r3 < 0) return { c, a, b };
	if (r1 < 0 && r3 < 0) return { b, c, a };
	if (r1 < 0) return { a, c, b };
	if (r2 < 0) return { b, a, c };
	return { c, b, a };
}

static std::vector<int> chk33(int a, int b, int c, int x, int y, int z) {
	if (Compare(a, y) < 0) {
		// x < a < y
		if (Compare(b, z) < 0) return { a, b, c };
		else return { a, c, b };
	}
	else if (Compare(a, z) < 0) {
		// y < a < z
		if (Compare(b, y) < 0) return { b, a, c };
		else return { c, a, b };
	}
	else {
		// z < a
		if (Compare(b, y) < 0) return { b, c, a };
		else return { c, b, a };
	}
}

std::vector<int> SortWines(int K, std::vector<int> A) {
	int N = A.size();
	std::vector<int> ans(N);

	if (K < 11) {
		std::vector<int> rank(N);
		for (int i = 0; i < N; ++i) rank[i] = i;
		std::sort(rank.begin(), rank.end(), [](int x, int y) {
			return (Compare(x, y) < 0);
		});
		for (int i = 0; i < N; ++i) ans[rank[i]] = i + 1;
		return ans;
	}

	int cnt = 0;
	for (int i = 1; i <= 5; ++i) {
		std::vector<int> sm, lg;
		for (int j = 0; j < N; ++j) {
			if (A[j] == i) sm.push_back(j);
			if (A[j] == 11 - i) lg.push_back(j);
		}

		if (sm.size() == 0) break;
		else if (sm.size() == 1) {
			ans[sm[0]] = ++cnt;
			if (lg.size() == 1) ans[lg[0]] = ++cnt;
		}
		else if (sm.size() == 2) {
			auto tmp = chk2(sm[0], sm[1]);
			if (lg.size() == 1) {
				ans[tmp[0]] = ++cnt;
				ans[lg[0]] = ++cnt;
				ans[tmp[1]] = ++cnt;
			}
			else { // lg.size() == 2
				if (Compare(lg[0], tmp[1]) < 0) {
					// tmp[0] lg[0] tmp[1] lg[1]
					ans[tmp[0]] = ++cnt;
					ans[lg[0]] = ++cnt;
					ans[tmp[1]] = ++cnt;
					ans[lg[1]] = ++cnt;
				}
				else {
					ans[tmp[0]] = ++cnt;
					ans[lg[1]] = ++cnt;
					ans[tmp[1]] = ++cnt;
					ans[lg[0]] = ++cnt;
				}
			}
		}
		else {
			auto tmp = chk3(sm[0], sm[1], sm[2]);
			std::vector<int> rr;
			if (lg.size() == 3) {
				rr = chk33(lg[0], lg[1], lg[2], tmp[0], tmp[1], tmp[2]);
			}
			else {
				rr = chk33(lg[0], lg[1], -1, tmp[0], tmp[1], tmp[2]);
			}

			ans[tmp[0]] = ++cnt;
			if (rr[0] >= 0) ans[rr[0]] = ++cnt;
			ans[tmp[1]] = ++cnt;
			if (rr[1] >= 0) ans[rr[1]] = ++cnt;
			ans[tmp[2]] = ++cnt;
			if (rr[2] >= 0) ans[rr[2]] = ++cnt;
		}
	}

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 772 KB Correct
2 Correct 9 ms 644 KB Correct
3 Correct 9 ms 772 KB Correct
4 Correct 8 ms 772 KB Correct
5 Incorrect 8 ms 644 KB Wrong
6 Halted 0 ms 0 KB -