Submission #800714

#TimeUsernameProblemLanguageResultExecution timeMemory
800714firewaterScales (IOI15_scales)C++14
Compilation error
0 ms0 KiB
#include "scales.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;















#define _MAXN 6
#define _MAX_ANSWER_CALLS 1
static int _realC[_MAXN];
static int _ind[_MAXN];
static int _numQueries;
static int _numAnswerCalls;
static FILE * _f;
static FILE * _of;

static int _getNumberOfTests() {
    int T, ret;

    _f = fopen("scales.in", "r");
    _of = fopen("scales.out", "w");

    ret = fscanf(_f, "%d", &T);
    assert(ret == 1);
    return T;
}

static void _initNewTest() {    
    int i, ret;

    for (i = 0; i < _MAXN; i++) {
        ret = fscanf(_f, "%d", &_realC[i]);
        assert(ret == 1);
        _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++)
        fprintf(_of, "%d ", W[i]);
    fprintf(_of, "\n%d\n", _numQueries); 
}

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;
}
















// int getHeaviest(int A, int B, int C) 
// int getMedian(int A, int B, int C) 
// int getLightest(int A, int B, int C) 
// int getNextLightest(int A, int B, int C, int D) 
#define N 100
int w,x,y,a[N],p[N],sav,ans[6];
void init(int T) {
    /* ... */
}
void orderCoins() {
    /* ... */
    x=0;y=1;
    ans[x]=y;
    for(int i=1;i<=6;++i)p[i]=0;
    p[y]=1;


    for(int i=1;i<=5;++i){
        w=0;
        for(int j=1;j<=6;++j)
            if(!p[j])a[++w]=j;
        sav=a[1];
        for(int j=2;j<=w;++j)
            sav=getMedian(ans[0],sav,a[j]);
        ans[i]=sav;
        p[sav]=1;
    }
    answer(ans);
}















int main() {

    int T, i;

    T = _getNumberOfTests();
    init(T);

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

Compilation message (stderr)

scales.cpp: In function 'void init(int)':
scales.cpp:193:15: warning: unused parameter 'T' [-Wunused-parameter]
  193 | void init(int T) {
      |           ~~~~^
/usr/bin/ld: /tmp/ccuLZ4sd.o: in function `answer':
scales.cpp:(.text+0x0): multiple definition of `answer'; /tmp/ccrGnYJe.o:grader.c:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccuLZ4sd.o: in function `getMedian':
scales.cpp:(.text+0x80): multiple definition of `getMedian'; /tmp/ccrGnYJe.o:grader.c:(.text+0x90): first defined here
/usr/bin/ld: /tmp/ccuLZ4sd.o: in function `getHeaviest':
scales.cpp:(.text+0x170): multiple definition of `getHeaviest'; /tmp/ccrGnYJe.o:grader.c:(.text+0x180): first defined here
/usr/bin/ld: /tmp/ccuLZ4sd.o: in function `getLightest':
scales.cpp:(.text+0x230): multiple definition of `getLightest'; /tmp/ccrGnYJe.o:grader.c:(.text+0x240): first defined here
/usr/bin/ld: /tmp/ccuLZ4sd.o: in function `getNextLightest':
scales.cpp:(.text+0x2f0): multiple definition of `getNextLightest'; /tmp/ccrGnYJe.o:grader.c:(.text+0x300): first defined here
/usr/bin/ld: /tmp/ccuLZ4sd.o: in function `main':
scales.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccrGnYJe.o:grader.c:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status