제출 #1358627

#제출 시각아이디문제언어결과실행 시간메모리
1358627haithamcoderScales (IOI15_scales)C++20
38.70 / 100
0 ms344 KiB
#include "scales.h"

#include<bits/stdc++.h>
using namespace std;
typedef int ll;

void init(int T) {
    /* ... */
}

ll other(ll a, ll b) {
    if (a > b) swap(a, b);

    ll add = (a > 3) * 3;
    if (a > 3) a -= 3, b -= 3;

    if (a == 1 && b == 2) return 3 + add;
    if (a == 1 && b == 3) return 2 + add;
    return 1 + add;
}

void orderCoins() {
    int w[] = {1, 2, 3, 4, 5, 6};

    w[0] = getLightest(1, 2, 3), w[2] = getHeaviest(1, 2, 3);
    w[1] = other(w[0], w[2]);
    
    w[3] = getLightest(4, 5, 6);
    w[5] = getHeaviest(4, 5, 6);
    w[4] = other(w[3], w[5]);

    vector<ll> a = {w[0], w[1], w[2]};
    vector<ll> b = {w[3], w[4], w[5]};


    auto insert = [&](ll x, ll p) {
        a.push_back(0);
        for (ll i = a.size() - 1; i > p; i--) {
            a[i] = a[i - 1];
        }
        a[p] = x;
    };

    while (b.size()) {
        auto x = b[0];

        ll s = a.size();

        bool p = max(max(a[s - 3], a[s - 2]), a[s - 1]) > 3;

        auto res = getNextLightest(a[s - 3], a[s - 2], a[s - 1], x);
        if (res == a[s - 3]) {
            if (p) insert(x, s);
            else {
                if (getLightest(a[s - 3], a[s - 2], x) == x) insert(x, s - 3);
                else insert(x, s);
            }
        }
        else if (res == a[s - 2]) insert(x, s - 2);
        else if (res == a[s - 1]) insert(x, s - 1);

        b.erase(b.begin());
    }

    ll res[6];
    for (ll i = 0; i < 6; i++) res[i] = a[i];

    answer(res);
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…