Submission #150176

# Submission time Handle Problem Language Result Execution time Memory
150176 2019-09-01T07:50:53 Z mit한의대지망생(#3602, TAMREF, imeimi2000, suzy) Lokahian Relics (FXCUP4_lokahia) C++17
0 / 100
7 ms 640 KB
#include "lokahia.h"
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

int FindBase(int n) {
    if (n == 1) return 0;
    if (n <= 20) {
        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, set<int>> mp;
    int mxs = 0;
    for (int i = 0; i < 300 - (n - mxs); ++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].insert(a);
        mp[ret].insert(b);
        mp[ret].insert(ret);
        mxs = max(mxs, (int)mp[ret].size());
    }
    if (mp.empty()) return -1;
    int mxi = -1;
    set<int> sp;
    for (auto &it : mp) {
        if (it.second.size() == mxs) mxi = it.first, sp = it.second;
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (sp.count(i) || CollectRelics(i, mxi) != -1) ++cnt;
    }
    if (cnt >= n / 2) return mxi;
    return -1;
}

Compilation message

lokahia.cpp: In function 'int FindBase(int)':
lokahia.cpp:26:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (v.size() >= n / 2) {
                 ~~~~~~~~~^~~~~~~~
lokahia.cpp:51:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (it.second.size() == mxs) mxi = it.first, sp = it.second;
             ~~~~~~~~~~~~~~~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Correct : C = 300
2 Correct 5 ms 512 KB Correct : C = 181
3 Correct 5 ms 512 KB Correct : C = 0
4 Incorrect 6 ms 512 KB Wrong
5 Correct 6 ms 640 KB Correct : C = 300
6 Correct 6 ms 512 KB Correct : C = 300
7 Incorrect 6 ms 640 KB Wrong
8 Correct 5 ms 384 KB Correct : C = 300
9 Correct 6 ms 512 KB Correct : C = 300
10 Incorrect 6 ms 640 KB Wrong
11 Correct 6 ms 512 KB Correct : C = 300
12 Correct 6 ms 640 KB Correct : C = 300
13 Correct 5 ms 640 KB Correct : C = 100
14 Correct 6 ms 512 KB Correct : C = 180
15 Correct 7 ms 640 KB Correct : C = 300
16 Correct 6 ms 640 KB Correct : C = 300
17 Correct 6 ms 640 KB Correct : C = 300
18 Correct 6 ms 512 KB Correct : C = 300
19 Correct 6 ms 640 KB Correct : C = 300
20 Correct 5 ms 640 KB Correct : C = 101
21 Correct 6 ms 640 KB Correct : C = 300
22 Correct 5 ms 512 KB Correct : C = 300
23 Correct 6 ms 640 KB Correct : C = 300
24 Correct 5 ms 512 KB Correct : C = 10
25 Correct 6 ms 640 KB Correct : C = 300
26 Correct 6 ms 512 KB Correct : C = 300
27 Incorrect 5 ms 512 KB Wrong