답안 #851410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851410 2023-09-19T17:51:02 Z Andrei Xylophone (JOI18_xylophone) C++17
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>

#include "xylophone.h"

using namespace std;

static int A[5005];

int query(int s,int t);
void answer(int i,int v);

void solve(int n)
{
    if(n==2)
    {
        answer(1,1);
        answer(2,2);
        return;
    }

    int p1;
    for(int i=n-1; i>=1; i--)
    {
        if(query(i,n)==n-1)
        {
            p1=i;
            break;
        }
    }

    answer(p1,1);
    A[p1]=1;

    if(p1==n-1)
    {
        answer(n,n);
        A[n]=n;
    }
    else
    {
        int j=p1;
        int last1=query(p1,p1+1);

        answer(p1+1,1+last1);
        A[p1+1]=1+last1;

        bool last2=0;
        for(int i=p1+2; i<=n; i++)
        {
            int v=query(j,i);
            if(v==last1)
            {
                j=i-1;
                last1=query(j,i);
                if(last2==0)
                {
                    A[i]=A[i-1]-last1;
                    answer(i,A[i]);
                    last2=1;
                }
                else
                {
                    A[i]=A[i-1]+last1;
                    answer(i,A[i]);
                    last2=0;
                }
            }
            else
            {
                if(last2==0)
                    A[i]=A[i-1]+(v-last1);
                else
                    A[i]=A[i-1]-(v-last1);
                answer(i,A[i]);
                last1=v;
            }
        }
    }

    if(p1>1)
    {
        if(p1==2)
            answer(1,1+query(1,2));
        else
        {
            int j=p1;
            int last1=query(p1-1,p1);

            answer(p1-1,1+last1);
            A[p1-1]=1+last1;

            bool last2=1;
            for(int i=p1-2; i>=1; i--)
            {
                int v=query(i,j);
                if(v==last1)
                {
                    j=i+1;
                    last1=query(i,j);
                    if(last2==0)
                    {
                        A[i]=A[i+1]+last1;
                        answer(i,A[i]);
                        last2=1;
                    }
                    else
                    {
                        A[i]=A[i+1]-last1;
                        answer(i,A[i]);
                        last2=0;
                    }
                }
                else
                {
                    if(last2==0)
                        A[i]=A[i+1]-(v-last1);
                    else
                        A[i]=A[i+1]+(v-last1);
                    answer(i,A[i]);
                    last1=v;
                }
            }
        }
    }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:87:28: warning: 'p1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   87 |             int last1=query(p1-1,p1);
      |                       ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 1 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 1 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 1 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -