답안 #150502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150502 2019-09-01T08:32:01 Z 1 WA = 5 Push Up(#3624, BaaaaaaaaaaaaaaaarkingDog, IohcEjnim, 0xrgb) 로카히아 유적 (FXCUP4_lokahia) C++17
0 / 100
7 ms 640 KB
#include "lokahia.h"
#include <stdlib.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
int p[706];
int query[706][3];

int find(int a){
  if(p[a] < 0) return a;
  return p[a] = find(p[a]);
}
int uni(int a, int b){
  a = find(a);
  b = find(b);
  if(a==b) return 0;
  p[a] += p[b];
  p[b] = a;
  return -p[a];
}

int mysize(int a){
  if(p[a] < 0) return -p[a];
  return mysize(p[a]);
}

int FindBase(int N){
  srand(234316);
  int GROUP_IDX = N+1;
  if(N==1) return 0;
  for(int i = 0; i < 700; i++){
    p[i] = -1;
  }
  int GUESS_IDX = 0;
  while(GUESS_IDX < 400){
    int a = 0, b = 0;
    while(find(a) == find(b)){
      a = rand()%N;
      b = rand()%N;
      //printf("%d %d %d %d\n",a,b,find(a),find(b));
    }
    int ret = CollectRelics(a,b);
    //printf("%d %d %d\n",a,b,ret);
    query[GUESS_IDX][0]=a;
    query[GUESS_IDX][1]=b;
    query[GUESS_IDX][2]=ret;
    if(ret != -1){
      uni(a, b);
      uni(a,ret);
      int sz = mysize(a);
      if(sz > N/2){
        int ret = -1;
        for(int i = 0; i < GUESS_IDX; i++){
          if(find(query[GUESS_IDX][0]) != find(a) or find(query[GUESS_IDX][1]) != find(a)) continue;
          ret = max(ret, query[GUESS_IDX][2]);         
        }
        return ret;
      }
    }
    GUESS_IDX++;
  }
  int mxidx = 0;
  for(int i = 0; i < N; i++){
    if(-p[i] > -p[mxidx]) mxidx = i;
  }
	int ret = -1;
  for(int i = 0; i < GUESS_IDX; i++){
    if(find(query[GUESS_IDX][0]) != find(mxidx) or find(query[GUESS_IDX][1]) != find(mxidx)) continue;
    ret = max(ret, query[GUESS_IDX][2]);
  }
  int cnt = 1;
  for(int i = 0; i < N; i++){
    if(i==ret) continue;
    if(CollectRelics(i,ret) != -1) cnt++;
  }
  if(cnt > N/2) return ret;
  else return -1;
}

Compilation message

lokahia.cpp: In function 'int FindBase(int)':
lokahia.cpp:29:7: warning: unused variable 'GROUP_IDX' [-Wunused-variable]
   int GROUP_IDX = N+1;
       ^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 6 ms 640 KB Partially correct : C = 599
2 Partially correct 6 ms 640 KB Partially correct : C = 598
3 Incorrect 6 ms 512 KB Wrong
4 Incorrect 5 ms 512 KB Wrong
5 Incorrect 6 ms 640 KB Wrong
6 Incorrect 7 ms 640 KB Wrong
7 Correct 6 ms 640 KB Correct : C = 63
8 Incorrect 7 ms 640 KB Wrong
9 Incorrect 6 ms 512 KB Wrong
10 Correct 5 ms 432 KB Correct : C = 0
11 Incorrect 6 ms 640 KB Wrong
12 Partially correct 7 ms 512 KB Partially correct : C = 519
13 Correct 6 ms 512 KB Correct : C = 217
14 Incorrect 7 ms 640 KB Wrong
15 Partially correct 6 ms 512 KB Partially correct : C = 383
16 Incorrect 6 ms 512 KB Wrong
17 Partially correct 6 ms 512 KB Partially correct : C = 518
18 Correct 5 ms 512 KB Correct : C = 39
19 Correct 5 ms 640 KB Correct : C = 300
20 Incorrect 6 ms 640 KB Wrong
21 Incorrect 6 ms 512 KB Wrong
22 Partially correct 6 ms 640 KB Partially correct : C = 599
23 Correct 6 ms 512 KB Correct : C = 37
24 Correct 6 ms 640 KB Correct : C = 233
25 Incorrect 6 ms 640 KB Wrong
26 Correct 6 ms 640 KB Correct : C = 59
27 Incorrect 6 ms 512 KB Wrong