# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
590385 | AlperenT | Scales (IOI15_scales) | C++17 | 678 ms | 344 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 0;
}
};
vector<Rule> currules;
bool finish;
pair<int, int> findcnt(){
int ans[3] = {};
vector<int> v;
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()));
return {*max_element(ans, ans + 3), ans[0] + ans[1] + ans[2]};
}
void orderCoins(){
currules.clear();;
vector<pair<int, 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}});
int x = findcnt().first;
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}});
int x = findcnt().first;
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;
vector<int> vec;
for(int i = 0; i < 3; i++){
rule.x = rule.param[i];
currules.push_back(rule);
if(findcnt().first == 1 && findcnt().second == 1) vec.push_back(i);
currules.pop_back();
}
if(vec.size() == 1){
rule.x = rule.param[vec[0]];
currules.push_back(rule);
break;
}
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... |