# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
957964 |
2024-04-04T15:01:30 Z |
Soumya1 |
Park (JOI17_park) |
C++17 |
|
235 ms |
772 KB |
#include "park.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1405;
vector<int> ad[mxN], edges[mxN];
int added[mxN];
int ask[mxN];
int n;
vector<int> all;
bool bad[mxN];
void get(int u) {
all.push_back(u);
for (int v : ad[u]) {
if (bad[v]) continue;
get(v);
}
}
int find_first(vector<int> nodes, int u) {
for (int i = 0; i < n; i++) ask[i] = 0;
for (int i : nodes) ask[i] = 1;
ask[u] = 1;
if (!Ask(nodes[0], u, ask)) return -1;
int lo = 0, hi = nodes.size() - 1;
while (lo < hi) {
int mid = (lo + hi) >> 1;
for (int i = 0; i < n; i++) ask[i] = 0;
for (int i = 0; i <= mid; i++) ask[nodes[i]] = 1;
ask[u] = 1;
if (Ask(nodes[0], u, ask)) hi = mid;
else lo = mid + 1;
}
return nodes[lo];
}
void dfs(int u) {
for (int i = 0; i < n; i++) ask[i] = added[i];
ask[u] = 1;
while (!Ask(0, u, ask)) {
int lo = 0, hi = n - 1;
while (lo < hi) {
int mid = (lo + hi) >> 1;
for (int i = 0; i < n; i++) {
ask[i] = (added[i] || i <= mid);
}
ask[0] = ask[u] = 1;
if (Ask(0, u, ask)) hi = mid;
else lo = mid + 1;
}
dfs(lo);
for (int i = 0; i < n; i++) ask[i] = added[i];
ask[u] = 1;
}
for (int i = 0; i < n; i++) bad[i] = false;
vector<int> roots;
roots.push_back(0);
int some = -1;
for (int i = 0; i < roots.size(); i++) {
int x = roots[i];
while (true) {
all.clear();
get(x);
int v = find_first(all, u);
if (v == -1) break;
some = v;
bad[v] = true;
edges[v].push_back(u);
for (int childs : ad[v]) roots.push_back(childs);
if (v == x) break;
}
}
ad[some].push_back(u);
added[u] = 1;
}
void Detect(int T, int N) {
n = N;
added[0] = 1;
for (int i = 1; i < N; i++) {
if (!added[i]) {
dfs(i);
}
}
for (int i = 0; i < n; i++) {
for (int j : edges[i]) {
Answer(min(i, j), max(i, j));
}
}
}
Compilation message
park.cpp: In function 'void dfs(int)':
park.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i = 0; i < roots.size(); i++) {
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Wrong Answer[4] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
234 ms |
684 KB |
Output is correct |
2 |
Correct |
87 ms |
772 KB |
Output is correct |
3 |
Correct |
129 ms |
772 KB |
Output is correct |
4 |
Correct |
235 ms |
604 KB |
Output is correct |
5 |
Correct |
234 ms |
752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Wrong Answer[4] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Wrong Answer[4] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
600 KB |
Wrong Answer[4] |
2 |
Halted |
0 ms |
0 KB |
- |