답안 #521787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521787 2022-02-03T06:34:08 Z qwerasdfzxcl Park (JOI17_park) C++14
67 / 100
325 ms 860 KB
#include "park.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

static int Place[1400];
int a[2020];

int ask(int x, int y){return Ask(min(x, y), max(x, y), Place);}

set<int> st[2020];
void answer(int x, int y){
    if (x>y) swap(x, y);
    if (st[x].find(y)!=st[x].end()) return;
    st[x].insert(y);
    Answer(x, y);
}

void _sort(int n){
    vector<int> ans = {0};

    for (int i=1;i<n;i++){
        fill(Place, Place+1400, 1);

        int l = 1, r = (int)ans.size()-1, idx = 0;
        while(l<=r){
            int m = (l+r)>>1;
            for (int j=m;j<(int)ans.size();j++) Place[ans[j]] = 0;

            if (ask(0, i)) r = m-1;
            else l = m+1, idx = m;

            for (int j=m;j<(int)ans.size();j++) Place[ans[j]] = 1;
        }
        ans.insert(ans.begin()+idx+1, i);
    }
    for (int i=0;i<n;i++) a[i] = ans[i];
}

vector<pair<int, int>> D;
vector<int> N0;
int cnt = 1;

void Find(int x){
    //for (auto &p:D) printf("(%d, %d) ", p.first, p.second);
    //printf("\n");
    fill(Place, Place+1400, 0);
    for (auto &p:D) Place[p.first] = 1;
    Place[x] = 1;

    int l = 1, r = cnt-1, idx = 0;
    while(l<=r){
        int m = (l+r)>>1;
        for (int i=m;i<cnt;i++) Place[D[i].first] = 0;

        if (!ask(0, x)) idx = m, l = m+1;
        else r = m-1;

        for (int i=m;i<cnt;i++) Place[D[i].first] = 1;
    }
    answer(D[idx].first, x);

    if (idx==0){
        N0.push_back(x);
    }

    else{
        Place[D[idx].first] = 0;
        int prv = idx, ans = -1;
        while(ask(0, x)){
            l = prv+1, r = cnt-1, ans = -1;
            while(l<=r){
                int m = (l+r)>>1;
                for (int i=m;i<cnt;i++) Place[D[i].first] = 0;

                if (!ask(0, x)) ans = m, l = m+1;
                else r = m-1;

                for (int i=m;i<cnt;i++) Place[D[i].first] = 1;
            }

            assert(ans!=-1);
            answer(D[ans].first, x);
            Place[D[ans].first] = 0;

            prv = ans;
        }
    }


    int pt = 0;
    for (;pt<cnt;pt++) if (D[pt].second > D[idx].second+1) break;
    D.insert(D.begin()+pt, make_pair(x, D[idx].second+1));
    cnt++;
}

void solveN0(int n){
    fill(Place, Place+1400, 0);
    Place[0] = 1;
    for (auto &x:N0) Place[x] = 1;

    for (int i=1;i<n;i++) if (!Place[i]){
        Place[i] = 1;
        if (ask(0, i)){
            for (auto &x:N0) Place[x] = 0;
            for (auto &x:N0){
                Place[x] = 1;
                if (ask(0, i)) answer(x, i);
                Place[x] = 0;
            }
            for (auto &x:N0) Place[x] = 1;
        }
        Place[i] = 0;
    }

    fill(Place, Place+1400, 0);
    for (int i=0;i<(int)N0.size();i++){
        for (int j=i+1;j<(int)N0.size();j++){
            Place[N0[i]] = Place[N0[j]] = 1;
            if (ask(N0[i], N0[j])) answer(N0[i], N0[j]);
            Place[N0[i]] = Place[N0[j]] = 0;
        }
    }
}

void Detect(int T, int N) {
    for (int i=1;i<N;i++) a[i] = i;
    _sort(N);

    //printf("A = ");
    //for (int i=0;i<N;i++) printf("%d ", a[i]);
    //printf("\n");

    D.emplace_back(0, 0);
    for (int i=1;i<N;i++){
        Find(a[i]);
    }

    solveN0(N);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Wrong Answer[6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 325 ms 552 KB Output is correct
2 Correct 138 ms 520 KB Output is correct
3 Correct 143 ms 536 KB Output is correct
4 Correct 319 ms 544 KB Output is correct
5 Correct 319 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 246 ms 644 KB Output is correct
2 Correct 239 ms 460 KB Output is correct
3 Correct 247 ms 460 KB Output is correct
4 Correct 237 ms 612 KB Output is correct
5 Correct 267 ms 484 KB Output is correct
6 Correct 243 ms 460 KB Output is correct
7 Correct 249 ms 860 KB Output is correct
8 Correct 242 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 472 KB Output is correct
2 Correct 256 ms 636 KB Output is correct
3 Correct 238 ms 488 KB Output is correct
4 Correct 253 ms 476 KB Output is correct
5 Correct 260 ms 580 KB Output is correct
6 Correct 279 ms 588 KB Output is correct
7 Correct 262 ms 460 KB Output is correct
8 Correct 251 ms 472 KB Output is correct
9 Correct 247 ms 488 KB Output is correct
10 Correct 258 ms 504 KB Output is correct
11 Correct 266 ms 580 KB Output is correct
12 Correct 256 ms 460 KB Output is correct
13 Correct 263 ms 492 KB Output is correct
14 Correct 259 ms 492 KB Output is correct
15 Correct 265 ms 524 KB Output is correct
16 Correct 247 ms 484 KB Output is correct
17 Correct 312 ms 604 KB Output is correct
18 Correct 272 ms 460 KB Output is correct
19 Correct 289 ms 568 KB Output is correct
20 Correct 252 ms 540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 252 ms 552 KB Wrong Answer[2]
2 Halted 0 ms 0 KB -