# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
952575 |
2024-03-24T09:47:36 Z |
GrindMachine |
Park (JOI17_park) |
C++17 |
|
358 ms |
848 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "park.h"
void Detect(int T, int n) {
vector<bool> vis(n);
vector<int> depth(n);
vis[0] = 1;
depth[0] = 0;
auto f = [&](int u, int v, vector<int> place){
if(u == v) return 1;
if(u > v) swap(u,v);
int place_arr[n];
rep(i,n) place_arr[i] = place[i];
return Ask(u,v,place_arr);
};
vector<pii> ans;
while(count(all(vis),1) < n){
int u = -1;
rep(i,n){
if(!vis[i]){
u = i;
break;
}
}
// largest depth active guy that is ancestor
vector<pii> active_order;
rep(i,n){
if(vis[i]){
active_order.pb({depth[i],i});
}
}
sort(all(active_order));
int l = 1, r = sz(active_order)-1;
int ances = 0;
while(l <= r){
int mid = (l+r) >> 1;
vector<int> place(n,1);
for(int i = mid; i < sz(active_order); ++i){
place[active_order[i].ss] = 0;
}
int res = f(u,0,place);
if(!res){
ances = active_order[mid].ss;
l = mid+1;
}
else{
r = mid-1;
}
}
vis[u] = 1;
vector<int> nodes;
nodes.pb(u);
while(true){
int l = 0, r = n-1;
int pos = -1;
vector<int> place(n);
while(l <= r){
int mid = (l+r) >> 1;
fill(all(place),1);
rep(i,mid+1){
if(!vis[i]){
place[i] = 0;
}
}
int res = f(u,0,place);
if(!res){
pos = mid;
r = mid-1;
}
else{
l = mid+1;
}
}
if(pos == -1) break;
nodes.pb(pos);
vis[pos] = 1;
}
auto cmp = [&](int u, int v){
vector<int> place(n,1);
place[u] = 0;
int res = f(0,v,place);
return !res;
};
stable_sort(all(nodes),cmp);
nodes.insert(nodes.begin(),ances);
rep1(i,sz(nodes)-1){
int u = nodes[i], p = nodes[i-1];
depth[u] = depth[p]+1;
ans.pb({u,p});
}
}
for(auto [u,v] : ans){
if(u > v) swap(u,v);
Answer(u,v);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Wrong Answer[2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
209 ms |
624 KB |
Output is correct |
2 |
Correct |
195 ms |
584 KB |
Output is correct |
3 |
Correct |
184 ms |
620 KB |
Output is correct |
4 |
Correct |
221 ms |
648 KB |
Output is correct |
5 |
Correct |
217 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
287 ms |
576 KB |
Output is correct |
2 |
Correct |
310 ms |
580 KB |
Output is correct |
3 |
Correct |
300 ms |
348 KB |
Output is correct |
4 |
Correct |
284 ms |
580 KB |
Output is correct |
5 |
Correct |
300 ms |
344 KB |
Output is correct |
6 |
Correct |
296 ms |
596 KB |
Output is correct |
7 |
Correct |
292 ms |
600 KB |
Output is correct |
8 |
Correct |
314 ms |
576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
532 KB |
Output is correct |
2 |
Correct |
289 ms |
556 KB |
Output is correct |
3 |
Correct |
293 ms |
808 KB |
Output is correct |
4 |
Correct |
257 ms |
600 KB |
Output is correct |
5 |
Correct |
273 ms |
848 KB |
Output is correct |
6 |
Correct |
269 ms |
592 KB |
Output is correct |
7 |
Correct |
252 ms |
588 KB |
Output is correct |
8 |
Correct |
267 ms |
344 KB |
Output is correct |
9 |
Correct |
263 ms |
592 KB |
Output is correct |
10 |
Correct |
274 ms |
608 KB |
Output is correct |
11 |
Correct |
259 ms |
608 KB |
Output is correct |
12 |
Correct |
289 ms |
596 KB |
Output is correct |
13 |
Correct |
242 ms |
596 KB |
Output is correct |
14 |
Correct |
284 ms |
584 KB |
Output is correct |
15 |
Correct |
239 ms |
592 KB |
Output is correct |
16 |
Correct |
309 ms |
348 KB |
Output is correct |
17 |
Correct |
229 ms |
600 KB |
Output is correct |
18 |
Correct |
262 ms |
596 KB |
Output is correct |
19 |
Correct |
247 ms |
584 KB |
Output is correct |
20 |
Correct |
275 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
358 ms |
576 KB |
Wrong Answer[2] |
2 |
Halted |
0 ms |
0 KB |
- |