답안 #996024

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996024 2024-06-10T07:24:48 Z toan2602 Xylophone (JOI18_xylophone) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;

int n, p1[5005], p2[5005], a[5005];

bool mark[50005];

void ANSWER(vector<int> &v) {
    for (int i = 0; i < v.size(); i++) ANSWER(i+1,v[i]);
}

void solve(int n) {
    vector<int> ANS;
    int x = query(1, 2);
    for (int i = 3; i <= n; i++) {
        p1[i] = query(i-1, i);
        p2[i] = query(i-2, i);
    }
    a[1] = x;
    a[2] = 0;
    for (int i = 3; i <= n; i++) {
        int val =a[i-1] + p1[i];
        a[i] = val;
        if(max({a[i], a[i-1],a[i-2]}) - min({a[i], a[i-1], a[i-2]}) == p2[i]) a[i] = val;
        else a[i] = a[i-1] - p1[i];

    }
    int mn = n;
    for (int i = 1; i <= n; i++) {
        mn = min(mn, a[i]);
    }
    if(mn > 0) mn = -(mn-1);
    else mn = abs(mn-1);
    bool ac = true;
    int pos1, posn;
    for (int i = 1; i <= n; i++) {
        a[i]+=mn;
        mark[a[i]] = true;
        if(a[i] > n) ac = false;
        if(a[i] == 1) pos1 = i;
        if(a[i] == n) posn = i;
    }
    for (int i = 1; i <= n; i++) if(!mark[i]) ac = false;
    if(pos1 > posn) ac = false;
    if(ac) {
        //ANSWER
        for (int i = 1; i <= n; i++) ANS.push_back(a[i]);
        ANSWER(ANS);
    }
    else {
        a[1] = 0, a[2] = x;
        for (int i = 3; i <= n; i++) {
            int val = a[i-1] + p1[i];
            a[i] = val;
            if(max({a[i], a[i-1],a[i-2]}) - min({a[i], a[i-1], a[i-2]}) == p2[i]) a[i] = val;
            else a[i] = a[i-1] - p1[i];
        }
        int mn = n;
        for (int i = 1; i <= n; i++) {
            mn = min(mn, a[i]);
        }
        if(mn > 0) mn = -(mn-1);
        else mn = abs(mn-1);
        for (int i = 1; i <= n; i++) a[i] += mn;
        for (int i = 1; i <= n; i++) ANS.push_back(a[i]);
        ANSWER(ANS);
    }
}

Compilation message

xylophone.cpp: In function 'void ANSWER(std::vector<int>&)':
xylophone.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for (int i = 0; i < v.size(); i++) ANSWER(i+1,v[i]);
      |                     ~~^~~~~~~~~~
xylophone.cpp:10:48: error: invalid initialization of non-const reference of type 'std::vector<int>&' from an rvalue of type 'int'
   10 |     for (int i = 0; i < v.size(); i++) ANSWER(i+1,v[i]);
      |                                               ~^~
xylophone.cpp:9:26: note: in passing argument 1 of 'void ANSWER(std::vector<int>&)'
    9 | void ANSWER(vector<int> &v) {
      |             ~~~~~~~~~~~~~^