답안 #995976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995976 2024-06-10T06:30:05 Z Thanhs Xylophone (JOI18_xylophone) C++14
0 / 100
1 ms 344 KB
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <xylophone.h>
using namespace std;
// #define int long long
#define pb push_back
 
// #define endl '\n'
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define setmin(x,y) x=min((x),(y))
#define setmax(x,y) x=max((x),(y))
#define fi first
#define se second
 
mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l,int r){return l+((hdp()%(r-l+1))+r-l+1)%(r-l+1);}

const int N = 1e4+5;
const int mod = 998244353;
const int SQ = 450;
const int inf = 1e9+1;

int ans[N],n;
bool b[N];

bool check(int x)
{
    if(x<0||x>n) return 0;
    return !b[x];
}

void solve(int _n)
{
    n=_n;
    int l=1,r=n-1;
    while(l<r-1)
    {
        int m=l+r>>1;
        if(query(1,m)!=n-1) r=m;
        else l=m;
    }
    ans[l]=1; b[1]=1;
    if(l-1) 
    {
        ans[l-1]=ans[l]+query(l-1,l);
        b[ans[l-1]]=1;
    }
    if(l+1<=n) 
    {
        ans[l+1]=ans[l]+query(l,l+1);
        b[ans[l+1]]=1;
    }
    for(int i=l-2;i>=1;i--)
    {
        int t=query(i,i+1);
        if(!check(ans[i+1]+t)) ans[i]=ans[i+1]-t;
        else if(!check(ans[i+1]-t)) ans[i]=ans[i+1]+t;
        if(!ans[i]) 
        {
            int tt=query(i,i+2);
            if(tt==abs(ans[i+2]-ans[i+1]))
            {
                if(ans[i+2]>ans[i+1]) ans[i]=ans[i+1]+t;
                else ans[i]=ans[i+1]-t;
            }
            else if(tt==t)
            {
                if(ans[i+2]>ans[i+1]) ans[i]=ans[i+1]+t;
                else ans[i]=ans[i+1]-t;
            }
            else
            {
                if(ans[i+2]>ans[i+1]) ans[i]=ans[i+1]-t;
                else ans[i]=ans[i+1]+t;
            }
        }
        b[ans[i]]=1;
    }
    for(int i=l+2;i<=n;i++)
    {
        int t=query(i,i-1);
        if(!check(ans[i-1]+t)) ans[i]=ans[i-1]-t;
        else if(!check(ans[i-1]-t)) ans[i]=ans[i-1]+t;
        if(!ans[i]) 
        {
            int tt=query(i,i-2);
            if(tt==abs(ans[i-2]-ans[i-1]))
            {
                if(ans[i-2]>ans[i-1]) ans[i]=ans[i-1]+t;
                else ans[i]=ans[i-1]-t;
            }
            else if(tt==t)
            {
                if(ans[i-2]>ans[i-1]) ans[i]=ans[i-1]+t;
                else ans[i]=ans[i-1]-t;
            }
            else
            {
                if(ans[i-2]>ans[i-1]) ans[i]=ans[i-1]-t;
                else ans[i]=ans[i-1]+t;
            }
        }
        b[ans[i]]=1;
    }
    for(int i=1;i<=n;i++) answer(i,ans[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:39:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |         int m=l+r>>1;
      |               ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Wrong Answer [1]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Wrong Answer [1]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Wrong Answer [1]
3 Halted 0 ms 0 KB -