제출 #788023

#제출 시각아이디문제언어결과실행 시간메모리
788023ymm저울 (IOI15_scales)C++17
100 / 100
36 ms424 KiB
#include "scales.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (int x = (l); x < (r); ++x)
using namespace std;

typedef array<int, 6> perm;

int whichval3(int *v, int x) {
	return (v[1] == x) + 2*(v[2] == x);
}

tuple<int,int,int> srt(const perm &p, int a, int b, int c) {
	if (p[a] > p[b]) swap(a, b);
	if (p[b] > p[c]) swap(b, c);
	if (p[a] > p[b]) swap(a, b);
	return {a, b, c};
}
int mn(const perm &p, int *v) {
	auto [x, y, z] = srt(p, v[0], v[1], v[2]);
	return whichval3(v, x);
}
int mx(const perm &p, int *v) {
	auto [x, y, z] = srt(p, v[0], v[1], v[2]);
	return whichval3(v, z);
}
int med(const perm &p, int *v) {
	auto [x, y, z] = srt(p, v[0], v[1], v[2]);
	return whichval3(v, y);
}
int nxt(const perm &p, int *v) {
	auto [x, y, z] = srt(p, v[0], v[1], v[2]);
	if (p[v[3]] < p[x]) return whichval3(v, x);
	if (p[v[3]] < p[y]) return whichval3(v, y);
	if (p[v[3]] < p[z]) return whichval3(v, z);
	return whichval3(v, x);
}

vector<vector<int>> sel3;
vector<vector<int>> sel4;
vector<perm> perms;

template<int (*f)(int, int, int)> int f3(int *v) { return f(v[0]+1, v[1]+1, v[2]+1)-1; }
template<int (*f)(int, int, int, int)> int f4(int *v) { return f(v[0]+1, v[1]+1, v[2]+1, v[3]+1)-1; }

int (*f2q(int (*f)(const perm &, int *)))(int *) {
	if (f == mn) return f3<getLightest>;
	if (f == mx) return f3<getHeaviest>;
	if (f == med) return f3<getMedian>;
	if (f == nxt) return f4<getNextLightest>;
	return NULL;
}

perm solve(const vector<perm> &ps)
{
	if (ps.size() == 1)
		return ps[0];
	tuple<int, array<vector<perm>, 3>, int (*)(int *), int *> ch;
	get<0>(ch) = INT_MAX;
	for (auto f : {nxt, med, mn, mx}) {
		auto &selx = f == nxt? sel4: sel3;
		for (auto &sel : selx) {
			array<vector<perm>, 3> vec;
			for (const auto &p : ps)
				vec[f(p, sel.data())].push_back(p);
			int x = max({vec[0].size(), vec[1].size(), vec[2].size()});
			if (x < get<0>(ch))
				ch = {x, vec, f2q(f), sel.data()};
		}
	}
	auto [_, chvec, chf, chin] = ch;
	int x = chf(chin);
	int i = whichval3(chin, x);
	return solve(chvec[i]);
}

void init(int T) {
	Loop (i,0,6) Loop (j,i+1,6) Loop (k,j+1,6)
		sel3.push_back({i, j, k});
	Loop (d,0,6) Loop (i,0,6) Loop (j,i+1,6) Loop (k,j+1,6) {
		if (i != d && j != d && k != d)
			sel4.push_back({i, j, k, d});
	}
	perm p = {0, 1, 2, 3, 4, 5};
	do {
		perms.push_back(p);
	} while (next_permutation(p.begin(), p.end()));
}

void orderCoins() {
	auto ans = solve(perms);
	int w[6];
	Loop (i,0,6)
		w[ans[i]] = i+1;
	answer(w);

}

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

scales.cpp: In function 'perm solve(const std::vector<std::array<int, 6> >&)':
scales.cpp:65:15: warning: conversion from 'long unsigned int' to 'int' may change value [-Wconversion]
   65 |    int x = max({vec[0].size(), vec[1].size(), vec[2].size()});
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scales.cpp: In function 'void init(int)':
scales.cpp:76:15: warning: unused parameter 'T' [-Wunused-parameter]
   76 | void init(int T) {
      |           ~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...