#include "lokahia.h"
#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;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int used[222];
int rtnumber[222];
map<ii,int> ma;
int ask(int u, int v)
{
if(ma.find({u,v})!=ma.end()) return ma[{u,v}];
return (ma[{u,v}]=ma[{v,u}]=CollectRelics(u,v));
}
int FindBase(int N)
{
int n=N;
if(n==1) return 0;
if(n==2)
{
return ask(0,1);
}
memset(used,0,sizeof(used));
set<int> S;
int rt=-1;
for(int i=0;i<n;i++)
{
if(used[i]) continue;
if(rt==-1)
{
S.insert(i); used[i]=1; rt=i; continue;
}
int newrt = ask(rt,i);
if(newrt==-1)
{
auto it = (prev(S.end()));
if(S.size()==1)
{
used[rt]=used[i]=1;
S.clear(); rt=-1; continue;
}
while((*it)==rt)
{
it--;
}
S.erase(it);
used[i]=1;
continue;
}
S.insert(i);
S.insert(newrt);
used[i]=used[newrt]=1;
rt=newrt;
}
if(S.empty())
{
return -1;
}
int u = (*S.begin());
int mx=-1;
int cnt=1;
for(int i=0;i<n;i++)
{
if(i!=u)
{
rtnumber[i]=ask(i,u);
if(rtnumber[i]>=0) cnt++;
mx=max(mx,rtnumber[i]);
}
}
if(cnt*2>n) return mx;
else return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Correct : C = 7 |
2 |
Partially correct |
3 ms |
760 KB |
Partially correct : C = 396 |
3 |
Partially correct |
3 ms |
632 KB |
Partially correct : C = 344 |
4 |
Correct |
2 ms |
504 KB |
Correct : C = 125 |
5 |
Partially correct |
3 ms |
760 KB |
Partially correct : C = 394 |
6 |
Partially correct |
3 ms |
632 KB |
Partially correct : C = 394 |
7 |
Correct |
2 ms |
632 KB |
Correct : C = 236 |
8 |
Correct |
3 ms |
632 KB |
Correct : C = 206 |
9 |
Correct |
2 ms |
504 KB |
Correct : C = 177 |
10 |
Correct |
3 ms |
632 KB |
Correct : C = 211 |
11 |
Correct |
2 ms |
632 KB |
Correct : C = 209 |
12 |
Partially correct |
3 ms |
632 KB |
Partially correct : C = 396 |
13 |
Correct |
3 ms |
632 KB |
Correct : C = 204 |
14 |
Correct |
2 ms |
504 KB |
Correct : C = 234 |
15 |
Correct |
2 ms |
632 KB |
Correct : C = 231 |
16 |
Correct |
3 ms |
632 KB |
Correct : C = 128 |
17 |
Correct |
2 ms |
632 KB |
Correct : C = 126 |
18 |
Correct |
3 ms |
632 KB |
Correct : C = 100 |
19 |
Partially correct |
3 ms |
632 KB |
Partially correct : C = 386 |
20 |
Partially correct |
3 ms |
632 KB |
Partially correct : C = 303 |
21 |
Partially correct |
3 ms |
632 KB |
Partially correct : C = 382 |
22 |
Correct |
2 ms |
504 KB |
Correct : C = 123 |
23 |
Correct |
2 ms |
636 KB |
Correct : C = 60 |
24 |
Correct |
3 ms |
632 KB |
Correct : C = 235 |
25 |
Correct |
2 ms |
376 KB |
Correct : C = 0 |
26 |
Partially correct |
3 ms |
632 KB |
Partially correct : C = 382 |
27 |
Correct |
3 ms |
632 KB |
Correct : C = 297 |