Submission #239638

# Submission time Handle Problem Language Result Execution time Memory
239638 2020-06-16T22:41:23 Z Dremix10 Xylophone (JOI18_xylophone) C++17
100 / 100
145 ms 98624 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define F first
#define S second
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define maxp 22
#define EPS (ld)(1e-18)
#define mod (int)(1e9+7)

int asked[5001][5001];

int ask(int l, int r){
    if(asked[l][r]!=-1)
        return asked[l][r];
    asked[l][r]=query(l,r);
    return asked[l][r];
}

void solve(int N) {
    int arr[N+1];

    int i,j;
    for(i=0;i<=N;i++)
        for(j=0;j<=N;j++)
        asked[i][j]=-1;

    int l=1,r=N;
    while(l<r){
        int mid=(l+r)/2;
        int x=ask(1,mid);
        if(x==N-1)
            r=mid-1;
        else
            l=mid+1;
    }
    int found;
    int x=ask(1,l);
    if(x==N-1)
        found=l;
    else
        found=l+1;
    //cout<<found<<endl;

    set<int> nums;
    for(i=1;i<N;i++)
        nums.insert(i);

    arr[found]=N;
    if(found>1){
        int x=ask(found-1,found);
        arr[found-1]=N-x;
        nums.erase(N-x);
    }
    if(found<N){
        int x=ask(found,found+1);
        arr[found+1]=N-x;
        nums.erase(N-x);
    }



    for(i=found-2;i>=1;i--){
        int x2=ask(i,i+1);
        //int x3=ask(i,i+2);
        int p1=arr[i+1]-x2;
        int p2=arr[i+1]+x2;

        if(nums.count(p1) && nums.count(p2)){
            int x3=ask(i,i+2);
            if(max({p1,arr[i+1],arr[i+2]})-min({p1,arr[i+1],arr[i+2]})==x3)
                arr[i]=p1;
            else
                arr[i]=p2;
        }
        else{
            if(nums.count(p1))
                arr[i]=p1;
            else
                arr[i]=p2;
        }
        nums.erase(arr[i]);
    }
    for(i=found+2;i<=N;i++){
        int x2=ask(i-1,i);
        //int x3=ask(i-2,i);
        int p1=arr[i-1]-x2;
        int p2=arr[i-1]+x2;

        if(nums.count(p1) && nums.count(p2)){
            int x3=ask(i-2,i);
            if(max({p1,arr[i-1],arr[i-2]})-min({p1,arr[i-1],arr[i-2]})==x3)
                arr[i]=p1;
            else
                arr[i]=p2;
        }
        else{
            if(nums.count(p1))
                arr[i]=p1;
            else
                arr[i]=p2;
        }

        nums.erase(arr[i]);
    }
    for(i=1;i<=N;i++)
        answer(i,arr[i]);

}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 7 ms 768 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 6 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 5 ms 848 KB Output is correct
11 Correct 6 ms 768 KB Output is correct
12 Correct 7 ms 768 KB Output is correct
13 Correct 6 ms 768 KB Output is correct
14 Correct 6 ms 768 KB Output is correct
15 Correct 6 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 7 ms 768 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 6 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 5 ms 848 KB Output is correct
11 Correct 6 ms 768 KB Output is correct
12 Correct 7 ms 768 KB Output is correct
13 Correct 6 ms 768 KB Output is correct
14 Correct 6 ms 768 KB Output is correct
15 Correct 6 ms 768 KB Output is correct
16 Correct 9 ms 1408 KB Output is correct
17 Correct 14 ms 3200 KB Output is correct
18 Correct 19 ms 6272 KB Output is correct
19 Correct 26 ms 8320 KB Output is correct
20 Correct 26 ms 8320 KB Output is correct
21 Correct 21 ms 8320 KB Output is correct
22 Correct 20 ms 8320 KB Output is correct
23 Correct 13 ms 8328 KB Output is correct
24 Correct 20 ms 8320 KB Output is correct
25 Correct 18 ms 8320 KB Output is correct
26 Correct 21 ms 8320 KB Output is correct
27 Correct 22 ms 8320 KB Output is correct
28 Correct 21 ms 8320 KB Output is correct
29 Correct 19 ms 8320 KB Output is correct
30 Correct 20 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 7 ms 768 KB Output is correct
5 Correct 6 ms 768 KB Output is correct
6 Correct 6 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 6 ms 768 KB Output is correct
9 Correct 6 ms 768 KB Output is correct
10 Correct 5 ms 848 KB Output is correct
11 Correct 6 ms 768 KB Output is correct
12 Correct 7 ms 768 KB Output is correct
13 Correct 6 ms 768 KB Output is correct
14 Correct 6 ms 768 KB Output is correct
15 Correct 6 ms 768 KB Output is correct
16 Correct 9 ms 1408 KB Output is correct
17 Correct 14 ms 3200 KB Output is correct
18 Correct 19 ms 6272 KB Output is correct
19 Correct 26 ms 8320 KB Output is correct
20 Correct 26 ms 8320 KB Output is correct
21 Correct 21 ms 8320 KB Output is correct
22 Correct 20 ms 8320 KB Output is correct
23 Correct 13 ms 8328 KB Output is correct
24 Correct 20 ms 8320 KB Output is correct
25 Correct 18 ms 8320 KB Output is correct
26 Correct 21 ms 8320 KB Output is correct
27 Correct 22 ms 8320 KB Output is correct
28 Correct 21 ms 8320 KB Output is correct
29 Correct 19 ms 8320 KB Output is correct
30 Correct 20 ms 8320 KB Output is correct
31 Correct 54 ms 27520 KB Output is correct
32 Correct 79 ms 50228 KB Output is correct
33 Correct 124 ms 85868 KB Output is correct
34 Correct 114 ms 98552 KB Output is correct
35 Correct 120 ms 98424 KB Output is correct
36 Correct 122 ms 98552 KB Output is correct
37 Correct 118 ms 98552 KB Output is correct
38 Correct 116 ms 98424 KB Output is correct
39 Correct 110 ms 98580 KB Output is correct
40 Correct 122 ms 98552 KB Output is correct
41 Correct 135 ms 98424 KB Output is correct
42 Correct 121 ms 98552 KB Output is correct
43 Correct 85 ms 98616 KB Output is correct
44 Correct 98 ms 98424 KB Output is correct
45 Correct 117 ms 98528 KB Output is correct
46 Correct 139 ms 98424 KB Output is correct
47 Correct 135 ms 98552 KB Output is correct
48 Correct 100 ms 98532 KB Output is correct
49 Correct 137 ms 98424 KB Output is correct
50 Correct 134 ms 98428 KB Output is correct
51 Correct 130 ms 98424 KB Output is correct
52 Correct 142 ms 98424 KB Output is correct
53 Correct 111 ms 98424 KB Output is correct
54 Correct 145 ms 98552 KB Output is correct
55 Correct 113 ms 98624 KB Output is correct
56 Correct 131 ms 98512 KB Output is correct
57 Correct 130 ms 98552 KB Output is correct
58 Correct 138 ms 98424 KB Output is correct
59 Correct 103 ms 98512 KB Output is correct
60 Correct 138 ms 98424 KB Output is correct