Submission #934479

# Submission time Handle Problem Language Result Execution time Memory
934479 2024-02-27T12:01:13 Z nguyentunglam Monster Game (JOI21_monster) C++17
0 / 100
38 ms 600 KB
#include "monster.h"
#include<bits/stdc++.h>
using namespace std;

mt19937 rng(10184104810471);

int rnd(int l, int r) {
  return l + rng() % (r - l + 1);
}

vector<int> dnc (vector<int> cur) {
  if (cur.size() < 2) return cur;
  vector<int> left, right;
  for(int i = 0; i < cur.size(); i++) {
    if (i < cur.size() / 2) left.push_back(cur[i]);
    else right.push_back(cur[i]);
  }
  left = dnc(left);
  right = dnc(right);
//  for(int &j : left) cout << j << " "; cout << endl;
//  for(int &j : right) cout << j << " "; cout << endl;
  vector<int> ret;
  for(int i = 0, j = 0; i < left.size() || j < right.size(); ) {
    if (i < left.size() && (j == right.size() || Query(right[j], left[i]))) {
      ret.push_back(left[i++]);
    } else ret.push_back(right[j++]);
  }
  return ret;
}

std::vector<int> Solve(int n) {
  vector<int> order;
  for(int i = 0; i < n; i++) order.push_back(i);
  shuffle(order.begin(), order.end(), rng);
  order = dnc(order);
//  for(int &j : order) cout << j << " "; cout << endl;
//  exit(0);

  int k = min(12, n);
  vector<int> win(k);
  for(int i = 0; i < k; i++) for(int j = i + 1; j < k; j++) {
    if (Query(order[i], order[j])) win[i]++;
    else win[j]++;
  }

  vector<int> tst;
  for(int i = 0; i < k; i++) if (win[i] == 1) {
    tst.push_back(order[i]);
//    cout << i << endl;
  }

  assert(tst.size() == 2);
  int x = Query(tst[0], tst[1]) ? tst[0] : tst[1];

  int i = 0, cnt = 0;

  vector<int> ans(n);

  auto expand = [&] () {
    vector<int> tmp;
    while (i < n) {
      tmp.push_back(order[i++]);
      if (order[i - 1] == x) break;
    }
    reverse(tmp.begin(), tmp.end());
    for(int &j : tmp) ans[j] = cnt++;
  };

  expand();
  while (x + 1 < n) {
    for(int y = x + 1; y <= n; y++) if (Query(x, y)) {
      x = y;
      break;
    }
    expand();
  }
  return ans;
}

Compilation message

monster.cpp: In function 'std::vector<int> dnc(std::vector<int>)':
monster.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |   for(int i = 0; i < cur.size(); i++) {
      |                  ~~^~~~~~~~~~~~
monster.cpp:15:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     if (i < cur.size() / 2) left.push_back(cur[i]);
      |         ~~^~~~~~~~~~~~~~~~
monster.cpp:23:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(int i = 0, j = 0; i < left.size() || j < right.size(); ) {
      |                         ~~^~~~~~~~~~~~~
monster.cpp:23:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(int i = 0, j = 0; i < left.size() || j < right.size(); ) {
      |                                            ~~^~~~~~~~~~~~~~
monster.cpp:24:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     if (i < left.size() && (j == right.size() || Query(right[j], left[i]))) {
      |         ~~^~~~~~~~~~~~~
monster.cpp:24:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     if (i < left.size() && (j == right.size() || Query(right[j], left[i]))) {
      |                             ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 600 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -