# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
430210 |
2021-06-16T12:08:45 Z |
8e7 |
Park (JOI17_park) |
C++14 |
|
1155 ms |
588 KB |
#include "park.h"
//Challenge: Accepted
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <random>
#include <time.h>
#include <assert.h>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
//using namespace __gnu_pbds;
void debug() {cout << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cout << a << " "; debug(b...);}
template <class T> void pary(T l, T r) {
while (l != r) {cout << *l << " ";l++;}
cout << endl;
}
#define ll long long
#define ld long double
#define maxn 1405
#define mod 1000000007
#define pii pair<long long, long long>
#define ff first
#define ss second
static int que[maxn];
vector<pii> ed;
int qcnt = 0;
void group(vector<int> root, vector<int> nom, int cent, vector<vector<int> > & rec);
int query(int a, int b) {
if (a > b) swap(a, b);
if (a == b || (que[a] == 0) || (que[b] == 0)) return 0;
qcnt++;
return Ask(a, b, que);
}
void solve(vector<int> v) {
//pary(v.begin(), v.end());
if (v.size() < 2) return;
if (v.size() == 2) {
ed.push_back({v[0], v[1]});
return;
}
//debug(v.size());
random_shuffle(v.begin(), v.end());
int cent = v[0];
for (int i = 0;i < maxn;i++) que[i] = 0;
for (int i:v) que[i] = 1;
if (v.size() > 5) {
int num = 5, ma = 0, best = 0, f = 0;
for (int i:v) {
que[i] = 0;
int cnt = 0;
for (int j = 0;j < num;j++) {
int ix = rand() % v.size(), iy = rand() % v.size();
if (v[ix] == i) ix = (ix + 1) % v.size();
while (iy == ix || v[iy] == i) {
iy = (iy + 1) % v.size();
}
cnt += query(v[ix], v[iy]) ? 0 : 1;
}
que[i] = 1;
if (cnt > ma) {
ma = cnt, best = i;
}
if (cnt > (num / 2)) {
cent = i, f = 1;
break;
}
}
if (!f) cent = best;
}
//debug(cent);
for (int i:v) que[i] = 0;
que[cent] = 1;
vector<int> adj, sub;
for (int i:v) {
if (i == cent) continue;
que[i] = 1;
if (query(i, cent)) {
ed.push_back({i, cent}), adj.push_back(i);
} else {
sub.push_back(i);
}
que[i] = 0;
}
for (int i:v) que[i] = 1;
vector<vector<int> > rec;
group(adj, sub, cent, rec);
for (int i:v) que[i] = 0;
int siz = 0;
//debug(cent);
for (auto i:rec) {
siz += i.size();
solve(i);
}
//assert(siz == v.size() - 1);
}
void group(vector<int> root, vector<int> nom, int cent, vector<vector<int> > &rec) {
if (root.size() == 0) return;
if (root.size() == 1) {
nom.push_back(root[0]);
rec.push_back(nom);
return;
}
vector<int> ar, br, an, bn;
for (int i = 0;i < root.size();i++) {
if (i < (root.size() / 2)) ar.push_back(root[i]);
else br.push_back(root[i]);
}
for (int i:ar) que[i] = 0;
for (int i:nom) {
if (!query(i, cent)) {
an.push_back(i);
} else {
bn.push_back(i);
}
}
for (int i:ar) que[i] = 1;
group(ar, an, cent, rec), group(br, bn, cent, rec);
}
void Detect(int T, int N) {
srand(time(NULL));
vector<int> ini;
for (int i = 0;i < N;i++) ini.push_back(i);
solve(ini);
//debug(qcnt);
//assert(ed.size() == N - 1);
for (auto i:ed) {
if (i.ff > i.ss) swap(i.ff, i.ss);
Answer(i.ff, i.ss);
}
}
/*
4
10 9
0 1
0 2
1 3
2 4
1 5
2 6
2 7
7 8
5 9
4
8 7
0 1
0 2
0 3
0 4
0 5
0 6
0 7
*/
Compilation message
park.cpp: In function 'void group(std::vector<int>, std::vector<int>, int, std::vector<std::vector<int> >&)':
park.cpp:112:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for (int i = 0;i < root.size();i++) {
| ~~^~~~~~~~~~~~~
park.cpp:113:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | if (i < (root.size() / 2)) ar.push_back(root[i]);
| ~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Wrong Answer[2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
556 KB |
Output is correct |
2 |
Correct |
43 ms |
556 KB |
Output is correct |
3 |
Correct |
47 ms |
584 KB |
Output is correct |
4 |
Correct |
60 ms |
460 KB |
Output is correct |
5 |
Correct |
88 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
548 KB |
Output is correct |
2 |
Correct |
141 ms |
484 KB |
Output is correct |
3 |
Correct |
190 ms |
448 KB |
Output is correct |
4 |
Correct |
105 ms |
440 KB |
Output is correct |
5 |
Correct |
270 ms |
408 KB |
Output is correct |
6 |
Correct |
315 ms |
540 KB |
Output is correct |
7 |
Correct |
119 ms |
412 KB |
Output is correct |
8 |
Correct |
169 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
404 KB |
Output is correct |
2 |
Correct |
99 ms |
572 KB |
Output is correct |
3 |
Correct |
79 ms |
456 KB |
Output is correct |
4 |
Correct |
134 ms |
516 KB |
Output is correct |
5 |
Correct |
83 ms |
440 KB |
Output is correct |
6 |
Correct |
109 ms |
460 KB |
Output is correct |
7 |
Correct |
106 ms |
472 KB |
Output is correct |
8 |
Correct |
136 ms |
520 KB |
Output is correct |
9 |
Correct |
155 ms |
448 KB |
Output is correct |
10 |
Correct |
94 ms |
572 KB |
Output is correct |
11 |
Correct |
84 ms |
512 KB |
Output is correct |
12 |
Correct |
126 ms |
588 KB |
Output is correct |
13 |
Correct |
185 ms |
568 KB |
Output is correct |
14 |
Correct |
113 ms |
580 KB |
Output is correct |
15 |
Correct |
88 ms |
444 KB |
Output is correct |
16 |
Correct |
144 ms |
528 KB |
Output is correct |
17 |
Correct |
71 ms |
580 KB |
Output is correct |
18 |
Correct |
93 ms |
544 KB |
Output is correct |
19 |
Correct |
66 ms |
500 KB |
Output is correct |
20 |
Correct |
144 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1155 ms |
492 KB |
Wrong Answer[5] |
2 |
Halted |
0 ms |
0 KB |
- |