답안 #530766

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

using namespace std;

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[1024];
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) {
            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(10, 0, N);

    int ind;
    int x = findMin(N);
    for (int i = 0; i < N; ++i) {
        if (T[i] == x) ind = i;
    }
    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 {0};
        }
    }

    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:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for (int i = 0; i < a.size(); ++i) {
      |                     ~~^~~~~~~~~~
monster.cpp: In function 'std::vector<int> sort(int, int, int)':
monster.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < c.size(); ++i) {
      |                     ~~^~~~~~~~~~
monster.cpp:44:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         if (iA < a.size() && iB < b.size()) {
      |             ~~~^~~~~~~~~~
monster.cpp:44:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         if (iA < a.size() && iB < b.size()) {
      |                              ~~~^~~~~~~~~~
monster.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             if (iA == a.size()) {
      |                 ~~~^~~~~~~~~~~
monster.cpp: In function 'int findMin(int)':
monster.cpp:77:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for (int i = 0; i < low.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
monster.cpp:79:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         while (ii < low.size() && higher[i] <= 3) {
      |                ~~~^~~~~~~~~~~~
monster.cpp:86:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for (int i = 0; i < low.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
monster.cpp:92:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for (int i = 0; i < possible.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~~~
monster.cpp:93:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |         for (int j = i + 1; j < possible.size(); ++j) {
      |                             ~~^~~~~~~~~~~~~~~~~
monster.cpp:99:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |     for (int i = 0; i < possible.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~~~
monster.cpp: In function 'std::vector<int> Solve(int)':
monster.cpp:113:9: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
  113 |     int ind;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 932 KB Output is correct
2 Correct 3 ms 924 KB Output is correct
3 Correct 3 ms 840 KB Output is correct
4 Correct 3 ms 840 KB Output is correct
5 Correct 3 ms 840 KB Output is correct
6 Correct 3 ms 840 KB Output is correct
7 Correct 3 ms 840 KB Output is correct
8 Correct 2 ms 840 KB Output is correct
9 Correct 3 ms 840 KB Output is correct
10 Correct 3 ms 840 KB Output is correct
11 Correct 3 ms 840 KB Output is correct
12 Correct 4 ms 936 KB Output is correct
13 Correct 4 ms 840 KB Output is correct
14 Correct 3 ms 840 KB Output is correct
15 Correct 3 ms 840 KB Output is correct
16 Correct 20 ms 1088 KB Output is correct
17 Correct 24 ms 996 KB Output is correct
18 Correct 17 ms 1156 KB Output is correct
19 Correct 27 ms 1024 KB Output is correct
20 Correct 21 ms 1076 KB Output is correct
21 Correct 3 ms 840 KB Output is correct
22 Correct 3 ms 840 KB Output is correct
23 Correct 2 ms 840 KB Output is correct
24 Correct 3 ms 840 KB Output is correct
25 Correct 2 ms 840 KB Output is correct
26 Correct 13 ms 968 KB Output is correct
27 Correct 3 ms 840 KB Output is correct
28 Correct 2 ms 840 KB Output is correct
29 Correct 3 ms 840 KB Output is correct
30 Correct 2 ms 840 KB Output is correct
31 Correct 3 ms 920 KB Output is correct
32 Correct 91 ms 2104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 932 KB Output is correct
2 Correct 3 ms 924 KB Output is correct
3 Correct 3 ms 840 KB Output is correct
4 Correct 3 ms 840 KB Output is correct
5 Correct 3 ms 840 KB Output is correct
6 Correct 3 ms 840 KB Output is correct
7 Correct 3 ms 840 KB Output is correct
8 Correct 2 ms 840 KB Output is correct
9 Correct 3 ms 840 KB Output is correct
10 Correct 3 ms 840 KB Output is correct
11 Correct 3 ms 840 KB Output is correct
12 Correct 4 ms 936 KB Output is correct
13 Correct 4 ms 840 KB Output is correct
14 Correct 3 ms 840 KB Output is correct
15 Correct 3 ms 840 KB Output is correct
16 Correct 20 ms 1088 KB Output is correct
17 Correct 24 ms 996 KB Output is correct
18 Correct 17 ms 1156 KB Output is correct
19 Correct 27 ms 1024 KB Output is correct
20 Correct 21 ms 1076 KB Output is correct
21 Correct 3 ms 840 KB Output is correct
22 Correct 3 ms 840 KB Output is correct
23 Correct 2 ms 840 KB Output is correct
24 Correct 3 ms 840 KB Output is correct
25 Correct 2 ms 840 KB Output is correct
26 Correct 13 ms 968 KB Output is correct
27 Correct 3 ms 840 KB Output is correct
28 Correct 2 ms 840 KB Output is correct
29 Correct 3 ms 840 KB Output is correct
30 Correct 2 ms 840 KB Output is correct
31 Correct 3 ms 920 KB Output is correct
32 Correct 91 ms 2104 KB Output is correct
33 Correct 96 ms 1600 KB Output is correct
34 Correct 96 ms 1504 KB Output is correct
35 Correct 80 ms 1556 KB Output is correct
36 Correct 105 ms 1568 KB Output is correct
37 Correct 92 ms 1584 KB Output is correct
38 Correct 113 ms 1448 KB Output is correct
39 Correct 84 ms 1576 KB Output is correct
40 Correct 102 ms 1628 KB Output is correct
41 Correct 110 ms 1528 KB Output is correct
42 Correct 93 ms 1524 KB Output is correct
43 Correct 107 ms 1268 KB Output is correct
44 Incorrect 240 ms 3480 KB Wrong Answer [6]
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 84 ms 1484 KB Partially correct
2 Correct 82 ms 1524 KB Output is correct
3 Partially correct 102 ms 1452 KB Partially correct
4 Partially correct 83 ms 1500 KB Partially correct
5 Partially correct 92 ms 1592 KB Partially correct
6 Partially correct 107 ms 1652 KB Partially correct
7 Partially correct 98 ms 1740 KB Partially correct
8 Correct 94 ms 1476 KB Output is correct
9 Correct 88 ms 1456 KB Output is correct
10 Correct 110 ms 1516 KB Output is correct
11 Correct 104 ms 1420 KB Output is correct
12 Partially correct 97 ms 1576 KB Partially correct
13 Partially correct 70 ms 1640 KB Partially correct
14 Partially correct 96 ms 1580 KB Partially correct
15 Correct 78 ms 1296 KB Output is correct
16 Incorrect 260 ms 3536 KB Wrong Answer [6]
17 Halted 0 ms 0 KB -