# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
229290 | 534351 | 로카히아 유적 (FXCUP4_lokahia) | C++17 | 6 ms | 688 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
map<int, int> mp[213];
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)
{
vi bucket, lis;
FOR(i, 0, N)
{
if (!lis.empty() && ask(lis.back(), i) != -1)
{
bucket.PB(i);
continue;
}
else
{
lis.PB(i);
if (!bucket.empty())
{
lis.PB(bucket.back());
bucket.pop_back();
}
}
}
int cand = lis.back(); bucket.PB(cand);
// for (int x : lis)
// {
// cerr << x << ' ';
// }
// cerr << endl;
// cerr << "cand = " << bucket.back() << endl;
int maj = cand, num = 1;
while(!bucket.empty() && !lis.empty())
{
int x = cand, T = bucket.back();
int n = ask(x, T);
if (n == -1)
{
lis.pop_back();
bucket.pop_back();
}
else
{
lis.pop_back();
if (!lis.empty()) lis.pop_back();
if (n == maj)
{
num++;
}
else
{
num--;
if (num == -1)
{
num = 1;
maj = n;
}
}
}
}
// cerr << "cand = " << cand << " maj = " << maj << endl;
return (bucket.empty() ? -1 : maj);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |