답안 #1052316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052316 2024-08-10T13:19:33 Z Sacharlemagne Monster Game (JOI21_monster) C++17
95 / 100
61 ms 848 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, 48);
    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 1 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 1 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 344 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 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 13 ms 344 KB Output is correct
17 Correct 8 ms 344 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 11 ms 344 KB Output is correct
20 Correct 10 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 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 8 ms 432 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 8 ms 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 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 344 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 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 13 ms 344 KB Output is correct
17 Correct 8 ms 344 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 11 ms 344 KB Output is correct
20 Correct 10 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 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 8 ms 432 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 8 ms 440 KB Output is correct
33 Correct 52 ms 432 KB Output is correct
34 Correct 43 ms 344 KB Output is correct
35 Correct 42 ms 596 KB Output is correct
36 Correct 39 ms 344 KB Output is correct
37 Correct 45 ms 664 KB Output is correct
38 Correct 54 ms 420 KB Output is correct
39 Correct 47 ms 344 KB Output is correct
40 Correct 46 ms 424 KB Output is correct
41 Correct 44 ms 440 KB Output is correct
42 Correct 61 ms 592 KB Output is correct
43 Correct 32 ms 600 KB Output is correct
44 Correct 30 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 43 ms 672 KB Partially correct
2 Partially correct 38 ms 344 KB Partially correct
3 Partially correct 53 ms 592 KB Partially correct
4 Partially correct 49 ms 424 KB Partially correct
5 Partially correct 34 ms 672 KB Partially correct
6 Correct 36 ms 344 KB Output is correct
7 Correct 44 ms 592 KB Output is correct
8 Partially correct 40 ms 428 KB Partially correct
9 Partially correct 40 ms 596 KB Partially correct
10 Partially correct 49 ms 424 KB Partially correct
11 Partially correct 49 ms 848 KB Partially correct
12 Partially correct 42 ms 416 KB Partially correct
13 Correct 37 ms 592 KB Output is correct
14 Correct 40 ms 440 KB Output is correct
15 Correct 22 ms 592 KB Output is correct
16 Correct 32 ms 344 KB Output is correct
17 Correct 26 ms 436 KB Output is correct
18 Partially correct 48 ms 680 KB Partially correct