답안 #229293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229293 2020-05-04T06:30:20 Z 534351 로카히아 유적 (FXCUP4_lokahia) C++17
0 / 100
5 ms 640 KB
#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();
			}
		}
	}
    //01010
    int cand = lis.back();
    // for (int x : lis)
    // {
    //     cerr << x << ' ';
    // }
    // cerr << endl;
    // cerr << "cand = " << bucket.back() << endl;
    int maj = cand, num = 0;
	while(!lis.empty())
	{
		int x = cand, T = lis.back();
        int n = ask(x, T);
        if (n == -1)
        {
            lis.pop_back();
            if (bucket.empty())
            {
                break;
            }
            bucket.pop_back();
        }
        else
        {
            if (SZ(lis) == 1)
            {
                bucket.PB(lis.back());
                lis.pop_back();
            }
            else
            {
                lis.pop_back();
                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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Correct : C = 119
2 Correct 5 ms 640 KB Correct : C = 199
3 Correct 5 ms 640 KB Correct : C = 279
4 Incorrect 5 ms 640 KB Wrong
5 Correct 5 ms 640 KB Correct : C = 119
6 Incorrect 5 ms 512 KB Wrong
7 Correct 5 ms 640 KB Correct : C = 281
8 Correct 5 ms 512 KB Correct : C = 0
9 Correct 5 ms 640 KB Correct : C = 176
10 Correct 5 ms 640 KB Correct : C = 295
11 Correct 5 ms 640 KB Correct : C = 297
12 Correct 5 ms 640 KB Correct : C = 171
13 Correct 5 ms 640 KB Correct : C = 177
14 Correct 5 ms 640 KB Correct : C = 295
15 Correct 5 ms 640 KB Correct : C = 297
16 Correct 5 ms 640 KB Correct : C = 176
17 Correct 5 ms 640 KB Correct : C = 177
18 Correct 5 ms 640 KB Correct : C = 200
19 Correct 5 ms 640 KB Correct : C = 296
20 Incorrect 5 ms 640 KB Wrong
21 Correct 5 ms 640 KB Correct : C = 282
22 Incorrect 5 ms 640 KB Wrong
23 Correct 5 ms 640 KB Correct : C = 298
24 Correct 5 ms 640 KB Correct : C = 200
25 Incorrect 5 ms 640 KB Wrong
26 Correct 5 ms 640 KB Correct : C = 199
27 Correct 5 ms 640 KB Correct : C = 120