제출 #800680

#제출 시각아이디문제언어결과실행 시간메모리
800680happypotato저울 (IOI15_scales)C++17
45.45 / 100
1 ms212 KiB
#include "scales.h"

#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back

void init(int T) {
	
}

/*
getHeaviest()
getLightest()
getMedian()
getNextLightest()
*/

vector<pair<int, vector<int>>> clues; // {type, {answer, [query elements]}}
vector<int> perm = {0, 1, 2, 3, 4, 5, 6};
vector<vector<int>> FindAllPossible() {
	sort(perm.begin(), perm.end());
	vector<vector<int>> res = {};
	do {
		bool valid = true;
		for (pair<int, vector<int>> &cur : clues) {
			// cerr << "CLUE " << cur.ff << ' ';
			// for (int &x : cur.ss) cerr << x << ' '; cerr << endl;
			if (cur.ff == 1) {
				for (int i = 1; i <= 3; i++) {
					if (cur.ss[0] == cur.ss[i]) continue;
					valid &= (perm[cur.ss[0]] > perm[cur.ss[i]]);
				}
			}
			if (cur.ff == 2) {
				for (int i = 1; i <= 3; i++) {
					if (cur.ss[0] == cur.ss[i]) continue;
					valid &= (perm[cur.ss[0]] < perm[cur.ss[i]]);
				}
			}
			if (cur.ff == 3) {
				int cnt = 0;
				for (int i = 1; i <= 3; i++) {
					if (cur.ss[0] == cur.ss[i]) continue;
					cnt += (perm[cur.ss[0]] < perm[cur.ss[i]]);
				}
				valid &= (cnt == 1);
			}
			if (cur.ff == 4) {
				bool allsmaller = true;
				for (int i = 1; i <= 3; i++) {
					allsmaller &= (perm[cur.ss[i]] < perm[cur.ss[4]]);
				}
				if (allsmaller) {
					for (int i = 1; i <= 3; i++) {
						if (cur.ss[0] == cur.ss[i]) continue;
						valid &= (perm[cur.ss[i]] < perm[cur.ss[0]]);
					}
				} else {
					valid &= (perm[cur.ss[0]] > perm[cur.ss[4]]);
					for (int i = 1; i <= 3; i++) {
						if (cur.ss[0] == cur.ss[i]) continue;
						valid &= (perm[cur.ss[i]] < perm[cur.ss[4]] || perm[cur.ss[i]] > perm[cur.ss[0]]);
					}
				}
			}
			if (!valid) break;
		}
		if (valid) {
			// cerr << "FOUND ";
			// for (int &x : perm) cerr << x << ' ';
			// cerr << endl;
			res.pb(perm);
		}
	} while (next_permutation(perm.begin() + 1, perm.end()));
	if (res.empty()) {
		throw runtime_error("cannot find correct permutation?");
	}
	return res;
}
void Answer(vector<int> v) {
	int ans[6];
	for (int i = 1; i <= 6; i++) ans[v[i] - 1] = i;
	answer(ans);
}

int Heaviest(int a, int b, int c = 0) {
	if (c == 0) c = (min(a, b) != 1 ? 1 : max(a, b) != 2 ? 2 : 3);
	int res = getHeaviest(a, b, c);
	clues.pb({1, {res, a, b, c}});
	return res;
}
int Lightest(int a, int b, int c = 0) {
	if (c == 0) c = (min(a, b) != 1 ? 1 : max(a, b) != 2 ? 2 : 3);
	int res = getLightest(a, b, c);
	clues.pb({2, {res, a, b, c}});
	return res;
}
int Median(int a, int b, int c) {
	int res = getMedian(a, b, c);
	clues.pb({3, {res, a, b, c}});
	return res;
}
int NextLightest(int a, int b, int c, int d) {
	int res = getNextLightest(a, b, c, d);
	clues.pb({4, {res, a, b, c, d}});
	return res;
}
/*
getHeaviest()
getLightest()
getMedian()
getNextLightest()
*/

void orderCoins() {
	clues.clear();
	
	int mini = Lightest(Lightest(1, 2, 3), Lightest(4, 5, 6));
	vector<int> bruhs;
	for (int i = 1; i <= 6; i++) {
		if (i != mini) bruhs.pb(i);
	}
	int maxi = Heaviest(Heaviest(bruhs[0], bruhs[1], bruhs[2]), bruhs[3], bruhs[4]);
	
	vector<int> rem1;
	for (int i = 1; i <= 6; i++) {
		if (i != mini && i != maxi) rem1.pb(i);
	}
	int res1 = Lightest(rem1[0], rem1[1], rem1[2]);
	vector<int> rem2;
	for (int &x : rem1) {
		if (x != res1) rem2.pb(x);
	}
	int res2 = Lightest(rem2[0], rem2[1], rem2[2]);
	int dk1 = -1, dk2 = -1;
	for (int &x : rem2) {
		if (x != res2) {
			if (dk1 == -1) dk1 = x;
			else dk2 = x;
		}
	}
	Median(mini, res1, res2);
	Median(mini, dk1, dk2);

	// for (pair<int, vector<int>> &cur : clues) {
	// 	cerr << "CLUE " << cur.ff << " | ";
	// 	for (int &x : cur.ss) cerr << x << ' ';
	// 	cerr << endl;
	// }

	vector<vector<int>> res = FindAllPossible();
	// cerr << "All possible options:\n";
	// for (vector<int> &cur : res) {
	// 	for (int &x : cur) cerr << ' ';
	// 	cerr << endl;
	// }
	if (res.empty()) throw runtime_error("no options?");
	if (res.size() >= 2) throw runtime_error("more than 1 final option?");
	Answer(res.front());
}
/*
15 edges to consider (know all -> must can sort)

*/

컴파일 시 표준 에러 (stderr) 메시지

scales.cpp: In function 'void init(int)':
scales.cpp:10:15: warning: unused parameter 'T' [-Wunused-parameter]
   10 | void init(int T) {
      |           ~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...