답안 #70868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70868 2018-08-23T14:37:36 Z ASG1065 Xylophone (JOI18_xylophone) C++14
100 / 100
105 ms 720 KB
#include "xylophone.h"
#include <bits/stdc++.h>

static int A[5000];
int pitch[5001];
bool used[5001];
int n;

int binarySearchn()
{
    int lo = 1;
    int hi = n;
    while (1)
    {
        int mid = (hi+lo)/2;
        if (hi == lo) return lo;
        if (query(1,mid) == n-1) hi = mid;
        else lo = mid+1;
    }
    return -1;
}

int binarySearch1()
{
    int lo = 1;
    int hi = n;
    while (1)
    {
        int mid = (hi+lo)/2 + (hi+lo)%2;
        if (hi == lo) return lo;
        if (query(mid, n) == n-1) lo = mid;
        else hi = mid-1;
    }
    return -1;
}

void solve(int N)
{
    n = N;
    std::memset(pitch, 0, sizeof pitch);
    std::memset(used, false, sizeof used);
    int smallest = binarySearch1();
    int biggest = binarySearchn();
    pitch[smallest] = 1;
    pitch[biggest] = n;
    used[1] = true;
    used[n] = true;
    int a = query(smallest, smallest+1);
    pitch[smallest+1] = 1+a;
    used[a+1] = true;
    int b = query(biggest-1, biggest);
    pitch[biggest-1] = n-b;
    used[n-b] = true;
    for (int i = smallest-1; i >=1; --i)
    {
        int diff = query(i, i+1);
        int option1 = pitch[i+1] - diff;
        int option2 = pitch[i+1] + diff;
        if (option1 < 1 || used[option1]) {used[option2] = true; pitch[i] = option2;}
        else if (option2 > n || used[option2]) {used[option1] = true; pitch[i] = option1;}
        else
        {
            int z = query(i, i+2);
            if (std::max(std::max(std::abs(option1-pitch[i+1]), std::abs(pitch[i+1]-pitch[i+2])), std::abs(pitch[i+2]-option1)) == z)
            {
                used[option1] = true;
                pitch[i] = option1;
            }
            else
            {
                used[option2] = true;
                pitch[i] = option2;
            }
        }
    }
    for (int i = biggest+1; i <= n; ++i)
    {
        int diff = query(i-1, i);
        int option1 = pitch[i-1] - diff;
        int option2 = pitch[i-1] + diff;
        if (option1 < 1 || used[option1]) {used[option2] = true; pitch[i] = option2;}
        else if (option2 > n || used[option2]) {used[option1] = true; pitch[i] = option1;}
        else
        {
            int z = query(i-2, i);
            if (std::max(std::max(std::abs(option1-pitch[i-1]), std::abs(pitch[i-1]-pitch[i-2])), std::abs(pitch[i-2]-option1)) == z)
            {
                used[option1] = true;
                pitch[i] = option1;
            }
            else
            {
                used[option2] = true;
                pitch[i] = option2;
            }
        }
    }
    for (int i = smallest+2; i <= biggest-2; ++i)
    {
        int diff = query(i-1, i);
        int option1 = pitch[i-1] - diff;
        int option2 = pitch[i-1] + diff;
        if (option1 < 1 || used[option1]) {used[option2] = true; pitch[i] = option2;}
        else if (option2 > n || used[option2]) {used[option1] = true; pitch[i] = option1;}
        else
        {
            int z = query(i-2, i);
            if (std::max(std::max(std::abs(option1-pitch[i-1]), std::abs(pitch[i-1]-pitch[i-2])), std::abs(pitch[i-2]-option1)) == z)
            {
                used[option1] = true;
                pitch[i] = option1;
            }
            else
            {
                used[option2] = true;
                pitch[i] = option2;
            }
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        answer(i, pitch[i]);
    }
}

Compilation message

xylophone.cpp:4:12: warning: 'A' defined but not used [-Wunused-variable]
 static int A[5000];
            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 4 ms 388 KB Output is correct
4 Correct 3 ms 464 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 7 ms 648 KB Output is correct
8 Correct 5 ms 648 KB Output is correct
9 Correct 6 ms 648 KB Output is correct
10 Correct 3 ms 648 KB Output is correct
11 Correct 2 ms 648 KB Output is correct
12 Correct 4 ms 648 KB Output is correct
13 Correct 3 ms 648 KB Output is correct
14 Correct 4 ms 648 KB Output is correct
15 Correct 4 ms 648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 4 ms 388 KB Output is correct
4 Correct 3 ms 464 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 7 ms 648 KB Output is correct
8 Correct 5 ms 648 KB Output is correct
9 Correct 6 ms 648 KB Output is correct
10 Correct 3 ms 648 KB Output is correct
11 Correct 2 ms 648 KB Output is correct
12 Correct 4 ms 648 KB Output is correct
13 Correct 3 ms 648 KB Output is correct
14 Correct 4 ms 648 KB Output is correct
15 Correct 4 ms 648 KB Output is correct
16 Correct 6 ms 648 KB Output is correct
17 Correct 9 ms 648 KB Output is correct
18 Correct 23 ms 648 KB Output is correct
19 Correct 14 ms 648 KB Output is correct
20 Correct 22 ms 648 KB Output is correct
21 Correct 23 ms 648 KB Output is correct
22 Correct 8 ms 648 KB Output is correct
23 Correct 15 ms 648 KB Output is correct
24 Correct 15 ms 648 KB Output is correct
25 Correct 16 ms 648 KB Output is correct
26 Correct 28 ms 700 KB Output is correct
27 Correct 27 ms 700 KB Output is correct
28 Correct 19 ms 700 KB Output is correct
29 Correct 21 ms 700 KB Output is correct
30 Correct 19 ms 700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 4 ms 388 KB Output is correct
4 Correct 3 ms 464 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 7 ms 648 KB Output is correct
8 Correct 5 ms 648 KB Output is correct
9 Correct 6 ms 648 KB Output is correct
10 Correct 3 ms 648 KB Output is correct
11 Correct 2 ms 648 KB Output is correct
12 Correct 4 ms 648 KB Output is correct
13 Correct 3 ms 648 KB Output is correct
14 Correct 4 ms 648 KB Output is correct
15 Correct 4 ms 648 KB Output is correct
16 Correct 6 ms 648 KB Output is correct
17 Correct 9 ms 648 KB Output is correct
18 Correct 23 ms 648 KB Output is correct
19 Correct 14 ms 648 KB Output is correct
20 Correct 22 ms 648 KB Output is correct
21 Correct 23 ms 648 KB Output is correct
22 Correct 8 ms 648 KB Output is correct
23 Correct 15 ms 648 KB Output is correct
24 Correct 15 ms 648 KB Output is correct
25 Correct 16 ms 648 KB Output is correct
26 Correct 28 ms 700 KB Output is correct
27 Correct 27 ms 700 KB Output is correct
28 Correct 19 ms 700 KB Output is correct
29 Correct 21 ms 700 KB Output is correct
30 Correct 19 ms 700 KB Output is correct
31 Correct 41 ms 700 KB Output is correct
32 Correct 37 ms 700 KB Output is correct
33 Correct 51 ms 700 KB Output is correct
34 Correct 75 ms 700 KB Output is correct
35 Correct 62 ms 720 KB Output is correct
36 Correct 68 ms 720 KB Output is correct
37 Correct 68 ms 720 KB Output is correct
38 Correct 29 ms 720 KB Output is correct
39 Correct 42 ms 720 KB Output is correct
40 Correct 78 ms 720 KB Output is correct
41 Correct 85 ms 720 KB Output is correct
42 Correct 49 ms 720 KB Output is correct
43 Correct 61 ms 720 KB Output is correct
44 Correct 66 ms 720 KB Output is correct
45 Correct 58 ms 720 KB Output is correct
46 Correct 35 ms 720 KB Output is correct
47 Correct 49 ms 720 KB Output is correct
48 Correct 100 ms 720 KB Output is correct
49 Correct 91 ms 720 KB Output is correct
50 Correct 105 ms 720 KB Output is correct
51 Correct 80 ms 720 KB Output is correct
52 Correct 47 ms 720 KB Output is correct
53 Correct 87 ms 720 KB Output is correct
54 Correct 67 ms 720 KB Output is correct
55 Correct 83 ms 720 KB Output is correct
56 Correct 91 ms 720 KB Output is correct
57 Correct 72 ms 720 KB Output is correct
58 Correct 83 ms 720 KB Output is correct
59 Correct 30 ms 720 KB Output is correct
60 Correct 32 ms 720 KB Output is correct