답안 #530770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530770 2022-02-26T17:51:37 Z c28dnv9q3 Monster Game (JOI21_monster) C++17
10 / 100
259 ms 6200 KB
#include "monster.h"
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

const int len = 12;

void print(string pre, vector<int> a) {
    return;
    cout << pre << " ";
    for (int i = 0; i < a.size(); ++i) {
        cout << a[i] << " ";
    }
    cout << "\n";
}

int higher[1 << len];
map<pair<int, int>, int> quer;

bool cmp(int a, int b, int N) {
    if (a >= N) return true;
    if (b >= N) return false;
    //cout << a << " " << b << "\n";
    bool q = Query(a, b);
    if (q) higher[a]++; else higher[b]++;
    return q;
}

bool compare(int a, int b, int N) {
    if (quer[{a, b}] != 0) return quer[{a, b}] == 2;
    bool q = cmp(a, b, N);
    quer[{a, b}] = q ? 2 : 1;
    quer[{b, a}] = q ? 1 : 2;
    return q;
}

vector<int> sort(int l, int o, int N) {
    if (l == 0) return std::vector<int>{o};
    vector<int> a = sort(l - 1, o, N);
    vector<int> b = sort(l - 1, o + (1 << (l - 1)), N);
    vector<int> c(a.size() + b.size());
    int iA = 0;
    int iB = 0;
    for (int i = 0; i < c.size(); ++i) {
        if (iA < a.size() && iB < b.size()) {
            if (compare(a[iA], b[iB], N)) {
                c[i] = b[iB++];
            } else {
                c[i] = a[iA++];
            }
        } else {
            if (iA == a.size()) {
                c[i] = b[iB++];
            } else {
                c[i] = a[iA++];
            }
        }
    }
    return c;
}

void rev(vector<int> &T, int a, int b) {
    for (int i = 0; i < (1 + b - a) / 2; ++i) {
        swap(T[a + i], T[b - i]);
    }
}

int findMin(int N) {
    vector<int> low;

    for (int i = 0; i < N; ++i) {
        if (higher[i] <= 3) low.push_back(i);
    }

    print("possible: ", low);

    int ii;
    for (int i = 0; i < low.size(); ++i) {
        ii = i + 1;
        while (ii < low.size() && higher[i] <= 3) {
            if (higher[ii] <= 3) compare(low[i], low[ii], N);
            ii++;
        }
    }

    vector<int> possible;
    for (int i = 0; i < low.size(); ++i) {
        if (higher[low[i]] <= 3) possible.push_back(low[i]);
    }

    print("possible: ", possible);

    for (int i = 0; i < possible.size(); ++i) {
        for (int j = i + 1; j < possible.size(); ++j) {
            compare(possible[i], possible[j], N);
        }
    }

    vector<int> min;
    for (int i = 0; i < possible.size(); ++i) {
        if (higher[possible[i]] == 1) min.push_back(possible[i]);
    }

    print("last: ", min);

    //for (int i = 0; i < N; ++i) cout << higher[i]; cout << "\n";

    return compare(min[0], min[1], N) ? min[0] : min[1];
}

std::vector<int> Solve(int N) {
    vector<int> T = sort(len, 0, N);

    int ind = -1;
    int x = findMin(N);
    for (int i = 0; i < N; ++i) {
        if (T[i] == x) ind = i;
    }
    if (ind == -1) return {};
    rev(T, 0, ind);

    for (int s = ind; s < N - 1;) {
        for (int i = s + 1; i < N; ++i) {
            if (compare(T[s], T[i], N)) {
                rev(T, s + 1, i);
                s = i;
                break;
            }
            if (i == N - 1) return {};
        }
    }

    vector<int> erg = vector<int>(N, 0);
    for (int i = 0; i < N; ++i) {
        erg[T[i]] = i;
    }

    return erg;
}

Compilation message

