답안 #915430

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915430 2024-01-23T22:44:11 Z alexdd 도서관 (JOI18_library) C++17
0 / 100
31 ms 692 KB
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
int n;
vector<int> con[1005];
vector<pair<int,int>> vecini;
int intreaba(int le, int ri)
{
    le--;
    ri--;
    vector<int> cv(n);
    for(int i=0;i<n;i++)
    {
        if(le<=i && i<=ri)
            cv[i]=1;
        else
            cv[i]=0;
    }
    return Query(cv);
}
vector<int> ord;
void dfs(int nod, int par)
{
    ord.push_back(nod);
    for(auto adj:con[nod])
    {
        if(adj!=par)
        {
            dfs(adj,nod);
        }
    }
}
void Solve(int N)
{
    n=N;
    for(int i=2;i<=n;i++)
    {
        if(intreaba(1,i)==intreaba(1,i-1))
        {
            //cerr<<"caz 1\n";
            ///am un vecin
            int st,dr,mij,ans=1;
            st=1;
            dr=i-1;
            while(st<=dr)
            {
                mij=(st+dr)/2;
                if(intreaba(mij,i)==intreaba(mij,i-1))
                {
                    ans=mij;
                    st=mij+1;
                }
                else
                    dr=mij-1;
            }
            vecini.push_back({ans,i});
        }
        else if(intreaba(1,i)==intreaba(1,i-1)+1)
        {
            //cerr<<"caz 2\n";
            ///nu fac nimic
        }
        else if(intreaba(1,i)==intreaba(1,i-1)-1)
        {
            //cerr<<"caz 3\n";
            //continue;
            ///am 2 vecini
            int st,dr,mij,ans=1;
            st=1;
            dr=i-1;
            while(st<=dr)
            {
                mij=(st+dr)/2;
                if(intreaba(mij,i)<intreaba(mij,i-1))
                {
                    ans=mij;
                    st=mij+1;
                }
                else
                    dr=mij-1;
            }
            vecini.push_back({ans,i});

            ans=1;
            st=1;
            dr=i-1;
            while(st<=dr)
            {
                mij=(st+dr)/2;
                if(intreaba(mij,i)<=intreaba(mij,i-1))
                {
                    ans=mij;
                    st=mij+1;
                }
                else
                    dr=mij-1;
            }
            vecini.push_back({ans,i});
        }
    }
    //for(auto x:vecini)
      //  cerr<<x.first<<" "<<x.second<<" zzz\n";
    for(auto x:vecini)
    {
        con[x.first].push_back(x.second);
        con[x.second].push_back(x.first);
    }
    int capat=-1;
    for(int i=n;i>0;i--)
        if((int)con[i].size()==1)
            capat=i;
    dfs(capat,0);
    //for(auto x:ord)
      //  cout<<x<<" ";

    Answer(ord);
}
/**
5
1 3 2 5 4

5
5 4 3 2 1

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 460 KB # of queries: 3462
2 Correct 25 ms 452 KB # of queries: 3418
3 Correct 28 ms 452 KB # of queries: 3596
4 Correct 25 ms 460 KB # of queries: 3552
5 Correct 26 ms 464 KB # of queries: 3588
6 Correct 24 ms 692 KB # of queries: 3584
7 Correct 28 ms 456 KB # of queries: 3558
8 Correct 31 ms 464 KB # of queries: 3400
9 Correct 24 ms 464 KB # of queries: 3598
10 Correct 16 ms 456 KB # of queries: 2180
11 Incorrect 0 ms 344 KB Wrong Answer [5]
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 460 KB # of queries: 3462
2 Correct 25 ms 452 KB # of queries: 3418
3 Correct 28 ms 452 KB # of queries: 3596
4 Correct 25 ms 460 KB # of queries: 3552
5 Correct 26 ms 464 KB # of queries: 3588
6 Correct 24 ms 692 KB # of queries: 3584
7 Correct 28 ms 456 KB # of queries: 3558
8 Correct 31 ms 464 KB # of queries: 3400
9 Correct 24 ms 464 KB # of queries: 3598
10 Correct 16 ms 456 KB # of queries: 2180
11 Incorrect 0 ms 344 KB Wrong Answer [5]
12 Halted 0 ms 0 KB -