Submission #150820

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

using namespace std;

int FindBase(int n) {
    if (n <= 3) return 0;
    int ord[201];
    int out[201];
    int same[201];
    int same1[201] = {};
    for (int i = 0; i < n; ++i) ord[i] = i;
    srand(0x52525522);
    random_shuffle(ord, ord + n);
    vector<int> L;
    L.push_back(0);
    same[0] = 1;
    out[0] = ord[0];
    int sum = 1, c = -1;
    for (int i = 1; i < n; ++i) {
        int ret = CollectRelics(ord[L.back()], ord[i]);
        if (ret != -1) {
            out[L.back()] = out[i] = ret;
            ++sum;
            same[i] = 1;
        }
        else {
            out[i] = ord[i];
            same[i] = 0;
            c = i;
            --sum;
        }
        if (sum == 0) {
            ++i;
            if (i < n) same[i] = 1;
            if (i < n) out[i] = ord[i];
            if (i < n) L.push_back(i);
            ++sum;
        }
    }
    int del = sum;
    int ed = -1;
    for (int i = 0; i < (int)L.size() - 1; ++i) {
        int a = L[i], b = L[i + 1];
        int ret = CollectRelics(ord[a], ord[L.back()]);
        if (ret != -1) {
            out[a] = out[L.back()] = ret;
            for (int j = a; j < b; ++j) {
                if (same[j]) {
                    continue;
                }
                c = j;
                ed = j;
            }
            continue;
        }
        for (int j = a; j < b; ++j) {
            ed = j;
            if (same[j]) {
                continue;
            }
            int ret = CollectRelics(ord[L.back()], ord[j]);
            if (ret != -1) {
                out[L.back()] = out[j] = ret;
            }
            else {
                c = j;
                if ((del -= 2) < -1) break;
            }
        }
        if (del < -1) break;
    }
    if (del > -2) return out[L.back()];
    if (c == -1) return -1;
    del = -sum;
    for (int i = 0; i < (int)L.size() - 1; ++i) {
        if (del < -1) break;
        int a = L[i], b = L[i + 1];
        int ret = -1;
        if (same1[a] == 0) {
            if (a == c) ret = out[c];
            else ret = CollectRelics(ord[a], ord[c]);
        }
        if (ret != -1) {
            out[a] = out[c] = ret;
            continue;
        }
        for (int j = a; j < b; ++j) {
            if (same[j]) {
                continue;
            }
            if (same1[j]) {
                if ((del -= 2) < -1) break;
                continue;
            }
            int ret;
            if (c == j) ret = out[c];
            else ret = CollectRelics(ord[c], ord[j]);
            if (ret != -1) {
                out[c] = out[j] = ret;
            }
            else if ((del -= 2) < -1) break;
        }
        if (del < -1) break;
    }
    for (int i = L.back(); i < n; ++i) {
        if (del < -1) break;
        if (same[i]) continue;
        int ret;
        if (c == i) ret = out[c];
        else CollectRelics(ord[c], ord[i]);
        if (ret != -1) {
            out[c] = out[i] = ret;
        }
        else if ((del -= 2) < -1) break;
    }
    if (del < -1) return -1;
    return out[c];
}

Compilation message

lokahia.cpp: In function 'int FindBase(int)':
lokahia.cpp:46:9: warning: variable 'ed' set but not used [-Wunused-but-set-variable]
     int ed = -1;
         ^~
lokahia.cpp:116:9: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (ret != -1) {
         ^~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Correct : C = 66
2 Correct 7 ms 640 KB Correct : C = 218
3 Correct 6 ms 640 KB Correct : C = 125
4 Incorrect 6 ms 560 KB Wrong
5 Correct 6 ms 640 KB Correct : C = 105
6 Correct 6 ms 640 KB Correct : C = 200
7 Correct 6 ms 640 KB Correct : C = 198
8 Correct 7 ms 640 KB Correct : C = 134
9 Incorrect 6 ms 640 KB Wrong
10 Correct 6 ms 640 KB Correct : C = 106
11 Correct 7 ms 688 KB Correct : C = 291
12 Correct 6 ms 512 KB Correct : C = 65
13 Correct 6 ms 512 KB Correct : C = 0
14 Correct 6 ms 512 KB Correct : C = 118
15 Correct 6 ms 640 KB Correct : C = 198
16 Correct 6 ms 512 KB Correct : C = 131
17 Correct 6 ms 512 KB Correct : C = 156
18 Incorrect 6 ms 640 KB Wrong
19 Correct 5 ms 384 KB Correct : C = 4
20 Correct 6 ms 640 KB Correct : C = 213
21 Correct 7 ms 640 KB Correct : C = 199
22 Correct 6 ms 512 KB Correct : C = 119
23 Correct 6 ms 512 KB Correct : C = 294
24 Correct 7 ms 640 KB Correct : C = 204
25 Correct 7 ms 512 KB Correct : C = 122
26 Incorrect 6 ms 512 KB Wrong
27 Correct 5 ms 512 KB Correct : C = 119