답안 #150138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
150138 2019-09-01T07:47:16 Z mit한의대지망생(#3602, TAMREF, imeimi2000, suzy) 로카히아 유적 (FXCUP4_lokahia) C++17
0 / 100
8 ms 688 KB
#include "lokahia.h"
#include <algorithm>
#include <vector>
#include <map>
#include <cstdlib>

using namespace std;

int FindBase(int n) {
    if (n == 1) return 0;
    if (n <= 2) {
        map<int, vector<int>> mp;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                int ret = CollectRelics(i, j);
                if (ret == -1) continue;
                mp[ret].push_back(i);
                mp[ret].push_back(j);
            }
        }
        for (auto it : mp) {
            vector<int> v = it.second;
            sort(v.begin(), v.end());
            v.erase(unique(v.begin(), v.end()), v.end());
            if (v.size() >= n / 2) {
                return it.first;
            }
        }
        return -1;
    }
    srand(0x5252);
    map<int, vector<int>> mp;
    for (int i = 0; i < 300 - n; ++i) {
        int a, b;
        do {
            a = rand() % n, b = rand() % n;
        } while (a == b);
        int ret = CollectRelics(a, b);
        if (ret == -1) continue;
        mp[ret].push_back(a);
        mp[ret].push_back(b);
    }
    if (mp.empty()) return -1;
    int mxi = -1, mxv = -1;
    for (auto &it : mp) {
        vector<int> &v = it.second;
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        if ((int)v.size() > mxv) mxi = it.first, mxv = (int)v.size();
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (i == mxi || CollectRelics(i, mxi) != -1) ++cnt;
    }
    if (cnt >= n / 2) return mxi;
    return -1;
}

Compilation message

lokahia.cpp: In function 'int FindBase(int)':
lokahia.cpp:25:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (v.size() >= n / 2) {
                 ~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 512 KB Correct : C = 181
2 Correct 6 ms 688 KB Correct : C = 299
3 Correct 6 ms 640 KB Correct : C = 299
4 Correct 6 ms 600 KB Correct : C = 299
5 Correct 6 ms 640 KB Correct : C = 101
6 Correct 6 ms 640 KB Correct : C = 100
7 Correct 6 ms 600 KB Correct : C = 299
8 Correct 5 ms 512 KB Correct : C = 180
9 Correct 6 ms 640 KB Correct : C = 299
10 Incorrect 7 ms 512 KB Wrong
11 Correct 6 ms 688 KB Correct : C = 299
12 Correct 6 ms 512 KB Correct : C = 299
13 Correct 5 ms 620 KB Correct : C = 299
14 Correct 6 ms 640 KB Correct : C = 299
15 Correct 6 ms 640 KB Correct : C = 299
16 Correct 6 ms 512 KB Correct : C = 0
17 Correct 6 ms 512 KB Correct : C = 299
18 Correct 6 ms 512 KB Correct : C = 299
19 Correct 6 ms 512 KB Correct : C = 299
20 Correct 6 ms 640 KB Correct : C = 299
21 Correct 6 ms 512 KB Correct : C = 299
22 Incorrect 7 ms 512 KB Wrong
23 Correct 7 ms 600 KB Correct : C = 299
24 Correct 6 ms 640 KB Correct : C = 299
25 Incorrect 8 ms 600 KB Wrong
26 Correct 6 ms 512 KB Correct : C = 299
27 Incorrect 7 ms 640 KB Wrong