제출 #704220

#제출 시각아이디문제언어결과실행 시간메모리
704220socpiteXylophone (JOI18_xylophone)C++14
100 / 100
168 ms456 KiB
#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;

const int maxn = 5e3+5;

int n;

int A[maxn];
int d[2][maxn];

int gt(int l, int r){
    int mn = n, mx = 1;
    for(int i = l; i <= r; i++){
        mn = min(mn, A[i]);
        mx = max(mx, A[i]);
    }
    return mx - mn;
}

void solve(int N){
    n = N;
    for(int i = 2; i <= n; i++){
        d[0][i] = query(i-1, i);
    }
    for(int i = 3; i <= n; i++){
        d[1][i] = query(i-2, i);
    }
    for(A[1] = 1; A[1] <= n; A[1]++){
        if(A[1] + d[0][2] > n)continue;
        A[2] = A[1] + d[0][2];
        bool chk = 0;
        for(int i = 3; i <= n; i++){
            if(A[i-1]+d[0][i] <= n){
                A[i] = A[i-1]+d[0][i];
                if(gt(i-2, i) == d[1][i])continue;
            }
            if(A[i-1]-d[0][i] >= 1){
                A[i] = A[i-1]-d[0][i];
                if(gt(i-2, i) == d[1][i])continue;
            }
            chk = 1;
            break;
        }
        if(!chk)break;
        if(A[1] - d[0][2] < 1)continue;
        A[2] = A[1] - d[0][2];
        chk = 0;
        for(int i = 3; i <= n; i++){
            if(A[i-1]+d[0][i] <= n){
                A[i] = A[i-1]+d[0][i];
                if(gt(i-2, i) == d[1][i])continue;
            }
            if(A[i-1]-d[0][i] >= 1){
                A[i] = A[i-1]-d[0][i];
                if(gt(i-2, i) == d[1][i])continue;
            }
            chk = 1;
            break;
        }
        if(!chk)break;
    }
    int p1, p2;
    for(int i = 1; i <= n; i++){
        if(A[i] == 1)p1 = i;
        if(A[i] == n)p2 = i;
    }
    if(p1 > p2)for(int i = 1; i <= n; i++)A[i] = n+1-A[i];
	/*for(int i = 1; i <= n; i++){
		//cout << A[i] << " ";
		cout << endl;
	}*/
    for(int i = 1; i <= n; i++){
		answer(i, A[i]);
	}
}

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

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:68:5: warning: 'p2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   68 |     if(p1 > p2)for(int i = 1; i <= n; i++)A[i] = n+1-A[i];
      |     ^~
xylophone.cpp:68:5: warning: 'p1' 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...