Submission #219471

# Submission time Handle Problem Language Result Execution time Memory
219471 2020-04-05T11:29:01 Z MKopchev Xylophone (JOI18_xylophone) C++14
100 / 100
1407 ms 1272 KB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;
const int nmax=5e3+42;

int output[nmax];
int n;
bool seen[nmax];

int diff[nmax],diff_2[nmax];
/*
int query(int s,int t)
{
    cout<<s<<" "<<t<<endl;
    int ret;
    cin>>ret;
    return ret;
}

int answer(int s,int t)
{
    cout<<"answer "<<s<<" "<<t<<endl;
}
*/
int my_ask(int s,int t)
{
    return query(s,t);
}

int maxi(vector<int> now)
{
    int a=0;
    for(auto k:now)
        a=max(a,k);
    return a;
}
int mini(vector<int> now)
{
    int a=nmax;
    for(auto k:now)
        a=min(a,k);
    return a;
}

bool STOP;
void print()
{
    for(int i=1;i<=n;i++)
        answer(i,output[i]);
    STOP=1;
}

void rec(int val,int pos)
{
    //cout<<"rec "<<val<<" "<<pos<<endl;

    if(STOP)return;

    if(1>val||val>n)return;
    if(seen[val])return;

    seen[val]=1;
    output[pos]=val;

    if(val==n&&seen[1]==0)
    {
        seen[val]=0;
        return;
    }

    //cout<<"rec: ";for(int i=1;i<=n;i++)cout<<output[i]<<" ";cout<<";"<<endl;for(int i=1;i<=n;i++)cout<<seen[i]<<" ";cout<<endl;

    if(diff_2[pos])
    {
        //cout<<"test_2 "<<maxi({output[pos-2],output[pos-1],output[pos]})<<" "<<mini({output[pos-2],output[pos-1],output[pos]})<<" "<<diff_2[pos]<<endl;

        if(maxi({output[pos-2],output[pos-1],output[pos]})-mini({output[pos-2],output[pos-1],output[pos]})!=diff_2[pos])
        {
            seen[val]=0;
            return;
        }
    }

    if(pos==n)print();

    rec(val+diff[pos],pos+1);

    rec(val-diff[pos],pos+1);

    seen[val]=0;
}
void solve(int N)
{
    n=N;

    for(int i=1;i+1<=n;i++)
        diff[i]=my_ask(i,i+1);

    for(int i=3;i<=n;i++)
        diff_2[i]=my_ask(i-2,i);

    for(int i=1;i<=n;i++)
        rec(i,1);
}
/*
int main()
{
    solve(5);
}
*/
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 7 ms 412 KB Output is correct
9 Correct 7 ms 336 KB Output is correct
10 Correct 6 ms 424 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 368 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 7 ms 412 KB Output is correct
9 Correct 7 ms 336 KB Output is correct
10 Correct 6 ms 424 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 368 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 11 ms 384 KB Output is correct
17 Correct 14 ms 384 KB Output is correct
18 Correct 14 ms 412 KB Output is correct
19 Correct 26 ms 480 KB Output is correct
20 Correct 23 ms 384 KB Output is correct
21 Correct 24 ms 384 KB Output is correct
22 Correct 28 ms 384 KB Output is correct
23 Correct 20 ms 380 KB Output is correct
24 Correct 74 ms 508 KB Output is correct
25 Correct 23 ms 388 KB Output is correct
26 Correct 24 ms 504 KB Output is correct
27 Correct 22 ms 504 KB Output is correct
28 Correct 14 ms 504 KB Output is correct
29 Correct 22 ms 480 KB Output is correct
30 Correct 26 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 7 ms 412 KB Output is correct
9 Correct 7 ms 336 KB Output is correct
10 Correct 6 ms 424 KB Output is correct
11 Correct 7 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 6 ms 368 KB Output is correct
14 Correct 7 ms 384 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 11 ms 384 KB Output is correct
17 Correct 14 ms 384 KB Output is correct
18 Correct 14 ms 412 KB Output is correct
19 Correct 26 ms 480 KB Output is correct
20 Correct 23 ms 384 KB Output is correct
21 Correct 24 ms 384 KB Output is correct
22 Correct 28 ms 384 KB Output is correct
23 Correct 20 ms 380 KB Output is correct
24 Correct 74 ms 508 KB Output is correct
25 Correct 23 ms 388 KB Output is correct
26 Correct 24 ms 504 KB Output is correct
27 Correct 22 ms 504 KB Output is correct
28 Correct 14 ms 504 KB Output is correct
29 Correct 22 ms 480 KB Output is correct
30 Correct 26 ms 504 KB Output is correct
31 Correct 78 ms 528 KB Output is correct
32 Correct 101 ms 660 KB Output is correct
33 Correct 102 ms 928 KB Output is correct
34 Correct 76 ms 888 KB Output is correct
35 Correct 102 ms 992 KB Output is correct
36 Correct 118 ms 988 KB Output is correct
37 Correct 1316 ms 1144 KB Output is correct
38 Correct 86 ms 888 KB Output is correct
39 Correct 102 ms 888 KB Output is correct
40 Correct 90 ms 1144 KB Output is correct
41 Correct 98 ms 888 KB Output is correct
42 Correct 86 ms 888 KB Output is correct
43 Correct 1407 ms 1272 KB Output is correct
44 Correct 86 ms 888 KB Output is correct
45 Correct 83 ms 892 KB Output is correct
46 Correct 135 ms 916 KB Output is correct
47 Correct 102 ms 916 KB Output is correct
48 Correct 86 ms 888 KB Output is correct
49 Correct 118 ms 1016 KB Output is correct
50 Correct 129 ms 1016 KB Output is correct
51 Correct 94 ms 1016 KB Output is correct
52 Correct 100 ms 1016 KB Output is correct
53 Correct 101 ms 1016 KB Output is correct
54 Correct 91 ms 888 KB Output is correct
55 Correct 102 ms 1016 KB Output is correct
56 Correct 107 ms 1016 KB Output is correct
57 Correct 98 ms 892 KB Output is correct
58 Correct 95 ms 1040 KB Output is correct
59 Correct 92 ms 1016 KB Output is correct
60 Correct 100 ms 1016 KB Output is correct