#include "park.h"
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
const ll maxn = 1405;
static int Place[1400];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll random(ll l ,ll r)
{
ll x = rng();
return (abs(x)%(r-l+1)+l);
}
ll t, n;
vector<pll> Edge;
ll par[maxn];
ll find_par(ll v)
{
if(v==par[v]) return v;
else return par[v] = find_par(par[v]);
}
bool mid(ll a, ll b, ll c)
{
if(a>c) swap(a, c);
//cout << a << " " << b << " " << c << "\n";
for(int i = 0; i< n; i++) Place[i] = 1;
Place[b] = 0;
return !Ask(a, c, Place);
}
bool adj(ll a, ll b)
{
if(a>b) swap(a, b);
//cout << a << " " << b << "\n";
for(int i = 0; i< n; i++) Place[i] = 0;
Place[a] = Place[b] = 1;
return Ask(a, b, Place);
}
void Answ()
{
for(auto u: Edge)
{
if(u.fi>u.se) swap(u.fi, u.se);
//cout << u.fi << " " << u.se << "\n";
Answer(u.fi, u.se);
}
}
namespace task1
{
void solve()
{
for(int i = 0; i< n; i++)
{
for(int j = i+1; j< n; j++)
{
if(adj(i, j)) Edge.push_back(mp(i, j));
}
}
Answ();
}
}
namespace task2
{
void dfs(ll a, ll b, vector<ll> T)
{
if(T.size()==0)
{
Edge.push_back(mp(a, b));
return;
}
vector<ll> A, B;
ll x = T[random(0, T.size()-1)];
for(auto u: T)
{
if(u==x) continue;
if(mid(a, u, x)) A.push_back(u);
else B.push_back(u);
}
dfs(a, x, A);
dfs(b, x ,B);
}
void solve()
{
vector<ll> T;
for(int i = 1; i< n-1; i++) T.push_back(i);
dfs(0, n-1, T);
Answ();
}
}
namespace task3
{
vector<ll> T[maxn];
bool chk[maxn];
ll Last[maxn] = {};
ll ptr[maxn] = {};
void dfs(ll a, ll b)
{
//cout << a << " " << b << " " << Last[b] << "\n";
//cout << T[a].size() << "\n";
if(ptr[b]==T[a].size()&&Last[b]==a) return;
Last[b] = a;
bool done = 0;
for(; ptr[b]< T[a].size(); ptr[b]++)
{
if(mid(0, T[a][ptr[b]], b))
{
ll save = ptr[b];
ptr[b] = 0;
dfs(T[a][save], b);
done = 1;
break;
}
}
if(!done)
{
Last[b] = a;
if(adj(a, b))
{
chk[b] = 1;
T[a].push_back(b);
Edge.push_back(mp(a, b));
return;
}
return;
}
}
void solve()
{
queue<ll> q;
for(int i = 0; i< n; i++) Last[i] = -1;
vector<ll> rr;
for(int i = 1; i< n; i++) rr.push_back(i);
random_shuffle(rr.begin(), rr.end());
for(auto u: rr) q.push(u);
int ti = 0;
while(!q.empty())
{
ti++;
ll x = q.front();
q.pop();
dfs(max(0,Last[x]), x);
if(chk[x]) continue;
q.push(x);
}
Answ();
}
}
void Detect(int xaa, int xa) {
t = xaa; n = xa;
if(t==1) task1::solve();
else if(t==2) task2::solve();
else if(t==3) task3::solve();
else task3::solve();
}
Compilation message
park.cpp: In function 'void task3::dfs(int, int)':
park.cpp:104:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | if(ptr[b]==T[a].size()&&Last[b]==a) return;
| ~~~~~~^~~~~~~~~~~~~
park.cpp:107:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for(; ptr[b]< T[a].size(); ptr[b]++)
| ~~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
464 KB |
Output is correct |
2 |
Correct |
7 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
207 ms |
792 KB |
Output is correct |
2 |
Correct |
88 ms |
504 KB |
Output is correct |
3 |
Correct |
81 ms |
536 KB |
Output is correct |
4 |
Correct |
185 ms |
568 KB |
Output is correct |
5 |
Correct |
182 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
580 KB |
Output is correct |
2 |
Correct |
500 ms |
592 KB |
Output is correct |
3 |
Correct |
393 ms |
448 KB |
Output is correct |
4 |
Correct |
291 ms |
436 KB |
Output is correct |
5 |
Correct |
362 ms |
432 KB |
Output is correct |
6 |
Correct |
387 ms |
596 KB |
Output is correct |
7 |
Correct |
321 ms |
456 KB |
Output is correct |
8 |
Correct |
459 ms |
440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
323 ms |
416 KB |
Output is correct |
2 |
Incorrect |
308 ms |
440 KB |
Wrong Answer[5] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2073 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |