Submission #725740

#TimeUsernameProblemLanguageResultExecution timeMemory
725740becaido저울 (IOI15_scales)C++17
45.45 / 100
1 ms308 KiB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifndef WAIMAI
#include "scales.h"
#endif

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout (T t, U...u) {cout << t << (sizeof... (u) ? ", " : ""), dout (u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

#ifdef WAIMAI
#define _MAXN 6
#define _MAX_ANSWER_CALLS 1

static int _realC[_MAXN];
static int _ind[_MAXN];
static int _numQueries;
static int _numAnswerCalls;

static int _getNumberOfTests() {
    int T;
    cin >> T;
    return T;
}

static void _initNewTest() {
    int i, ret;

    for (i = 0; i < _MAXN; i++) {
        cin >> _realC[i];
        _realC[i]--;
        _ind[_realC[i]] = i;
    }

    _numQueries = 0;
    _numAnswerCalls = 0;
}

void answer(int W[]) {
    int i;
    _numAnswerCalls++;
    if (_numAnswerCalls > _MAX_ANSWER_CALLS)
        return;
    for (i = 0; i < 6; i++) cout << W[i] << ' ';
    cout << "\n" << _numQueries << '\n';
}

static void _checkQuery(int A, int B, int C, int D) {
    if (D == -1) {
        if (A < 1 || A > 6 || B < 1 || B > 6 || C < 1 || C > 6)
            assert(0);
        if (A == B || B == C || A == C)
            assert(0);
    }
    else {
        if (A < 1 || A > 6 || B < 1 || B > 6 || C < 1 || C > 6 || D < 1 || D > 6)
            assert(0);
        if (A == B || A == C || A == D || B == C || B == D || C == D)
            assert(0);
    }
}

int getMedian(int A, int B, int C) {
    _numQueries++;
    _checkQuery(A, B, C, -1);

    A--; B--; C--;

    if (_ind[B] < _ind[A] && _ind[A] < _ind[C])
        return A + 1;

    if (_ind[C] < _ind[A] && _ind[A] < _ind[B])
        return A + 1;

    if (_ind[A] < _ind[B] && _ind[B] < _ind[C])
        return B + 1;

    if (_ind[C] < _ind[B] && _ind[B] < _ind[A])
        return B + 1;

    return C + 1;
}

int getHeaviest(int A, int B, int C) {
    _numQueries++;
    _checkQuery(A, B, C, -1);

    A--; B--; C--;

    if (_ind[A] > _ind[B] && _ind[A] > _ind[C])
        return A + 1;

    if (_ind[B] > _ind[A] && _ind[B] > _ind[C])
        return B + 1;

    return C + 1;
}

int getLightest(int A, int B, int C) {
    _numQueries++;
    _checkQuery(A, B, C, -1);

    A--; B--; C--;

    if (_ind[A] < _ind[B] && _ind[A] < _ind[C])
        return A + 1;

    if (_ind[B] < _ind[A] && _ind[B] < _ind[C])
        return B + 1;

    return C + 1;
}

int getNextLightest(int A, int B, int C, int D) {
    int allLess = 1;

    _numQueries++;
    _checkQuery(A, B, C, D);

    A--; B--; C--; D--;

    if (_ind[A] > _ind[D] || _ind[B] > _ind[D] || _ind[C] > _ind[D])
        allLess = 0;

    if (allLess == 1) {
        if (_ind[A] < _ind[B] && _ind[A] < _ind[C])
            return A + 1;

        if (_ind[B] < _ind[A] && _ind[B] < _ind[C])
            return B + 1;

        return C + 1;
    }

    if (_ind[A] > _ind[D]) {
        if ((_ind[A] < _ind[B] || _ind[B] < _ind[D]) && (_ind[A] < _ind[C] || _ind[C] < _ind[D]))
            return A + 1;
    }

    if (_ind[B] > _ind[D]) {
        if ((_ind[B] < _ind[A] || _ind[A] < _ind[D]) && (_ind[B] < _ind[C] || _ind[C] < _ind[D]))
            return B + 1;
    }

    return C + 1;
}
#endif

void init(int T) {}

void orderCoins() {
    int a[3], b[3];

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

    b[0] = getLightest(4, 5, 6);
    b[2] = getHeaviest(4, 5, 6);
    b[1] = 15 - b[0] - b[2];

    int ans[6];
    for (int i = 0, ai = 0, bi = 0; i < 6; i++) {
        if (ai == 3) ans[i] = b[bi++];
        else if (bi == 3) ans[i] = a[ai++];
        else {
            if (ai == 2 && bi == 2) {
                ans[i] = getMedian(a[0], a[ai], b[bi]);
                (ans[i] == a[ai] ? ai : bi)++;
            } else if (ai == 2) {
                ans[i] = getLightest(a[ai], b[bi], b[2]);
                (ans[i] == a[ai] ? ai : bi)++;
            } else {
                ans[i] = getLightest(a[ai], b[bi], a[2]);
                (ans[i] == a[ai] ? ai : bi)++;
            }
        }
    }
    answer(ans);
}

/*
in1
1
3 4 6 2 1 5
out1
3 4 6 2 1 5
*/

#ifdef WAIMAI
int main() {
    int T, i;

    T = _getNumberOfTests();
    init(T);

    for (i = 1; i <= T; i++) {
        _initNewTest();
        orderCoins();
    }

    return 0;
}
#endif

Compilation message (stderr)

scales.cpp: In function 'void init(int)':
scales.cpp:164:15: warning: unused parameter 'T' [-Wunused-parameter]
  164 | void init(int T) {}
      |           ~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...