답안 #542494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
542494 2022-03-26T19:07:14 Z status_coding Xylophone (JOI18_xylophone) C++14
100 / 100
81 ms 560 KB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

int n;
int a[5005];

map<int, int> fr;

int findN()
{
    int st=2, dr=n, mij, last=-1;
    while(st <= dr)
    {
        mij = (st+dr)/2;

        //cout<<1<<' '<<mij<<'\n';

        if(query(1, mij) == n-1)
        {
            last=mij;
            dr=mij-1;
        }
        else
            st=mij+1;
    }

    return last;
}

bool bad(int x)
{
    if(x > n)
        return true;
    if(x <= 0)
        return true;
    if(fr[x])
        return true;

    return false;
}

int check(int a, int b, int c)
{
   return max({a, b, c}) - min({a, b, c});
}

void solve(int N)
{
    n=N;

    int p = findN();

    if(p == -1)
        exit(1);

    a[p] = n;
    fr[n] = 1;

    int mini=n;
    for(int i=p-1;i>=1;i--)
    {
        int dif = query(i, i+1);

        int x1 = a[i+1] - dif;
        int x2 = a[i+1] + dif;

        if(bad(x1))
            a[i]=x2;
        else if(bad(x2))
            a[i]=x1;
        else
        {
            int nQ = query(i, i+2);

            if(check(x2, a[i+1], a[i+2]) == nQ)
                a[i]=x2;
            else
                a[i]=x1;
        }

        mini=min(mini, a[i]);
        fr[ a[i] ] =1;
    }

    mini=n;
    for(int i=p+1;i<=n;i++)
    {
        int dif = query(i-1, i);

        int x1 = a[i-1] - dif;
        int x2 = a[i-1] + dif;

        if(bad(x1))
            a[i]=x2;
        else if(bad(x2))
            a[i]=x1;
        else
        {
            int nQ = query(i-2, i);

            if(check(a[i-2], a[i-1], x2) == nQ)
                a[i]=x2;
            else
                a[i]=x1;
        }

        mini=min(mini, a[i]);
        fr[ a[i] ] =1;
    }

    /*
    for(int i=1;i<=n;i++)
        cout<<a[i]<<' ';
    */

    for(int i=1;i<=n;i++)
        answer(i, a[i]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 2 ms 300 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 2 ms 300 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 3 ms 300 KB Output is correct
18 Correct 10 ms 320 KB Output is correct
19 Correct 11 ms 336 KB Output is correct
20 Correct 10 ms 336 KB Output is correct
21 Correct 11 ms 340 KB Output is correct
22 Correct 11 ms 336 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 13 ms 348 KB Output is correct
25 Correct 9 ms 336 KB Output is correct
26 Correct 15 ms 340 KB Output is correct
27 Correct 11 ms 336 KB Output is correct
28 Correct 12 ms 328 KB Output is correct
29 Correct 12 ms 336 KB Output is correct
30 Correct 11 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 2 ms 300 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 2 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 3 ms 208 KB Output is correct
17 Correct 3 ms 300 KB Output is correct
18 Correct 10 ms 320 KB Output is correct
19 Correct 11 ms 336 KB Output is correct
20 Correct 10 ms 336 KB Output is correct
21 Correct 11 ms 340 KB Output is correct
22 Correct 11 ms 336 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 13 ms 348 KB Output is correct
25 Correct 9 ms 336 KB Output is correct
26 Correct 15 ms 340 KB Output is correct
27 Correct 11 ms 336 KB Output is correct
28 Correct 12 ms 328 KB Output is correct
29 Correct 12 ms 336 KB Output is correct
30 Correct 11 ms 336 KB Output is correct
31 Correct 24 ms 320 KB Output is correct
32 Correct 31 ms 412 KB Output is correct
33 Correct 47 ms 432 KB Output is correct
34 Correct 64 ms 460 KB Output is correct
35 Correct 58 ms 456 KB Output is correct
36 Correct 40 ms 536 KB Output is correct
37 Correct 43 ms 452 KB Output is correct
38 Correct 48 ms 508 KB Output is correct
39 Correct 62 ms 532 KB Output is correct
40 Correct 52 ms 552 KB Output is correct
41 Correct 47 ms 540 KB Output is correct
42 Correct 52 ms 548 KB Output is correct
43 Correct 47 ms 524 KB Output is correct
44 Correct 36 ms 476 KB Output is correct
45 Correct 60 ms 444 KB Output is correct
46 Correct 64 ms 512 KB Output is correct
47 Correct 56 ms 504 KB Output is correct
48 Correct 81 ms 492 KB Output is correct
49 Correct 32 ms 528 KB Output is correct
50 Correct 60 ms 468 KB Output is correct
51 Correct 51 ms 560 KB Output is correct
52 Correct 54 ms 472 KB Output is correct
53 Correct 61 ms 460 KB Output is correct
54 Correct 45 ms 544 KB Output is correct
55 Correct 60 ms 512 KB Output is correct
56 Correct 45 ms 456 KB Output is correct
57 Correct 50 ms 460 KB Output is correct
58 Correct 54 ms 488 KB Output is correct
59 Correct 56 ms 464 KB Output is correct
60 Correct 58 ms 460 KB Output is correct