답안 #590483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590483 2022-07-06T03:02:37 Z Huy Xylophone (JOI18_xylophone) C++17
100 / 100
84 ms 336 KB
#include<bits/stdc++.h>
#include "xylophone.h"
//#define int long long
//#define pii pair<int,ll>
//#define fi first
//#define se second
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")*/
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ldb = long double;
const ll N = (int)1e9 + 1;
const int maxN = (int)3e5 + 1;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infty = 1e18 + 7;
const int base = (int)4e5;

void InputFile()
{
    //freopen("scrivener.inp","r",stdin);
    //freopen("scrivener.out","w",stdout);
    //freopen("test.out","r",stdin);
}

void FastInput()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int a[5005];
int apr[5005];

void solve(int n)
{
    int low = 1;
    int high = n;
    while(low <= high)
    {
        int mid = (low + high) / 2;
        int x = query(mid,n);
        if(x == n - 1)
            low = mid + 1;
        else
            high = mid - 1;
    }
    answer(high,1);
    int pt = high;
    a[high] = 1;
    apr[1]++;
    for(int i = pt - 1; i >= 1; i--)
    {
        int diff = query(i,i+1);
        if(a[i+1] - diff < 1)
        {
            a[i] = a[i+1] + diff;
            answer(i,a[i]);
        }
        else if(a[i+1] + diff > n)
        {
            a[i] = a[i+1] - diff;
            answer(i,a[i]);
        }
        else
        {
            if(apr[a[i+1]-diff])
            {
                a[i] = a[i+1]+diff;
                answer(i,a[i]);
            }
            else if(apr[a[i+1]+diff])
            {
                a[i] = a[i+1] - diff;
                answer(i,a[i]);
            }
            else
            {
                int c = a[i+1] - diff;
                int maxi,mini;
                maxi = max(max(c,a[i+1]),a[i+2]);
                mini = min(min(c,a[i+1]),a[i+2]);
                if(query(i,i+2) == maxi - mini)
                {
                    a[i] = c;
                    answer(i,c);
                }
                else 
                {   
                    a[i] = a[i+1] + diff; 
                    answer(i,a[i+1] + diff);
                }
            }
        }

        apr[a[i]]++;
    }

    for(int i = pt + 1; i <= n; i++)
    {
        int diff = query(i-1,i);
        if(a[i-1] - diff < 1)
        {
            a[i] = a[i-1] + diff;
            answer(i,a[i]);
        }
        else if(a[i-1] + diff > n)
        {
            a[i] = a[i-1] - diff;
            answer(i,a[i]);
        }
        else
        {
            if(apr[a[i-1]-diff])
            {
                a[i] = a[i-1] + diff;
                answer(i,a[i]);
            }
            else if(apr[a[i-1]+diff])
            {
                a[i] = a[i-1] - diff;
                answer(i,a[i]);
            }
            else
            {
                int c = a[i-1] - diff;
                int maxi,mini;
                maxi = max(max(c,a[i-1]),a[i-2]);
                mini = min(min(c,a[i-1]),a[i-2]);
                if(query(i-2,i) == maxi - mini)
                {
                    a[i] = c;
                    answer(i,c);
                }
                else 
                {   
                    a[i] = a[i-1] + diff;
                    answer(i,a[i-1] + diff);
                }
            }
        }

        apr[a[i]]++;
    }
}

void Debug()
{

}


/*int32_t main()
{
    FastInput();
    //InputFile();
    //int sub_type;
    //cin >> sub_type;
    //Sieve();
    //Prepare();
    int test;
    cin >> test;
    //test = 1;
    while(test--)
        //for(int prc = 1; prc <= test; prc++)
    {
        Read();
        Solve();
        //Debug();
    }
}*/

/*
2 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/
# 결과 실행 시간 메모리 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 1 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 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 2 ms 300 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 1 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 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 2 ms 300 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 10 ms 208 KB Output is correct
19 Correct 9 ms 308 KB Output is correct
20 Correct 12 ms 208 KB Output is correct
21 Correct 10 ms 208 KB Output is correct
22 Correct 10 ms 308 KB Output is correct
23 Correct 8 ms 208 KB Output is correct
24 Correct 11 ms 308 KB Output is correct
25 Correct 16 ms 304 KB Output is correct
26 Correct 12 ms 312 KB Output is correct
27 Correct 14 ms 208 KB Output is correct
28 Correct 14 ms 292 KB Output is correct
29 Correct 5 ms 312 KB Output is correct
30 Correct 12 ms 300 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 1 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 2 ms 208 KB Output is correct
8 Correct 2 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 2 ms 208 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 2 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 2 ms 300 KB Output is correct
16 Correct 4 ms 208 KB Output is correct
17 Correct 5 ms 208 KB Output is correct
18 Correct 10 ms 208 KB Output is correct
19 Correct 9 ms 308 KB Output is correct
20 Correct 12 ms 208 KB Output is correct
21 Correct 10 ms 208 KB Output is correct
22 Correct 10 ms 308 KB Output is correct
23 Correct 8 ms 208 KB Output is correct
24 Correct 11 ms 308 KB Output is correct
25 Correct 16 ms 304 KB Output is correct
26 Correct 12 ms 312 KB Output is correct
27 Correct 14 ms 208 KB Output is correct
28 Correct 14 ms 292 KB Output is correct
29 Correct 5 ms 312 KB Output is correct
30 Correct 12 ms 300 KB Output is correct
31 Correct 19 ms 316 KB Output is correct
32 Correct 32 ms 208 KB Output is correct
33 Correct 40 ms 324 KB Output is correct
34 Correct 51 ms 320 KB Output is correct
35 Correct 61 ms 324 KB Output is correct
36 Correct 49 ms 296 KB Output is correct
37 Correct 32 ms 316 KB Output is correct
38 Correct 41 ms 316 KB Output is correct
39 Correct 53 ms 328 KB Output is correct
40 Correct 60 ms 312 KB Output is correct
41 Correct 59 ms 320 KB Output is correct
42 Correct 40 ms 304 KB Output is correct
43 Correct 37 ms 316 KB Output is correct
44 Correct 39 ms 336 KB Output is correct
45 Correct 61 ms 320 KB Output is correct
46 Correct 52 ms 300 KB Output is correct
47 Correct 60 ms 328 KB Output is correct
48 Correct 51 ms 324 KB Output is correct
49 Correct 66 ms 328 KB Output is correct
50 Correct 76 ms 312 KB Output is correct
51 Correct 57 ms 324 KB Output is correct
52 Correct 41 ms 328 KB Output is correct
53 Correct 61 ms 312 KB Output is correct
54 Correct 63 ms 208 KB Output is correct
55 Correct 65 ms 304 KB Output is correct
56 Correct 52 ms 312 KB Output is correct
57 Correct 50 ms 328 KB Output is correct
58 Correct 57 ms 208 KB Output is correct
59 Correct 64 ms 320 KB Output is correct
60 Correct 84 ms 208 KB Output is correct