110222024-06-13 06:57:00hogyKutyák és macskákcpp17Accepted 100/1001.05s612 KiB
#include "KutyakMacskak.h"

#include <vector>
#include <algorithm>
#include <numeric>
#include <deque>

using namespace std;

void insertion_sort(vector<int>& group, int dog) {
    auto cmp = [dog](int c1, int c2) -> bool {
        return ask(dog, c1, c2) == c1 ? true : false;
    };
    for (int i=1; i<(int)group.size(); ++i) {
        int lo = -1, hi = i;
        while (lo+1 < hi) {
            int mid = (lo+hi)/2;
            if (!cmp(group[mid], group[i]))
                hi = mid;
            else
                lo = mid;
        }
        for (int j=i; j>hi; --j)
            swap(group[j-1], group[j]);
    }
}
vector<int> find_order(int N, int M) {
    vector<int> cats(M);
    iota(cats.begin(), cats.end(), 1);
    insertion_sort(cats, 1);
    int nearcat = cats[0], farcat = cats[M-1];
    int X = 2;
    while (ask(X, nearcat, farcat) == nearcat)
        ++X;
    vector<bool> is_opposite(M, false);
    for (int j = 1; j+1 < M; ++j) {
        int cat = cats[j];
        if (ask(X, cat, nearcat) == nearcat)
            is_opposite[j] = true;
    }
    deque<int> ord({cats[0]});
    for (int j=1; j<M; ++j) {
        if (is_opposite[j])
            ord.push_front(cats[j]);
        else
            ord.push_back(cats[j]);
    }
    return vector<int>(ord.begin(), ord.end());
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms356 KiB
2Accepted908ms612 KiB
subtask26/6
3Accepted984ms424 KiB
4Accepted985ms504 KiB
5Accepted1.001s360 KiB
6Accepted972ms508 KiB
7Accepted961ms484 KiB
subtask37/7
8Accepted4ms436 KiB
9Accepted4ms548 KiB
10Accepted3ms408 KiB
11Accepted4ms504 KiB
12Accepted4ms396 KiB
13Accepted28ms384 KiB
14Accepted35ms384 KiB
subtask410/10
15Accepted8ms356 KiB
16Accepted8ms384 KiB
17Accepted8ms356 KiB
18Accepted9ms396 KiB
19Accepted8ms228 KiB
20Accepted9ms396 KiB
21Accepted8ms300 KiB
22Accepted9ms256 KiB
23Accepted10ms300 KiB
24Accepted12ms360 KiB
25Accepted12ms384 KiB
26Accepted12ms360 KiB
27Accepted9ms512 KiB
28Accepted8ms256 KiB
29Accepted10ms416 KiB
subtask512/12
30Accepted8ms356 KiB
31Accepted8ms384 KiB
32Accepted8ms356 KiB
33Accepted9ms396 KiB
34Accepted8ms228 KiB
35Accepted9ms396 KiB
36Accepted8ms300 KiB
37Accepted9ms256 KiB
38Accepted10ms300 KiB
39Accepted12ms360 KiB
40Accepted12ms384 KiB
41Accepted12ms360 KiB
42Accepted9ms512 KiB
43Accepted8ms256 KiB
44Accepted10ms416 KiB
45Accepted43ms316 KiB
46Accepted32ms492 KiB
47Accepted43ms420 KiB
48Accepted37ms420 KiB
49Accepted50ms536 KiB
50Accepted41ms424 KiB
51Accepted41ms384 KiB
52Accepted45ms528 KiB
53Accepted45ms356 KiB
54Accepted54ms420 KiB
55Accepted57ms360 KiB
56Accepted46ms532 KiB
57Accepted46ms492 KiB
58Accepted46ms384 KiB
59Accepted50ms384 KiB
subtask665/65
60Accepted3ms376 KiB
61Accepted977ms428 KiB
62Accepted984ms424 KiB
63Accepted985ms504 KiB
64Accepted1.001s360 KiB
65Accepted972ms508 KiB
66Accepted961ms484 KiB
67Accepted4ms436 KiB
68Accepted4ms548 KiB
69Accepted3ms408 KiB
70Accepted4ms504 KiB
71Accepted4ms396 KiB
72Accepted28ms384 KiB
73Accepted35ms384 KiB
74Accepted8ms356 KiB
75Accepted8ms384 KiB
76Accepted8ms356 KiB
77Accepted9ms396 KiB
78Accepted8ms228 KiB
79Accepted9ms396 KiB
80Accepted8ms300 KiB
81Accepted9ms256 KiB
82Accepted10ms300 KiB
83Accepted12ms360 KiB
84Accepted12ms384 KiB
85Accepted12ms360 KiB
86Accepted9ms512 KiB
87Accepted8ms256 KiB
88Accepted10ms416 KiB
89Accepted43ms316 KiB
90Accepted32ms492 KiB
91Accepted43ms420 KiB
92Accepted37ms420 KiB
93Accepted50ms536 KiB
94Accepted41ms424 KiB
95Accepted41ms384 KiB
96Accepted45ms528 KiB
97Accepted45ms356 KiB
98Accepted54ms420 KiB
99Accepted57ms360 KiB
100Accepted46ms532 KiB
101Accepted46ms492 KiB
102Accepted46ms384 KiB
103Accepted50ms384 KiB
104Accepted981ms432 KiB
105Accepted986ms484 KiB
106Accepted984ms544 KiB
107Accepted976ms440 KiB
108Accepted981ms428 KiB
109Accepted1.013s540 KiB
110Accepted1.016s424 KiB
111Accepted995ms428 KiB
112Accepted972ms432 KiB
113Accepted991ms496 KiB
114Accepted986ms488 KiB
115Accepted977ms484 KiB
116Accepted1.023s484 KiB
117Accepted1.037s424 KiB
118Accepted1.039s552 KiB
119Accepted1.041s432 KiB
120Accepted1.031s428 KiB
121Accepted1.004s428 KiB
122Accepted999ms372 KiB
123Accepted986ms428 KiB
124Accepted995ms444 KiB
125Accepted981ms424 KiB
126Accepted1.031s532 KiB
127Accepted1.049s548 KiB
128Accepted1.05s500 KiB
129Accepted1.039s436 KiB
130Accepted1.026s420 KiB
131Accepted967ms428 KiB
132Accepted958ms484 KiB