Submission #379217

# Submission time Handle Problem Language Result Execution time Memory
379217 2021-03-17T14:15:51 Z tqbfjotld Lokahian Relics (FXCUP4_lokahia) C++17
Compilation error
0 ms 0 KB
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
int CollectRelics(int R1, int R2);
int FindBase(int N);


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;
}

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;
}

#include <bits/stdc++.h>
using namespace std;
//#include "lokahia.h"

int X[205];
int retval[205];

int FindBase(int N){
    memset(X,-1,sizeof(X));
    for (int x = 0; x<N-1; x++){
        retval[x+1] = CollectRelics(x,x+1);
        if (retval[x+1]!=-1){
            X[x+1] = X[x];
        }
        else{
            X[x+1] = X[x+1];
        }
    }
    int longest = -1;
    int longpos = -1;
    for (int x = 0; x<N; x++){
        if (x-X[x]>longest){
            longest = x-X[x];
            longpos = x;
        }
    }
    int fingroup = X[longpos];
    int cur = N-1;
    int compsize = longest+1;
    int ans = -1;
    for (int x = fingroup+1; X[x]==fingroup; x++){
        ans = max(ans,retval[x]);
    }
    int queryCount = N-1;
    while (cur!=-1){
        if (X[X[cur]-1]==fingroup){
            cur = X[cur]-1;
            continue;
        }
        if (X[cur]==fingroup){
            cur = X[cur]-1;
            continue;
        }
        if (cur+1==fingroup){
            cur = X[cur]-1;
            continue;
        }
        if (queryCount==300) return -1;
        int ret = CollectRelics(cur,fingroup);
        queryCount++;
        if (ret==-1){
            cur = X[cur]-1;
            continue;
        }
        else{
            compsize += cur-X[cur]+1;
            ans = max(ans,ret);
            if (X[cur]==0) cur = -1;
            else cur = X[X[cur]-1]-1;
        }

    }
	return compsize>N/2?ans:-1;
}

Compilation message

/tmp/ccOJ3h4s.o: In function `CollectRelics(int, int)':
grader.cpp:(.text+0x10): multiple definition of `CollectRelics(int, int)'
/tmp/ccB4cOIH.o:lokahia.cpp:(.text+0x10): first defined here
/tmp/ccOJ3h4s.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccB4cOIH.o:lokahia.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status