답안 #874260

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874260 2023-11-16T14:41:53 Z LucaLucaM Super Dango Maker (JOI22_dango3) C++17
22 / 100
3366 ms 1048576 KB
#include "dango3.h"
#ifdef LOCAL
#include "grader.cpp"
#endif // LOCAL

#include <vector>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iostream>
#include <map>

std::mt19937 rng(3192702);

void Solve(int n, int m) {
  /**

  sol in O(n * m^2) query uri:

  pornesc cu toate valorile ramase si de fiecare data incerc sa scot cate 1

  **/

  std::vector<int> id(n * m + 1);
  for (int i = 1; i <= n * m; i++) {
    id[i] = i;
  }
  shuffle(id.begin() + 1, id.end(), rng);

  std::map<std::vector<int>, int> memo;

  auto query = [&] (std::vector<int> v) {
    std::vector<int> w;
    for (const auto &x : v) {
      w.push_back(id[x]);
    }
    if (memo.count(w)) {
      return memo[w];
    }
    return memo[w] = Query(w);
  };
  auto answer = [&] (std::vector<int> v) {
    std::vector<int> w;
    for (const auto &x : v) {
      w.push_back(id[x]);
    }
    Answer(w);
  };

  std::function<std::vector<int>(std::vector<int>)> exclude = [&] (std::vector<int> v) {
    bool dont[n * m + 1] = {};
    for (const auto &x : v) {
      dont[x] = true;
    }
    std::vector<int> w;
    for (int i = 1; i <= n * m; i++) {
      if (!dont[i]) {
        w.push_back(i);
      }
    }
    return w;
  };

  bool taken[n * m + 1] = {};

  int SZ = 45'000 / m;

  for (int rep = 0; rep < m; rep++) {
    std::vector<int> cand;
    for (int i = 1; i <= n * m; i++) {
      if (!taken[i]) {
        cand.push_back(i);
      }
    }
    std::vector<int> idk;
    do {
      shuffle(cand.begin(), cand.end(), rng);
      idk = cand;
      if ((int) idk.size() > SZ) {
        idk.resize(SZ);
      }
    } while (query(idk) == 0);
    cand = idk;
    std::vector<int> ret;
    ret.push_back(cand[0]);
    int qq = query(exclude(ret));
    for (int i = 1; i < (int) cand.size() && (int) ret.size() < n; i++) {
      std::vector<int> nw = ret;
      nw.push_back(cand[i]);
      if (qq == query(exclude(nw))) {
        ret.push_back(cand[i]);
      }
    }
//    std::cout << "! " << (int) ret.size() << '\n';
    answer(ret);
    for (const auto &x : ret) {
      taken[x] = true;
    }
  }

}
/**


3 2
3 3 1 2 1 2

4 4
2 2 3 2 4 4 3 2 3 1 1 3 4 1 4 1


**/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 11776 KB Output is correct
2 Correct 37 ms 12116 KB Output is correct
3 Correct 51 ms 12368 KB Output is correct
4 Correct 56 ms 12576 KB Output is correct
5 Correct 32 ms 11092 KB Output is correct
6 Correct 45 ms 11468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1177 ms 406084 KB Output is correct
2 Correct 1209 ms 413660 KB Output is correct
3 Correct 1107 ms 381652 KB Output is correct
4 Correct 1179 ms 400724 KB Output is correct
5 Correct 1200 ms 416488 KB Output is correct
6 Correct 1315 ms 427992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3366 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -