Submission #150839

# Submission time Handle Problem Language Result Execution time Memory
150839 2019-09-01T08:59:06 Z mit한의대지망생(#3602, TAMREF, imeimi2000, suzy) Lokahian Relics (FXCUP4_lokahia) C++17
0 / 100
12 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 <= 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]) {
                    same1[j] = 1;
                    continue;
                }
                c = j;
            }
            continue;
        }
        for (int j = a; j < b; ++j) {
            if (same[j]) {
                continue;
            }
            int ret = CollectRelics(ord[L.back()], ord[j]);
            if (ret != -1) {
                same1[j] = 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: unused variable 'ed' [-Wunused-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 = 119
2 Correct 5 ms 640 KB Correct : C = 105
3 Correct 6 ms 512 KB Correct : C = 65
4 Incorrect 6 ms 640 KB Wrong
5 Incorrect 12 ms 512 KB Wrong
6 Correct 6 ms 640 KB Correct : C = 198
7 Correct 6 ms 640 KB Correct : C = 127
8 Correct 6 ms 640 KB Correct : C = 202
9 Correct 6 ms 640 KB Correct : C = 205
10 Correct 6 ms 512 KB Correct : C = 119
11 Correct 6 ms 640 KB Correct : C = 119
12 Correct 5 ms 384 KB Correct : C = 0
13 Incorrect 6 ms 640 KB Wrong
14 Correct 6 ms 620 KB Correct : C = 106
15 Correct 6 ms 512 KB Correct : C = 116
16 Correct 7 ms 512 KB Correct : C = 126
17 Correct 6 ms 640 KB Correct : C = 201
18 Correct 6 ms 640 KB Correct : C = 199
19 Correct 6 ms 512 KB Correct : C = 121
20 Correct 5 ms 512 KB Correct : C = 167
21 Correct 6 ms 640 KB Correct : C = 118
22 Correct 6 ms 640 KB Correct : C = 207
23 Correct 6 ms 640 KB Correct : C = 199
24 Correct 6 ms 512 KB Correct : C = 66
25 Correct 5 ms 512 KB Correct : C = 4
26 Correct 6 ms 640 KB Correct : C = 255
27 Correct 6 ms 640 KB Correct : C = 198