답안 #1052318

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052318 2024-08-10T13:20:05 Z Sacharlemagne Monster Game (JOI21_monster) C++17
99 / 100
55 ms 696 KB
#include "monster.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
namespace {

bool example_variable;

}  // namespace
vi solveP(int l, int r) {
    if (l == r) return {l};
    vi lp = solveP(l,(l+r)/2), rp = solveP(1+(l+r)/2,r);
    vi ans;
    int p1 = 0, p2 = 0;
    while (p1 < lp.size() || p2 < rp.size()) {
        if (p1 < lp.size() && p2 < rp.size()) {
            if (!Query(lp[p1],rp[p2])) ans.push_back(rp[p2++]);
            else ans.push_back(lp[p1++]);
        }
        else if (p1 < lp.size()) ans.push_back(lp[p1++]);
        else ans.push_back(rp[p2++]);
    }
    return ans;
}
vector<int> badSolve(int N, vi ans) {
    map<int,int> v;
    for (int i = 0; i<N; ++i) {
        for (int j = i+1; j<N; ++j) {
            ++v[Query(ans[i],ans[j]) ? ans[i] : ans[j]];
        }
    }
    sort(ans.begin(), ans.end(), [&](int a, int b) {return v[a] < v[b];});
    if (!Query(ans[0], ans[1])) swap(ans[0], ans[1]);
    if (!Query(ans[N-2], ans[N-1])) swap(ans[N-2], ans[N-1]);
    return ans;
}
vi Solve(int N) {
    vi v = solveP(0,N-1);
    reverse(v.begin(), v.end());
    int k = min(N, 30);
    vi partial(v.begin(), v.begin()+k);
    int zero = badSolve(k,partial)[0];
    int ind = find(v.begin(), v.end(), zero)-v.begin();
    reverse(v.begin(), v.begin()+ind+1);
    while (ind < N-1) {
        int i = ind+1;
        while (Query(v[i],v[ind])) ++i;
        reverse(v.begin()+ind+1,v.begin()+i+1);
        ind = i;
    }
    vi ret(N); for (int i = 0; i<N; ++i) ret[v[i]] = i;
    return ret;
}

Compilation message

monster.cpp: In function 'vi solveP(int, int)':
monster.cpp:15:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     while (p1 < lp.size() || p2 < rp.size()) {
      |            ~~~^~~~~~~~~~~
monster.cpp:15:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     while (p1 < lp.size() || p2 < rp.size()) {
      |                              ~~~^~~~~~~~~~~
monster.cpp:16:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         if (p1 < lp.size() && p2 < rp.size()) {
      |             ~~~^~~~~~~~~~~
monster.cpp:16:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         if (p1 < lp.size() && p2 < rp.size()) {
      |                               ~~~^~~~~~~~~~~
monster.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         else if (p1 < lp.size()) ans.push_back(lp[p1++]);
      |                  ~~~^~~~~~~~~~~
monster.cpp: At global scope:
monster.cpp:7:6: warning: '{anonymous}::example_variable' defined but not used [-Wunused-variable]
    7 | bool example_variable;
      |      ^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 356 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 9 ms 436 KB Output is correct
17 Correct 8 ms 600 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 10 ms 432 KB Output is correct
20 Correct 11 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 8 ms 444 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 504 KB Output is correct
32 Correct 5 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 356 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 9 ms 436 KB Output is correct
17 Correct 8 ms 600 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 10 ms 432 KB Output is correct
20 Correct 11 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 8 ms 444 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 504 KB Output is correct
32 Correct 5 ms 344 KB Output is correct
33 Correct 54 ms 344 KB Output is correct
34 Correct 52 ms 436 KB Output is correct
35 Correct 52 ms 436 KB Output is correct
36 Correct 45 ms 600 KB Output is correct
37 Correct 54 ms 684 KB Output is correct
38 Correct 49 ms 432 KB Output is correct
39 Correct 54 ms 592 KB Output is correct
40 Correct 38 ms 432 KB Output is correct
41 Correct 55 ms 672 KB Output is correct
42 Correct 55 ms 688 KB Output is correct
43 Correct 29 ms 344 KB Output is correct
44 Correct 25 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 49 ms 500 KB Partially correct
2 Partially correct 47 ms 344 KB Partially correct
3 Partially correct 43 ms 600 KB Partially correct
4 Partially correct 44 ms 436 KB Partially correct
5 Partially correct 42 ms 440 KB Partially correct
6 Correct 35 ms 440 KB Output is correct
7 Correct 37 ms 440 KB Output is correct
8 Partially correct 51 ms 676 KB Partially correct
9 Partially correct 49 ms 436 KB Partially correct
10 Partially correct 48 ms 436 KB Partially correct
11 Partially correct 50 ms 436 KB Partially correct
12 Partially correct 48 ms 600 KB Partially correct
13 Correct 46 ms 600 KB Output is correct
14 Correct 44 ms 600 KB Output is correct
15 Correct 33 ms 696 KB Output is correct
16 Correct 27 ms 600 KB Output is correct
17 Correct 30 ms 440 KB Output is correct
18 Correct 36 ms 420 KB Output is correct