Submission #590481

# Submission time Handle Problem Language Result Execution time Memory
590481 2022-07-06T03:00:22 Z Huy Xylophone (JOI18_xylophone) C++17
0 / 100
1 ms 208 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 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 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
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Incorrect 1 ms 208 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Incorrect 1 ms 208 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Incorrect 1 ms 208 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -