답안 #83006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83006 2018-11-03T15:15:07 Z Vasiljko Xylophone (JOI18_xylophone) C++14
100 / 100
75 ms 720 KB
#include <bits/stdc++.h>
using namespace std;

void solve(int N);
int query(int s, int t);
void answer(int i, int a);


int a[5000];
bool vis[5000];

void solve(int n) {
    int diff=n-1;
    int ind;
    int lo=1;
    int hi=n;

    while(lo<=hi){
        int mid=(lo+hi)>>1;
        if(query(mid,n)==diff){
            lo=mid+1;
        }else{
            ind=mid-1;
            hi=mid-1;
        }
    }

    a[ind]=1;
    a[ind+1]=1+query(ind,ind+1);
    if(ind>1){
        a[ind-1]=1+query(ind-1,ind);
        vis[a[ind-1]]=true;
    }
    vis[a[ind]]=true;
    vis[a[ind+1]]=true;

    for(int i=ind+2;i<=n;i++){
        int q=query(i-1,i);

        if(vis[a[i-1]+q]){
            a[i]=a[i-1]-q;
            continue;
        }else if(vis[a[i-1]-q]){
            a[i]=a[i-1]+q;
            continue;
        }

        int p=query(i-2,i);

        int val=a[i-1]+q;
        if(max(val,max(a[i-1],a[i-2]))-min(val,min(a[i-1],a[i-2]))==p){
            a[i]=val;
        }else{
            a[i]=a[i-1]-q;
        }
        vis[a[i]]=true;
    }

    if(ind>1){
        for(int i=ind-2;i>=1;i--){
            int q=query(i,i+1);

            if(vis[a[i+1]+q]){
                a[i]=a[i+1]-q;
                continue;
            }else if(vis[a[i+1]-q]){
                a[i]=a[i+1]+q;
                continue;
            }

            int p=query(i,i+2);

            int val=a[i+1]+q;
            if(max(val,max(a[i+1],a[i+2]))-min(val,min(a[i+1],a[i+2]))==p){
                a[i]=val;
            }else{
                a[i]=a[i+1]-q;
            }
            vis[a[i]]=true;
        }
    }
    for(int i=1;i<=n;i++)answer(i,a[i]);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:34:14: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
     vis[a[ind]]=true;
         ~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
3 Correct 3 ms 456 KB Output is correct
4 Correct 4 ms 456 KB Output is correct
5 Correct 3 ms 456 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 3 ms 456 KB Output is correct
8 Correct 3 ms 572 KB Output is correct
9 Correct 3 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 4 ms 572 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 3 ms 572 KB Output is correct
14 Correct 3 ms 572 KB Output is correct
15 Correct 4 ms 572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
3 Correct 3 ms 456 KB Output is correct
4 Correct 4 ms 456 KB Output is correct
5 Correct 3 ms 456 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 3 ms 456 KB Output is correct
8 Correct 3 ms 572 KB Output is correct
9 Correct 3 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 4 ms 572 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 3 ms 572 KB Output is correct
14 Correct 3 ms 572 KB Output is correct
15 Correct 4 ms 572 KB Output is correct
16 Correct 4 ms 572 KB Output is correct
17 Correct 5 ms 572 KB Output is correct
18 Correct 8 ms 572 KB Output is correct
19 Correct 10 ms 572 KB Output is correct
20 Correct 8 ms 572 KB Output is correct
21 Correct 12 ms 572 KB Output is correct
22 Correct 16 ms 576 KB Output is correct
23 Correct 17 ms 576 KB Output is correct
24 Correct 9 ms 576 KB Output is correct
25 Correct 11 ms 576 KB Output is correct
26 Correct 15 ms 576 KB Output is correct
27 Correct 13 ms 576 KB Output is correct
28 Correct 9 ms 576 KB Output is correct
29 Correct 17 ms 588 KB Output is correct
30 Correct 15 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 456 KB Output is correct
3 Correct 3 ms 456 KB Output is correct
4 Correct 4 ms 456 KB Output is correct
5 Correct 3 ms 456 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 3 ms 456 KB Output is correct
8 Correct 3 ms 572 KB Output is correct
9 Correct 3 ms 572 KB Output is correct
10 Correct 3 ms 572 KB Output is correct
11 Correct 4 ms 572 KB Output is correct
12 Correct 2 ms 572 KB Output is correct
13 Correct 3 ms 572 KB Output is correct
14 Correct 3 ms 572 KB Output is correct
15 Correct 4 ms 572 KB Output is correct
16 Correct 4 ms 572 KB Output is correct
17 Correct 5 ms 572 KB Output is correct
18 Correct 8 ms 572 KB Output is correct
19 Correct 10 ms 572 KB Output is correct
20 Correct 8 ms 572 KB Output is correct
21 Correct 12 ms 572 KB Output is correct
22 Correct 16 ms 576 KB Output is correct
23 Correct 17 ms 576 KB Output is correct
24 Correct 9 ms 576 KB Output is correct
25 Correct 11 ms 576 KB Output is correct
26 Correct 15 ms 576 KB Output is correct
27 Correct 13 ms 576 KB Output is correct
28 Correct 9 ms 576 KB Output is correct
29 Correct 17 ms 588 KB Output is correct
30 Correct 15 ms 588 KB Output is correct
31 Correct 38 ms 588 KB Output is correct
32 Correct 25 ms 588 KB Output is correct
33 Correct 60 ms 604 KB Output is correct
34 Correct 68 ms 604 KB Output is correct
35 Correct 66 ms 604 KB Output is correct
36 Correct 56 ms 604 KB Output is correct
37 Correct 38 ms 604 KB Output is correct
38 Correct 61 ms 604 KB Output is correct
39 Correct 58 ms 604 KB Output is correct
40 Correct 70 ms 716 KB Output is correct
41 Correct 47 ms 716 KB Output is correct
42 Correct 32 ms 716 KB Output is correct
43 Correct 36 ms 716 KB Output is correct
44 Correct 59 ms 716 KB Output is correct
45 Correct 54 ms 716 KB Output is correct
46 Correct 54 ms 716 KB Output is correct
47 Correct 63 ms 716 KB Output is correct
48 Correct 55 ms 716 KB Output is correct
49 Correct 40 ms 716 KB Output is correct
50 Correct 64 ms 716 KB Output is correct
51 Correct 64 ms 716 KB Output is correct
52 Correct 75 ms 720 KB Output is correct
53 Correct 68 ms 720 KB Output is correct
54 Correct 57 ms 720 KB Output is correct
55 Correct 48 ms 720 KB Output is correct
56 Correct 74 ms 720 KB Output is correct
57 Correct 69 ms 720 KB Output is correct
58 Correct 67 ms 720 KB Output is correct
59 Correct 38 ms 720 KB Output is correct
60 Correct 64 ms 720 KB Output is correct