답안 #995992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995992 2024-06-10T06:41:40 Z vjudge1 Xylophone (JOI18_xylophone) C++17
100 / 100
50 ms 856 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];
}

// int query(int l,int r)
// {
//     cout<<l<<' '<<r<<endl;
//     int res; cin>>res; return res;
// }

void solve(int _n)
// signed main()
{
    n=_n;
    // cin>>n;
    int l=1,r=n;
    while(l<r-1)
    {
        int m=l+r>>1;
        if(query(m,n)!=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-1,i);
        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-2,i);
            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]);
    // for(int i=1;i<=n;i++) cout<<ans[i]<<' ';
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:47:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |         int m=l+r>>1;
      |               ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 5 ms 344 KB Output is correct
19 Correct 8 ms 344 KB Output is correct
20 Correct 4 ms 344 KB Output is correct
21 Correct 6 ms 456 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 5 ms 448 KB Output is correct
24 Correct 5 ms 344 KB Output is correct
25 Correct 5 ms 392 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 5 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 6 ms 344 KB Output is correct
30 Correct 5 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 3 ms 344 KB Output is correct
18 Correct 5 ms 344 KB Output is correct
19 Correct 8 ms 344 KB Output is correct
20 Correct 4 ms 344 KB Output is correct
21 Correct 6 ms 456 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 5 ms 448 KB Output is correct
24 Correct 5 ms 344 KB Output is correct
25 Correct 5 ms 392 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 5 ms 344 KB Output is correct
28 Correct 6 ms 344 KB Output is correct
29 Correct 6 ms 344 KB Output is correct
30 Correct 5 ms 452 KB Output is correct
31 Correct 15 ms 708 KB Output is correct
32 Correct 13 ms 344 KB Output is correct
33 Correct 20 ms 468 KB Output is correct
34 Correct 28 ms 344 KB Output is correct
35 Correct 26 ms 464 KB Output is correct
36 Correct 25 ms 592 KB Output is correct
37 Correct 26 ms 700 KB Output is correct
38 Correct 24 ms 452 KB Output is correct
39 Correct 41 ms 592 KB Output is correct
40 Correct 33 ms 592 KB Output is correct
41 Correct 36 ms 444 KB Output is correct
42 Correct 25 ms 856 KB Output is correct
43 Correct 34 ms 696 KB Output is correct
44 Correct 24 ms 724 KB Output is correct
45 Correct 40 ms 344 KB Output is correct
46 Correct 38 ms 592 KB Output is correct
47 Correct 40 ms 704 KB Output is correct
48 Correct 39 ms 696 KB Output is correct
49 Correct 37 ms 464 KB Output is correct
50 Correct 35 ms 600 KB Output is correct
51 Correct 24 ms 852 KB Output is correct
52 Correct 37 ms 344 KB Output is correct
53 Correct 30 ms 444 KB Output is correct
54 Correct 50 ms 692 KB Output is correct
55 Correct 31 ms 592 KB Output is correct
56 Correct 31 ms 848 KB Output is correct
57 Correct 31 ms 696 KB Output is correct
58 Correct 30 ms 448 KB Output is correct
59 Correct 42 ms 344 KB Output is correct
60 Correct 32 ms 456 KB Output is correct