monster.cpp: In function 'void print(std::string, std::vector<int>)':
monster.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i = 0; i < a.size(); ++i) {
      |                     ~~^~~~~~~~~~
monster.cpp: In function 'std::vector<int> sort(int, int, int)':
monster.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 0; i < c.size(); ++i) {
      |                     ~~^~~~~~~~~~
monster.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if (iA < a.size() && iB < b.size()) {
      |             ~~~^~~~~~~~~~
monster.cpp:46:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if (iA < a.size() && iB < b.size()) {
      |                              ~~~^~~~~~~~~~
monster.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             if (iA == a.size()) {
      |                 ~~~^~~~~~~~~~~
monster.cpp: In function 'int findMin(int)':
monster.cpp:79:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for (int i = 0; i < low.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
monster.cpp:81:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         while (ii < low.size() && higher[i] <= 3) {
      |                ~~~^~~~~~~~~~~~
monster.cpp:88:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for (int i = 0; i < low.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
monster.cpp:94:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for (int i = 0; i < possible.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~~~
monster.cpp:95:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |         for (int j = i + 1; j < possible.size(); ++j) {
      |                             ~~^~~~~~~~~~~~~~~~~
monster.cpp:101:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for (int i = 0; i < possible.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3400 KB Output is correct
2 Correct 15 ms 3400 KB Output is correct
3 Correct 11 ms 3360 KB Output is correct
4 Correct 11 ms 3400 KB Output is correct
5 Correct 11 ms 3400 KB Output is correct
6 Correct 10 ms 3400 KB Output is correct
7 Correct 11 ms 3304 KB Output is correct
8 Correct 10 ms 3296 KB Output is correct
9 Correct 10 ms 3368 KB Output is correct
10 Correct 10 ms 3400 KB Output is correct
11 Correct 11 ms 3400 KB Output is correct
12 Correct 15 ms 3368 KB Output is correct
13 Correct 12 ms 3400 KB Output is correct
14 Correct 17 ms 3400 KB Output is correct
15 Correct 11 ms 3352 KB Output is correct
16 Correct 29 ms 3532 KB Output is correct
17 Correct 19 ms 3576 KB Output is correct
18 Correct 23 ms 3492 KB Output is correct
19 Correct 32 ms 3612 KB Output is correct
20 Correct 27 ms 3572 KB Output is correct
21 Correct 12 ms 3400 KB Output is correct
22 Correct 12 ms 3372 KB Output is correct
23 Correct 14 ms 3400 KB Output is correct
24 Correct 11 ms 3368 KB Output is correct
25 Correct 11 ms 3400 KB Output is correct
26 Correct 62 ms 4024 KB Output is correct
27 Correct 10 ms 3332 KB Output is correct
28 Correct 13 ms 3404 KB Output is correct
29 Correct 11 ms 3344 KB Output is correct
30 Correct 10 ms 3400 KB Output is correct
31 Correct 13 ms 3328 KB Output is correct
32 Correct 48 ms 4248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3400 KB Output is correct
2 Correct 15 ms 3400 KB Output is correct
3 Correct 11 ms 3360 KB Output is correct
4 Correct 11 ms 3400 KB Output is correct
5 Correct 11 ms 3400 KB Output is correct
6 Correct 10 ms 3400 KB Output is correct
7 Correct 11 ms 3304 KB Output is correct
8 Correct 10 ms 3296 KB Output is correct
9 Correct 10 ms 3368 KB Output is correct
10 Correct 10 ms 3400 KB Output is correct
11 Correct 11 ms 3400 KB Output is correct
12 Correct 15 ms 3368 KB Output is correct
13 Correct 12 ms 3400 KB Output is correct
14 Correct 17 ms 3400 KB Output is correct
15 Correct 11 ms 3352 KB Output is correct
16 Correct 29 ms 3532 KB Output is correct
17 Correct 19 ms 3576 KB Output is correct
18 Correct 23 ms 3492 KB Output is correct
19 Correct 32 ms 3612 KB Output is correct
20 Correct 27 ms 3572 KB Output is correct
21 Correct 12 ms 3400 KB Output is correct
22 Correct 12 ms 3372 KB Output is correct
23 Correct 14 ms 3400 KB Output is correct
24 Correct 11 ms 3368 KB Output is correct
25 Correct 11 ms 3400 KB Output is correct
26 Correct 62 ms 4024 KB Output is correct
27 Correct 10 ms 3332 KB Output is correct
28 Correct 13 ms 3404 KB Output is correct
29 Correct 11 ms 3344 KB Output is correct
30 Correct 10 ms 3400 KB Output is correct
31 Correct 13 ms 3328 KB Output is correct
32 Correct 48 ms 4248 KB Output is correct
33 Correct 128 ms 4288 KB Output is correct
34 Correct 99 ms 4336 KB Output is correct
35 Correct 131 ms 4436 KB Output is correct
36 Correct 155 ms 4384 KB Output is correct
37 Correct 136 ms 4312 KB Output is correct
38 Correct 149 ms 4392 KB Output is correct
39 Correct 99 ms 4360 KB Output is correct
40 Correct 121 ms 4356 KB Output is correct
41 Correct 132 ms 4372 KB Output is correct
42 Correct 123 ms 4372 KB Output is correct
43 Incorrect 259 ms 6200 KB Wrong Answer [6]
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 106 ms 4392 KB Partially correct
2 Partially correct 145 ms 4632 KB Partially correct
3 Partially correct 116 ms 4432 KB Partially correct
4 Partially correct 135 ms 4372 KB Partially correct
5 Partially correct 127 ms 4488 KB Partially correct
6 Incorrect 235 ms 6136 KB Wrong Answer [6]
7 Halted 0 ms 0 KB -