# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
590343 | AlperenT | Scales (IOI15_scales) | C++17 | 711 ms | 420 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "scales.h"
using namespace std;
const int INF = 1e8 + 5;
void init(int T) {
/* ... */
}
struct Rule{
int rt, x;
vector<int> param;
bool operator < (const Rule &sc) const{
return false;
}
};
vector<Rule> currules;
bool finish;
long double findcnt(){
int ans[3] = {};
vector<int> v;
// if(finish) v = {5, 4, 3, 2, 1, 0};
// else v = {0, 1, 2, 3, 4, 5};
v = {0, 1, 2, 3, 4, 5};
do{
bool flag = true;
for(int i = 0; i < (int)currules.size() - 1; i++){
if(!flag) break;
auto rule = currules[i];
if(rule.rt == 1){
int a = rule.param[0], b = rule.param[1], c = rule.param[2];
if(min({v[a], v[b], v[c]}) == v[rule.x]) continue;
else flag = false;
}
else if(rule.rt == 2){
int a = rule.param[0], b = rule.param[1], c = rule.param[2];
if(min({v[a], v[b], v[c]}) != v[rule.x] && max({v[a], v[b], v[c]}) != v[rule.x]) continue;
else flag = false;
}
else if(rule.rt == 3){
int a = rule.param[0], b = rule.param[1], c = rule.param[2];
if(max({v[a], v[b], v[c]}) == v[rule.x]) continue;
else flag = false;
}
else if(rule.rt == 4){
int a = rule.param[0], b = rule.param[1], c = rule.param[2], d = rule.param[3];
vector<int> v2;
if(v[a] > v[d]) v2.push_back(a);
if(v[b] > v[d]) v2.push_back(b);
if(v[c] > v[d]) v2.push_back(c);
if(v2.empty()){
if(min({v[a], v[b], v[c]}) == v[rule.x]) continue;
else flag = false;
}
else{
int mn = INF;
for(auto x : v2) mn = min(mn, v[x]);
if(v[rule.x] == mn) continue;
else flag = false;
}
}
}
if(flag){
Rule rule = currules[currules.size() - 1];
for(int i = 0; i < 3; i++){
rule.x = rule.param[i];
bool flag2 = true;
if(rule.rt == 1){
int a = rule.param[0], b = rule.param[1], c = rule.param[2];
if(min({v[a], v[b], v[c]}) == v[rule.x]) goto skip;
else flag2 = false;
}
else if(rule.rt == 2){
int a = rule.param[0], b = rule.param[1], c = rule.param[2];
if(min({v[a], v[b], v[c]}) != v[rule.x] && max({v[a], v[b], v[c]}) != v[rule.x]) goto skip;
else flag2 = false;
}
else if(rule.rt == 3){
int a = rule.param[0], b = rule.param[1], c = rule.param[2];
if(max({v[a], v[b], v[c]}) == v[rule.x]) goto skip;
else flag2 = false;
}
else if(rule.rt == 4){
int a = rule.param[0], b = rule.param[1], c = rule.param[2], d = rule.param[3];
vector<int> v2;
if(v[a] > v[d]) v2.push_back(a);
if(v[b] > v[d]) v2.push_back(b);
if(v[c] > v[d]) v2.push_back(c);
if(v2.empty()){
if(min({v[a], v[b], v[c]}) == v[rule.x]) goto skip;
else flag2 = false;
}
else{
int mn = INF;
for(auto x : v2) mn = min(mn, v[x]);
if(v[rule.x] == mn) goto skip;
else flag2 = false;
}
}
skip:
if(flag2) ans[i]++;
}
}
}while(next_permutation(v.begin(), v.end()));
int sum = 0, cnt = 0;
for(int i = 0; i < 3; i++) if(ans[i] != 0) sum += ans[i], cnt++;
// if(finish) cout << ans[0] << " " << ans[1] << " " << ans[2] << "\n";
return *max_element(ans, ans + 3);
return cnt == 0 ? INF : (long double)sum / cnt;
}
void orderCoins(){
currules.clear();;
vector<pair<long double, Rule>> posrules;
while(true){
posrules.clear();
for(int t = 1; t <= 3; t++){
for(int a = 0; a < 6; a++){
for(int b = a + 1; b < 6; b++){
for(int c = b + 1; c < 6; c++){
currules.push_back({t, -1, {a, b, c}});
long double x = findcnt();
currules.pop_back();
posrules.push_back({x, {t, -1, {a, b, c}}});
}
}
}
}
for(int a = 0; a < 6; a++){
for(int b = a + 1; b < 6; b++){
for(int c = b + 1; c < 6; c++){
for(int d = 0; d < 6; d++){
if(a != d && b != d && c != d){
currules.push_back({4, -1, {a, b, c, d}});
long double x = findcnt();
currules.pop_back();
posrules.push_back({x, {4, -1, {a, b, c, d}}});
}
}
}
}
}
auto p = *min_element(posrules.begin(), posrules.end());
if(p.first == 1){
auto rule = p.second;
if(rule.rt == 1){
int x = getLightest(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1);
currules.push_back({1, x - 1, {rule.param[0], rule.param[1], rule.param[2]}});
}
else if(rule.rt == 2){
int x = getMedian(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1);
currules.push_back({2, x - 1, {rule.param[0], rule.param[1], rule.param[2]}});
}
else if(rule.rt == 3){
int x = getHeaviest(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1);
currules.push_back({3, x - 1, {rule.param[0], rule.param[1], rule.param[2]}});
}
else if(rule.rt == 4){
int x = getNextLightest(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1, rule.param[3] + 1);
currules.push_back({4, x - 1, {rule.param[0], rule.param[1], rule.param[2], rule.param[3]}});
}
break;
}
else{
auto rule = p.second;
if(rule.rt == 1){
int x = getLightest(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1);
currules.push_back({1, x - 1, {rule.param[0], rule.param[1], rule.param[2]}});
}
else if(rule.rt == 2){
int x = getMedian(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1);
currules.push_back({2, x - 1, {rule.param[0], rule.param[1], rule.param[2]}});
}
else if(rule.rt == 3){
int x = getHeaviest(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1);
currules.push_back({3, x - 1, {rule.param[0], rule.param[1], rule.param[2]}});
}
else if(rule.rt == 4){
int x = getNextLightest(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1, rule.param[3] + 1);
currules.push_back({4, x - 1, {rule.param[0], rule.param[1], rule.param[2], rule.param[3]}});
}
}
}
vector<int> v = {0, 1, 2, 3, 4, 5};
do{
bool flag = true;
for(auto rule : currules){
if(!flag) break;
if(rule.rt == 1){
int a = rule.param[0], b = rule.param[1], c = rule.param[2];
if(min({v[a], v[b], v[c]}) == v[rule.x]) continue;
else flag = false;
}
else if(rule.rt == 2){
int a = rule.param[0], b = rule.param[1], c = rule.param[2];
if(min({v[a], v[b], v[c]}) != v[rule.x] && max({v[a], v[b], v[c]}) != v[rule.x]) continue;
else flag = false;
}
else if(rule.rt == 3){
int a = rule.param[0], b = rule.param[1], c = rule.param[2];
if(max({v[a], v[b], v[c]}) == v[rule.x]) continue;
else flag = false;
}
else if(rule.rt == 4){
int a = rule.param[0], b = rule.param[1], c = rule.param[2], d = rule.param[3];
vector<int> v2;
if(v[a] > v[d]) v2.push_back(a);
if(v[b] > v[d]) v2.push_back(b);
if(v[c] > v[d]) v2.push_back(c);
if(v2.empty()){
if(min({v[a], v[b], v[c]}) == v[rule.x]) continue;
else flag = false;
}
else{
int mn = INF;
for(auto x : v2) mn = min(mn, v[x]);
if(v[rule.x] == mn) continue;
else flag = false;
}
}
}
if(flag){
vector<pair<int, int>> ansv;
for(int i = 0; i < 6; i++) ansv.push_back({v[i], i + 1});
sort(ansv.begin(), ansv.end());
int arr[6];
for(int i = 0; i < 6; i++) arr[i] = ansv[i].second;
answer(arr);
return;
}
}while(next_permutation(v.begin(), v.end()));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |