#include "lokahia.h"
#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
const int MAXN = 213;
map<int, int> mp[MAXN];
int dsu[MAXN], stor[MAXN];
int get(int u)
{
return (u == dsu[u] ? u : dsu[u] = get(dsu[u]));
}
void merge(int u, int v)
{
u = get(u);
v = get(v);
if (u == v) return;
ckmax(stor[u], stor[v]);
dsu[v] = u;
return;
}
int ask(int i, int j)
{
if (i == j) return i;
if (mp[i].count(j))
{
return mp[i][j];
}
int res = CollectRelics(i, j);
mp[i][j] = res;
mp[j][i] = res;
// cerr << "ask " << i << ' ' << j << " = " << res << endl;
return res;
}
int FindBase(int N)
{
assert(N >= 2);
return -2;
if (N == 0)
{
return 1;
}
if (N == 1)
{
return ask(0, 1);
}
vi bucket, lis;
FOR(i, 0, N)
{
if (!lis.empty() && ask(lis.back(), i) != -1)
{
int x = ask(lis.back(), i);
merge(lis.back(), i);
if (lis.back() != i) ckmax(stor[get(i)], x);
bucket.PB(i);
continue;
}
else
{
lis.PB(i);
if (!bucket.empty())
{
lis.PB(bucket.back());
bucket.pop_back();
}
}
}
int cand = lis.back();
// for (int x : lis)
// {
// cerr << x << ' ';
// }
// cerr << endl;
// cerr << "cand = " << bucket.back() << endl;
int maj = -1, num = 0;
while(!lis.empty())
{
int n = ask(cand, lis.back());
if (n == -1)
{
lis.pop_back();
if (bucket.empty())
{
break;
}
bucket.pop_back();
}
else
{
merge(lis.back(), cand);
if (lis.back() != cand)
{
ckmax(stor[get(cand)], n);
}
if (SZ(lis) == 1)
{
bucket.PB(lis.back());
lis.pop_back();
}
else
{
lis.pop_back();
lis.pop_back();
}
}
}
if (bucket.empty()) return -1;
return stor[get(cand)];
// cerr << "cand = " << cand << " maj = " << maj << endl;
}
Compilation message
lokahia.cpp: In function 'int FindBase(int)':
lokahia.cpp:109:9: warning: unused variable 'maj' [-Wunused-variable]
int maj = -1, num = 0;
^~~
lokahia.cpp:109:19: warning: unused variable 'num' [-Wunused-variable]
int maj = -1, num = 0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
512 KB |
Wrong |
2 |
Incorrect |
5 ms |
640 KB |
Wrong |
3 |
Incorrect |
5 ms |
640 KB |
Wrong |
4 |
Incorrect |
5 ms |
640 KB |
Wrong |
5 |
Incorrect |
5 ms |
640 KB |
Wrong |
6 |
Incorrect |
5 ms |
640 KB |
Wrong |
7 |
Incorrect |
5 ms |
640 KB |
Wrong |
8 |
Incorrect |
5 ms |
640 KB |
Wrong |
9 |
Incorrect |
4 ms |
512 KB |
Wrong |
10 |
Incorrect |
5 ms |
512 KB |
Wrong |
11 |
Incorrect |
5 ms |
640 KB |
Wrong |
12 |
Incorrect |
5 ms |
640 KB |
Wrong |
13 |
Incorrect |
5 ms |
640 KB |
Wrong |
14 |
Runtime error |
5 ms |
768 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Incorrect |
5 ms |
640 KB |
Wrong |
16 |
Incorrect |
5 ms |
512 KB |
Wrong |
17 |
Incorrect |
5 ms |
640 KB |
Wrong |
18 |
Incorrect |
5 ms |
640 KB |
Wrong |
19 |
Incorrect |
5 ms |
640 KB |
Wrong |
20 |
Incorrect |
5 ms |
640 KB |
Wrong |
21 |
Incorrect |
5 ms |
640 KB |
Wrong |
22 |
Incorrect |
5 ms |
640 KB |
Wrong |
23 |
Incorrect |
5 ms |
640 KB |
Wrong |
24 |
Incorrect |
5 ms |
512 KB |
Wrong |
25 |
Incorrect |
5 ms |
640 KB |
Wrong |
26 |
Incorrect |
5 ms |
640 KB |
Wrong |
27 |
Incorrect |
5 ms |
512 KB |
Wrong |