답안 #123411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123411 2019-07-01T11:59:56 Z arnold518 Xylophone (JOI18_xylophone) C++14
0 / 100
2 ms 388 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 5000;

int N, A[MAXN+10], Q1[MAXN+10], Q2[MAXN+10], D[MAXN+10], P1[MAXN+10], P2[MAXN+10];

void ans(int* P)
{
    int i, j;
    for(i=1; i<=N; i++) answer(i, P[i]);
}

void solve(int n)
{
    int i, j;

    for(i=1; i<N; i++) Q1[i]=query(i, i+1);
    for(i=1; i+1<N; i++) Q2[i]=query(i, i+2);

    D[1]=1;
    for(i=1; i+1<N; i++)
    {
        int a=Q1[i]+Q1[i+1];
        int b=max(Q1[i], Q1[i+1]);

        if(a==Q2[i]) D[i+1]=D[i];
        else D[i+1]=-D[i];
    }

    P1[1]=P2[1]=0;
    int min1=987654321, min2=987654321;
    for(i=2; i<=N; i++)
    {
        P1[i]=P1[i-1]+D[i-1]*Q1[i-1];
        P2[i]=P2[i-1]-D[i-1]*Q1[i-1];
        min1=min(min1, P1[i]);
        min2=min(min2, P2[i]);
    }

    for(i=1; i<=N; i++) P1[i]+=min1, P2[i]+=min2;

    int a, b;
    for(i=1; i<=N; i++)
    {
        if(P1[i]==1) a=i;
        if(P1[i]==N) b=i;
    }
    if(a<b) ans(P1);
    else ans(P2);
}

Compilation message

xylophone.cpp: In function 'void ans(int*)':
xylophone.cpp:15:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:30:13: warning: unused variable 'b' [-Wunused-variable]
         int b=max(Q1[i], Q1[i+1]);
             ^
xylophone.cpp:21:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
xylophone.cpp:54:5: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if(a<b) ans(P1);
     ^~
xylophone.cpp:54:5: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 388 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 388 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 388 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -