답안 #149731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149731 2019-09-01T07:02:38 Z Ian and 2-bit memory(#3648, percywtc, nhho, ulna) 로카히아 유적 (FXCUP4_lokahia) C++17
0 / 100
40 ms 688 KB
#include <bits/stdc++.h>

using namespace std;

#include "lokahia.h"

int FindBase(int N){
	if (N == 1)
		return 0;
	srand(456);
	int left = 300 - N;
	vector<int> v(N, 1);
	map<pair<int, int>, int> m;
	int cnt = 0;
	while (left) {
		int hv = 0;
		for (int i = 0; i < N; i++)
			if (v[i])
				hv += max(20, v[i]);
		int ta = rand() % hv;
		for (int i = 0; i < N; i++) {
			if (!v[i])
				continue;
			if (ta < max(20, v[i])) {
				ta = i;
				hv -= max(20, v[i]);
				break;
			} else
				ta -= max(20, v[i]);
		}
		if (!hv)
			break;
		int tb = rand() % hv;
		for (int i = 0; i < N; i++) {
			if (!v[i] || i == ta)
				continue;
			if (tb < max(20, v[i])) {
				tb = i;
				break;
		} else
				tb -= max(20, v[i]);
		}
		if (ta > tb)
			swap(ta, tb);
		int tc;
		if (m.count({ta, tb})) {
			tc = m[{ta, tb}];
			cnt++;
			if (cnt == 2000) {
				cnt = 0;
				left--;
			}
		} else {
			m[{ta, tb}] = tc = CollectRelics(ta, tb);
			left--;
			cnt = 0;
		}
		if (tc != -1) {
			if (tc != ta) {
				v[tc] += v[ta];
				v[ta] = 0;
			}
			if (tc != tb) {
				v[tc] += v[tb];
				v[tb] = 0;
			}
		}
	}
	int ans = -1, ma = -1;
	for (int i = 0; i < N; i++)
		if (v[i] >= ma) {
			ma = v[i];
			ans = i;
		}
	if (ans == -1)
		return ans;
	ma = 1;
	for (int i = 0; i < N; i++)
		if (i != ans) {
			int ta = CollectRelics(i, ans);
			if (ta == -1)
				continue;
			ma++;
			ans = ta;
		}
	if (ma > N / 2)
		return ans;
	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 640 KB Correct : C = 299
2 Correct 6 ms 512 KB Correct : C = 7
3 Correct 7 ms 640 KB Correct : C = 299
4 Correct 6 ms 640 KB Correct : C = 299
5 Correct 7 ms 640 KB Correct : C = 299
6 Correct 6 ms 640 KB Correct : C = 299
7 Correct 7 ms 640 KB Correct : C = 299
8 Correct 7 ms 512 KB Correct : C = 299
9 Correct 6 ms 640 KB Correct : C = 186
10 Correct 7 ms 640 KB Correct : C = 299
11 Correct 6 ms 640 KB Correct : C = 299
12 Correct 6 ms 512 KB Correct : C = 299
13 Correct 40 ms 512 KB Correct : C = 242
14 Correct 6 ms 640 KB Correct : C = 299
15 Correct 7 ms 640 KB Correct : C = 299
16 Correct 6 ms 640 KB Correct : C = 186
17 Correct 6 ms 640 KB Correct : C = 299
18 Correct 6 ms 688 KB Correct : C = 299
19 Correct 5 ms 640 KB Correct : C = 299
20 Correct 7 ms 640 KB Correct : C = 299
21 Incorrect 7 ms 640 KB Wrong
22 Correct 7 ms 640 KB Correct : C = 299
23 Correct 7 ms 640 KB Correct : C = 299
24 Correct 6 ms 640 KB Correct : C = 299
25 Incorrect 7 ms 640 KB Wrong
26 Correct 6 ms 512 KB Correct : C = 0
27 Correct 7 ms 512 KB Correct : C = 299