제출 #502568

#제출 시각아이디문제언어결과실행 시간메모리
502568fabijan_cikacXylophone (JOI18_xylophone)C++17
100 / 100
116 ms1564 KiB
#include <bits/stdc++.h>
#include "xylophone.h"

using namespace std;

void solve(int N){
    map<int, map<int, int> > m; vector<pair<int, int> > v;
    int a[15000]; bool b = true;
    int sol[15000]; m[0][1] = query(1, 2);
    for (int i = 2; i < N; ++i){
        m[i - 2][i] = query(i - 1, i + 1);
        m[i - 1][i] = query(i, i + 1);
    }
    //a[0] < a[1]
    a[0] = 0; a[1] = m[0][1];
    for (int i = 2; i < N; ++i){
        bool c = false;
        for (int j = -1; j <= 1; ++j){
            if (j == 0) continue;
            a[i] = a[i - 1] + j * m[i - 1][i];
            if (max(a[i - 2], max(a[i - 1], a[i])) - min(a[i - 2], min(a[i - 1], a[i])) == m[i - 2][i]){
                c = true; break;
            }
        }
        if (!c){
            b = false; break;
        }
    }
    for (int i = 0; i < N; ++i)
        v.push_back({a[i], i});
    sort(v.begin(), v.end()); int x, y;
    for (int i = 0; i < N; ++i){
        sol[v[i].second] = i + 1;
        if (i + 1 == 1) x = v[i].second;
        if (i + 1 == N) y = v[i].second;
    }
    if (!b || x > y){
       a[0] = 0; a[1] = -m[0][1];
        for (int i = 2; i < N; ++i){
            for (int j = -1; j <= 1; ++j){
                if (j == 0) continue;
                a[i] = a[i - 1] + j * m[i - 1][i];
                if (max(a[i - 2], max(a[i - 1], a[i])) - min(a[i - 2], min(a[i - 1], a[i])) == m[i - 2][i])
                    break;
            }
        }
        v.clear();
        for (int i = 0; i < N; ++i)
            v.push_back({a[i], i});
        sort(v.begin(), v.end());
        for (int i = 0; i < N; ++i)
            sol[v[i].second] = i + 1;
    }
    for (int i = 0; i < N; ++i)
        answer(i + 1, sol[i]);

    return;
}

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

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:37:17: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |     if (!b || x > y){
      |               ~~^~~
xylophone.cpp:37:17: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...