제출 #374653

#제출 시각아이디문제언어결과실행 시간메모리
374653idk321저울 (IOI15_scales)C++11
컴파일 에러
0 ms0 KiB
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "scales.h"

#define _MAXN 6
#define _MAX_ANSWER_CALLS 1
#include <bits/stdc++.h>
using namespace std;

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(stdin, "%d", &T);
    assert(ret == 1);
    return T;
}

static void _initNewTest() {
    int i, ret;

    for (i = 0; i < _MAXN; i++) {
        ret = fscanf(stdin, "%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(stdout, "%d ", W[i]);
    fprintf(stdout, "\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 main() {

    int T, i;

    T = _getNumberOfTests();
    init(T);

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

    return 0;
}

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

/tmp/ccb051PA.o: In function `answer':
scales.cpp:(.text+0x100): multiple definition of `answer'
/tmp/cc0fJts6.o:grader.c:(.text+0x100): first defined here
/tmp/ccb051PA.o: In function `getMedian':
scales.cpp:(.text+0x180): multiple definition of `getMedian'
/tmp/cc0fJts6.o:grader.c:(.text+0x190): first defined here
/tmp/ccb051PA.o: In function `getHeaviest':
scales.cpp:(.text+0x210): multiple definition of `getHeaviest'
/tmp/cc0fJts6.o:grader.c:(.text+0x220): first defined here
/tmp/ccb051PA.o: In function `getLightest':
scales.cpp:(.text+0x280): multiple definition of `getLightest'
/tmp/cc0fJts6.o:grader.c:(.text+0x290): first defined here
/tmp/ccb051PA.o: In function `getNextLightest':
scales.cpp:(.text+0x2f0): multiple definition of `getNextLightest'
/tmp/cc0fJts6.o:grader.c:(.text+0x300): first defined here
/tmp/ccb051PA.o: In function `main':
scales.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc0fJts6.o:grader.c:(.text.startup+0x0): first defined here
/tmp/cc0fJts6.o: In function `main':
grader.c:(.text.startup+0x79): undefined reference to `init'
grader.c:(.text.startup+0xf2): undefined reference to `orderCoins'
/tmp/ccb051PA.o: In function `main':
scales.cpp:(.text.startup+0x70): undefined reference to `init'
scales.cpp:(.text.startup+0xe2): undefined reference to `orderCoins'
collect2: error: ld returned 1 exit status