Submission #704264

# Submission time Handle Problem Language Result Execution time Memory
704264 2023-03-02T02:16:59 Z Tuanlinh123 Xylophone (JOI18_xylophone) C++17
0 / 100
1 ms 208 KB
#include<bits/stdc++.h>
#include "xylophone.h"
#define ll int
using namespace std;

ll a[100005];

ll calc(ll a, ll b, ll dis1, ll dis2)
{
    if (a<b)
    {
        if (dis1==dis2 || dis2==b-a)
            return a+dis1;
        return a-dis1;
    }
    if (dis1==dis2 || dis2==a-b)
        return a-dis1;
    return a+dis1;
}

void solve(ll n)
{
    freopen("output.txt", "w", stdout);
    ll L=1, R=n;
    ll lo=L, hi=R, val=query(lo, hi);
    while (hi-lo>1)
    {
        ll mid=(hi+lo)/2;
        if (query(L, mid)!=val)
            lo=mid;
        else hi=mid;
    }
    if (query(L, lo)!=val)
        R=hi;
    else R=lo;
    lo=L, hi=R;
    while (hi-lo>1)
    {
        ll mid=(hi+lo)/2;
        if (query(mid, R)!=val)
            hi=mid;
        else lo=mid;
    }
    if (query(hi, R)!=val)
        L=lo;
    else R=hi;
    a[L]=1; a[R]=n;
//    cout << L << " " << R << "\n";
    if (L>1) a[L-1]=a[L]+query(L-1, L);
    a[L+1]=a[L]+query(L, L+1);
    if (R<n) a[R+1]=a[R]-query(R, R+1);
    for (ll i=L-2; i>=1; i--)
        a[i]=calc(a[i+1], a[i+2], query(i, i+1), query(i, i+2));
    for (ll i=L+2; i<R; i++)
        a[i]=calc(a[i-1], a[i-2], query(i-1, i), query(i-2, i));
    for (ll i=R+2; i<=n; i++)
        a[i]=calc(a[i-1], a[i-2], query(i-1, i), query(i-2, i));
//    for (ll i=1; i<=n; i++)
//        cout << a[i] << " ";
//    cout << "\n";
    for (ll i=1; i<=n; i++)
        answer(i, a[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1 ms 208 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1 ms 208 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1 ms 208 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -