Submission #759950

# Submission time Handle Problem Language Result Execution time Memory
759950 2023-06-17T05:56:01 Z denniskim Lokahian Relics (FXCUP4_lokahia) C++17
Compilation error
0 ms 0 KB
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include "lokahia.h"

static void my_assert(int TF, const char* message){
	if(!TF){ puts(message); exit(0); }
}

static int N, reach[202][202], call_cnt = 0;
int CollectRelics(int R1, int R2){
	call_cnt++;
	my_assert(call_cnt <= 300, "Wrong : Too Much Calls");
	my_assert(0 <= R1 && 0 <= R2 && R1 < N && R2 < N && R1 != R2, "Wrong : Invalid Argument");

	for(int i=0; i<N; i++){
		if(reach[i][R1] && reach[i][R2]) return i;
	}
	return -1;
}

#include "lokahia.h"
#include <bits/stdc++.h>

using namespace std;
typedef int ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())

ll chk[210][210];
ll cou[210];

ll FindBase(ll N)
{
	srand(time(NULL));
	
	for(ll i = 0 ; i < 300 ; i++)
	{
		ll num1 = rand() % N, num2 = rand() % N;
		ll coco = 0;
		
		while(chk[num1][num2] || num1 == num2)
		{
			num1 = rand() % N;
			num2 = rand() % N;
			coco++;
			
			if(coco >= 10000)
				break;
		}
		
		if(coco >= 10000)
			continue;
		
		ll gap = CollectRelics(num1, num2);
		chk[num1][num2] = chk[num2][num1] = 1;
		
		if(gap != -1)
			cou[gap]++;
	}
	
	ll maxx = 0, sum = 0, ans = 0;
	
	for(ll i = 0 ; i < N ; i++)
	{
		if(cou[i] > maxx)
		{
			maxx = cou[i];
			ans = i;
		}
		
		sum += cou[i];
	}
	
	if(sum - maxx * 2 <= 5)
		return ans;
	
	return -1;
}

int main(){
	my_assert(scanf("%d", &N) == 1, "Error: Invalid Input");
	my_assert(1 <= N && N <= 200, "Error: Invalid Input");

	int con[202][202] = {0,};
	for(int i = 1; i < N; i++){
		int s, e, m;
		my_assert(scanf("%d%d%d", &s, &e, &m) == 3, "Error: Invalid Input");
		my_assert(0 <= s && s < N && 0 <= e && e < N && s != e && 1 <= m && m <= N, "Error: Invalid Input");
		con[s][e] = con[e][s] = m;
	}

	int near[202];
	for(int i = 0; i < N; i++){
		memset(near, 0, sizeof(near));
		reach[i][i] = 1, near[i] = -1;
		for(int j = 0; j < N; j++){
			if(con[i][j] > 0 && near[j] == 0) near[j] = con[i][j];
		}
		for(int vis = 1; vis < N; vis++){
			int nxt = -1;
			for(int j = 0; j < N; j++){
				if(near[j] > 0 && near[j] <= vis){
					nxt = j;
					break;
				}
			}
			if(nxt < 0) break;
			reach[i][nxt] = 1, near[nxt] = -1;
			for(int j = 0; j < N; j++){
				if(con[nxt][j] > 0 && near[j] == 0) near[j] = con[nxt][j];
			}
		}
	}

	int base = FindBase(N);
	if(base == -1){
		for(int i = 0; i < N; i++){
			int cnt = 0;
			for(int j = 0; j < N; j++) cnt += reach[i][j];
			my_assert(cnt <= N / 2, "Wrong: Wrong Answer");
		}
	}
	else if(0 <= base && base < N){
		int cnt = 0;
		for(int j = 0; j < N; j++) cnt += reach[base][j];
		my_assert(cnt > N / 2, "Wrong: Wrong Answer");
	}
	else my_assert(0, "Wrong: Wrong Answer");
	printf("Correct\n%d\n", call_cnt);
	return 0;
}

Compilation message

/usr/bin/ld: /tmp/cctSE7Vd.o: in function `CollectRelics(int, int)':
grader.cpp:(.text+0x20): multiple definition of `CollectRelics(int, int)'; /tmp/ccfqCPRc.o:lokahia.cpp:(.text+0x20): first defined here
/usr/bin/ld: /tmp/cctSE7Vd.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccfqCPRc.o:lokahia.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status