제출 #286484

#제출 시각아이디문제언어결과실행 시간메모리
286484Puddlestomps저울 (IOI15_scales)C++17
38.46 / 100
1 ms384 KiB
#include "bits/stdc++.h"

#define TESTING 0
#if TESTING
#include "graderlib.c"
#else
#include "scales.h"
#endif

using namespace std;

/*
bool lessThan(int a, int b, int val, bool lower = false)
{
    if(lower) //val is lower than a and b
    {
        int k = getMedian(a, b, val);
        if(k == a) return true;
        else return false;
    }
    else
    {
        int k = getLightest(a, b, val);
        if(k == a) return true;
        else return false;
    }
}

void swap(int* a, int* b)
{
    if(a == b) return;
    *a = (*a) ^ (*b);
    *b = (*a) ^ (*b);
    *a = (*a) ^ (*b);
}

void sort(int* begin, int* end, int mid = -1, bool less = false)
{
    if(end - begin == 1) return;
    if(end - begin == 2)
    {
        if(lessThan(*begin, *(end - 1), mid, less)) swap(begin, end - 1);
        return;
    }

    int first = *begin, second = *(begin + 1), third = *(begin + 2);
    int mid = getMedian(first, second, third);

    int* m = nullptr;
    if(mid == first) m = begin;
    else if(mid == second) m = begin + 1;
    else m = begin + 2;

    int* back = end - 1;
    swap(m, back);
    --back;
    int* front = begin;

    while(front != back)
    {
        if(*front)
    }

}*/


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

void orderCoins()
{
    set<int> unsorted = {1, 2, 3, 4, 5, 6};
    int W[] = {1, 2, 3, 4, 5, 6};
    sort(W, W + 6);

    int l1 = getLightest(1, 2, 3);
    int l2 = getLightest(6, 4, 5);
    int other = 1;
    if(other == l1 || other == l2) other++;
    if(other == l1 || other == l2) other++;
    int l = getLightest(other, l1, l2);
    unsorted.erase(l);
    //int lind = l - 1;
    W[0] = l;
    //First coin is now sorted
    if(TESTING) cerr << "W[0] = " << l << "\n";

    auto it = unsorted.begin();
    auto it2 = it++;
    auto it3 = it++;
    l1 = getLightest(*it, *it2, *it3);
    it++;
    auto it5 = it++;
    l = getLightest(l1, *it, *it5);
    unsorted.erase(l);
    W[1] = l;
    //second coin sorted
    if(TESTING) cerr << "W[1] = " << l << "\n";

    it = unsorted.begin();
    it2 = it++;
    it3 = it++;
    l1 = getLightest(*it, *it2, *it3);
    auto othern = unsorted.begin();
    if(*othern == l1) othern++;
    it++;
    l2 = getLightest(l1, *othern, *it);
    unsorted.erase(l2);
    W[2] = l2;
    //third coin sorted;
    if(TESTING) cerr << "W[2] = " << l2 << "\n";

    it = unsorted.begin();
    it2 = it++;
    it3 = it++;
    l1 = getLightest(*it, *it2, *it3);
    W[3] = l1;
    if(TESTING) cerr << "W[3] = " << l1 << "\n";

    l1 = getMedian(*it, *it2, *it3);
    W[4] = l1;
    if(TESTING) cerr << "W[4] = " << l1 << "\n";

    l1 = getHeaviest(*it, *it2, *it3);
    W[5] = l1;
    if(TESTING) cerr << "W[5] = " << l1 << "\n";

    answer(W);
}

#if TESTING

int main() {

    int T, i;

    T = _getNumberOfTests();
    init(T);

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

#endif

컴파일 시 표준 에러 (stderr) 메시지

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