Submission #138804

#TimeUsernameProblemLanguageResultExecution timeMemory
138804TalantScales (IOI15_scales)C++14
38.70 / 100
3 ms376 KiB
#include "scales.h"
//#include "grader.cpp"

#include <bits/stdc++.h>

#define sc second
#define fr first
#define mk make_pair
#define pb push_back

using namespace std;

const int N = (1e6 + 5);
const int inf = (1e9 + 7);


int t;
int a[7];
int f = 0;
int o,cur;
void init(int T) {
      t = T;
}

void orderCoins() {
      f = 0;
      o = cur = 0;
      for (int i = 0; i < 6; i ++)
            a[i] = 0;

      a[2] = getHeaviest(1,2,3);
      a[1] = getMedian(1,2,3);
      a[0] = 6 - (a[2] + a[1]);

      a[5] = getHeaviest(4,5,6);
      a[4] = getMedian(4,5,6);
      a[3] = 15 - a[5] - a[4];

      ///1

      o = getNextLightest(a[1],a[2],a[0],a[3]);
      cur = a[3];
      if (o == a[0]) {
            int oo = getLightest(a[0],a[1],cur);
            if (oo == cur) {
                  for (int i = 2; i >= 0; i --)
                        a[i + 1] = a[i];
                  a[0] = cur;
            }
            else {
                  f = 1;
            }
      }
      else {
            for (int i = 2; i >= 1; i --) {
                  a[i + 1] = a[i];
                  if (a[i] == o) {
                        a[i] = cur;
                        break;
                  }
            }
      }

      ///2

      if (!f) {
            o = getNextLightest(a[1],a[2],a[3],a[4]);
            cur = a[4];
            if (o == a[1]) {
                  int oo = getLightest(a[1],a[2],cur);
                  if (oo == cur) {
                        for (int i = 3; i >= 1; i --)
                              a[i + 1] = a[i];
                        a[1] = cur;
                  }
                  else {
                        f = 1;
                  }
            }
            else {
                  for (int i = 3; i >= 2; i --) {
                        a[i + 1] = a[i];
                        if (a[i] == o) {
                              a[i] = cur;
                              break;
                        }
                  }
            }
      }
      ///3

      if (!f) {
            o = getNextLightest(a[4],a[2],a[3],a[5]);
            cur = a[5];

            if (o == a[2]) {
                  int oo = getLightest(a[2],a[3],cur);
                  if (oo == cur) {
                        for (int i = 4; i >= 2; i --)
                              a[i + 1] = a[i];
                        a[2] = cur;
                  }
                  else {
                        f = 1;
                  }
            }
            else {
                  for (int i = 4; i >= 3; i --) {
                        a[i + 1] = a[i];
                        if (a[i] == o) {
                              a[i] = cur;
                              break;
                        }
                  }
            }
      }
      answer(a);
}
#Verdict Execution timeMemoryGrader output
Fetching results...