답안 #232837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232837 2020-05-18T10:44:43 Z Charis02 Xylophone (JOI18_xylophone) C++14
100 / 100
67 ms 512 KB
#include "xylophone.h"
#include<iostream>

using namespace std;

int A[5001];
bool used[5001];
int NN;

bool is_valid(int x)
{
    return (1 <= x && x<=NN && !used[x]);
}

void solve(int N)
{
    NN=N;
    int low = 1;
    int high = N-1;
    int res = 1;

    while(low <= high)
    {
        int mid = (low+high)/2;

        if(query(mid,N) == N-1)
        {
            res=max(res,mid);
            low=mid+1;
        }
        else
            high=mid-1;
    }

    used[1] = true;
    A[res] = 1;

   // cout << "OOOOO OP " << res << endl << endl;

    for(int i = res-1;i >= 1;i--)
    {
        int dif1 = query(i,i+1);

        if(!is_valid(A[i+1]+dif1))
            A[i] = A[i+1]-dif1;
        else if(!is_valid(A[i+1]-dif1))
            A[i] = A[i+1]+dif1;
        else
        {
            int dif2 = query(i,i+2);

            if(A[i+1] < A[i+2])
            {
                if(dif2 == A[i+2]-A[i+1])
                    A[i] = dif1+A[i+1];
                else if(dif2 > dif1)
                    A[i] = A[i+1]-dif1;
                else
                    A[i] = A[i+1]+dif1;
            }
            else
            {
                if(dif2 == A[i+1]-A[i+2])
                    A[i] = A[i+1]-dif1;
                else if(dif2 > dif1)
                    A[i] = A[i+1]+dif1;
                else
                    A[i] = A[i+1]-dif1;
            }
        }

        used[A[i]] = true;
    }

    for(int i = res+1;i <= N;i++)
    {
        int dif1 = query(i-1,i);

        if(!is_valid(A[i-1]+dif1))
            A[i] = A[i-1]-dif1;
        else if(!is_valid(A[i-1]-dif1))
            A[i] = A[i-1]+dif1;
        else
        {
            int dif2 = query(i-2,i);

            if(A[i-1] < A[i-2])
            {
                if(dif2 == A[i-2]-A[i-1])
                    A[i] = dif1+A[i-1];
                else if(dif2 > dif1)
                    A[i] = A[i-1]-dif1;
                else
                    A[i] = A[i-1]+dif1;
            }
            else
            {
                if(dif2 == A[i-1]-A[i-2])
                    A[i] = A[i-1]-dif1;
                else if(dif2 > dif1)
                    A[i] = A[i-1]+dif1;
                else
                    A[i] = A[i-1]-dif1;
            }
        }

        used[A[i]] = true;
    }

    for(int i = 1;i <= N;i++)
        answer(i,A[i]);

    return;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 256 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 256 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 256 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 9 ms 384 KB Output is correct
18 Correct 12 ms 384 KB Output is correct
19 Correct 15 ms 384 KB Output is correct
20 Correct 17 ms 384 KB Output is correct
21 Correct 14 ms 384 KB Output is correct
22 Correct 19 ms 384 KB Output is correct
23 Correct 14 ms 384 KB Output is correct
24 Correct 14 ms 512 KB Output is correct
25 Correct 14 ms 376 KB Output is correct
26 Correct 19 ms 384 KB Output is correct
27 Correct 17 ms 384 KB Output is correct
28 Correct 19 ms 376 KB Output is correct
29 Correct 13 ms 384 KB Output is correct
30 Correct 19 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 6 ms 256 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 256 KB Output is correct
16 Correct 7 ms 384 KB Output is correct
17 Correct 9 ms 384 KB Output is correct
18 Correct 12 ms 384 KB Output is correct
19 Correct 15 ms 384 KB Output is correct
20 Correct 17 ms 384 KB Output is correct
21 Correct 14 ms 384 KB Output is correct
22 Correct 19 ms 384 KB Output is correct
23 Correct 14 ms 384 KB Output is correct
24 Correct 14 ms 512 KB Output is correct
25 Correct 14 ms 376 KB Output is correct
26 Correct 19 ms 384 KB Output is correct
27 Correct 17 ms 384 KB Output is correct
28 Correct 19 ms 376 KB Output is correct
29 Correct 13 ms 384 KB Output is correct
30 Correct 19 ms 384 KB Output is correct
31 Correct 27 ms 504 KB Output is correct
32 Correct 38 ms 384 KB Output is correct
33 Correct 55 ms 384 KB Output is correct
34 Correct 52 ms 388 KB Output is correct
35 Correct 60 ms 512 KB Output is correct
36 Correct 49 ms 384 KB Output is correct
37 Correct 42 ms 384 KB Output is correct
38 Correct 55 ms 384 KB Output is correct
39 Correct 56 ms 508 KB Output is correct
40 Correct 55 ms 384 KB Output is correct
41 Correct 58 ms 384 KB Output is correct
42 Correct 52 ms 384 KB Output is correct
43 Correct 37 ms 392 KB Output is correct
44 Correct 54 ms 384 KB Output is correct
45 Correct 64 ms 384 KB Output is correct
46 Correct 67 ms 392 KB Output is correct
47 Correct 66 ms 376 KB Output is correct
48 Correct 66 ms 384 KB Output is correct
49 Correct 66 ms 384 KB Output is correct
50 Correct 63 ms 384 KB Output is correct
51 Correct 62 ms 384 KB Output is correct
52 Correct 55 ms 392 KB Output is correct
53 Correct 62 ms 384 KB Output is correct
54 Correct 56 ms 392 KB Output is correct
55 Correct 66 ms 376 KB Output is correct
56 Correct 55 ms 504 KB Output is correct
57 Correct 62 ms 384 KB Output is correct
58 Correct 61 ms 384 KB Output is correct
59 Correct 61 ms 480 KB Output is correct
60 Correct 62 ms 384 KB Output is correct