제출 #502548

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

using namespace std;

void solve(int N){
    int m[10010][10010]; vector<pair<int, int> > v;
    int a[15000]; bool b = true;
    int sol[15000]; m[0][1] = query(0, 1);
    for (int i = 2; i < N; ++i){
        m[i - 2][i] = query(i - 2, i);
        m[i - 1][i] = query(i - 1, i);
    }
    //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;
    }
    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]; b = true;
        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;
        }
        v.clear();
        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;
        }
    }
    for (int i = 0; i < N; ++i)
        answer(i + 1, sol[i]);

    return;
}

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

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:51:39: warning: variable 'x' set but not used [-Wunused-but-set-variable]
   51 |         sort(v.begin(), v.end()); int x, y;
      |                                       ^
xylophone.cpp:51:42: warning: variable 'y' set but not used [-Wunused-but-set-variable]
   51 |         sort(v.begin(), v.end()); int x, y;
      |                                          ^
xylophone.cpp:35:17: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |     if (!b || x > y){
      |               ~~^~~
xylophone.cpp:35: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...