답안 #1053590

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053590 2024-08-11T14:07:19 Z juicy Monster Game (JOI21_monster) C++17
100 / 100
56 ms 848 KB
#include "monster.h"

#include <bits/stdc++.h>

using namespace std;

std::vector<int> Solve(int N) {
  auto in = [&](int x) {
    return 0 <= x && x < N;
  };
  function<vector<int>(vector<int>)> mrg = [&](vector<int> A) {
    if (A.size() == 1) {
      return A;
    }
    int md = A.size() / 2;
    auto lt = mrg(vector(A.begin(), A.begin() + md)), rt = mrg(vector(A.begin() + md, A.end()));
    vector<int> res;
    for (int i = 0, j = 0; i < lt.size() || j < rt.size(); ) { 
      if (i < lt.size() && (j == rt.size() || Query(rt[j], lt[i]))) {
        res.push_back(lt[i++]);
      } else {
        res.push_back(rt[j++]);
      }
    }
    return res;
  };
  vector<int> ord(N); iota(ord.begin(), ord.end(), 0);
  ord = mrg(ord);
  int k = min(N, 10);
  vector<int> cnt(k);
  for (int i = 0; i < k; ++i) {
    for (int j = i + 1; j < k; ++j) {
      if (Query(ord[i], ord[j])) {
        ++cnt[i];
      } else {
        ++cnt[j];
      }
    }
  }
  int a = min_element(cnt.begin(), cnt.end()) - cnt.begin();
  int b = min_element(cnt.begin() + a + 1, cnt.end()) - cnt.begin();
  int c = Query(ord[a], ord[b]) ? a : b;
  rotate(ord.begin(), ord.begin() + c, ord.begin() + c + 1);
  for (int i = 1, p = 0; i < N; ++i) {
    int j = i;
    while (!Query(ord[p], ord[j])) {
      ++j;
    }
    reverse(ord.begin() + i, ord.begin() + j + 1);
    p = i = j;
  }
  vector<int> res(N);
  for (int i = 0; i < N; ++i) {
    res[ord[i]] = i;
  }
  return res;
}

Compilation message

monster.cpp: In lambda function:
monster.cpp:18:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0, j = 0; i < lt.size() || j < rt.size(); ) {
      |                            ~~^~~~~~~~~~~
monster.cpp:18:47: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0, j = 0; i < lt.size() || j < rt.size(); ) {
      |                                             ~~^~~~~~~~~~~
monster.cpp:19:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |       if (i < lt.size() && (j == rt.size() || Query(rt[j], lt[i]))) {
      |           ~~^~~~~~~~~~~
monster.cpp:19:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |       if (i < lt.size() && (j == rt.size() || Query(rt[j], lt[i]))) {
      |                             ~~^~~~~~~~~~~~
monster.cpp: In function 'std::vector<int> Solve(int)':
monster.cpp:8:8: warning: variable 'in' set but not used [-Wunused-but-set-variable]
    8 |   auto in = [&](int x) {
      |        ^~
# 결과 실행 시간 메모리 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 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 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 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 6 ms 344 KB Output is correct
17 Correct 6 ms 440 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 6 ms 600 KB Output is correct
20 Correct 6 ms 440 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 384 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 4 ms 344 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 344 KB Output is correct
32 Correct 4 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 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 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 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 6 ms 344 KB Output is correct
17 Correct 6 ms 440 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 6 ms 600 KB Output is correct
20 Correct 6 ms 440 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 384 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 4 ms 344 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 344 KB Output is correct
32 Correct 4 ms 344 KB Output is correct
33 Correct 37 ms 344 KB Output is correct
34 Correct 40 ms 692 KB Output is correct
35 Correct 42 ms 432 KB Output is correct
36 Correct 40 ms 344 KB Output is correct
37 Correct 41 ms 592 KB Output is correct
38 Correct 40 ms 596 KB Output is correct
39 Correct 45 ms 680 KB Output is correct
40 Correct 37 ms 344 KB Output is correct
41 Correct 50 ms 600 KB Output is correct
42 Correct 36 ms 444 KB Output is correct
43 Correct 18 ms 344 KB Output is correct
44 Correct 22 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 440 KB Output is correct
2 Correct 46 ms 684 KB Output is correct
3 Correct 45 ms 448 KB Output is correct
4 Correct 34 ms 684 KB Output is correct
5 Correct 49 ms 848 KB Output is correct
6 Correct 27 ms 448 KB Output is correct
7 Correct 35 ms 344 KB Output is correct
8 Correct 47 ms 684 KB Output is correct
9 Correct 39 ms 688 KB Output is correct
10 Correct 30 ms 444 KB Output is correct
11 Correct 56 ms 424 KB Output is correct
12 Correct 39 ms 592 KB Output is correct
13 Correct 37 ms 592 KB Output is correct
14 Correct 40 ms 456 KB Output is correct
15 Correct 21 ms 344 KB Output is correct
16 Correct 22 ms 592 KB Output is correct
17 Correct 37 ms 432 KB Output is correct
18 Correct 25 ms 592 KB Output is correct