QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572046#8952. 解谜游戏wsyear0 1ms3952kbC++233.1kb2024-09-18 11:27:282024-09-18 11:27:29

Judging History

This is the latest submission verdict.

  • [2024-09-18 11:27:29]
  • Judged
  • Verdict: 0
  • Time: 1ms
  • Memory: 3952kb
  • [2024-09-18 11:27:28]
  • Submitted

answer

#include <bits/stdc++.h>
#include "puzzle.h"

#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

template<class T>inline void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T>inline void chkmx(T &x, T y) { if (y > x) x = y; }

using namespace std;

const int maxn = 1010;
mt19937 rnd(1);

int n, a[maxn], b[maxn], ans[maxn], loop[maxn], tot;
vector<int> e[maxn];
vector<pii> vec[maxn];

int get(int *ask) {
  vector<int> p;
  rep (i, 1, n) p.emplace_back(ask[i] - 1);
  return query(p);
}

void solve(vector<pii> vec, int sum) {
  if (!sum) return;
  if (SZ(vec) == 1) {
    e[vec[0].fi].emplace_back(vec[0].se);
    e[vec[0].se].emplace_back(vec[0].fi);
    return;
  }
  int lsz = SZ(vec) / 2;
  vector<pii> L, R;
  rep (i, 0, lsz - 1) L.emplace_back(vec[i]);
  rep (i, lsz, SZ(vec) - 1) R.emplace_back(vec[i]);
  rep (i, 1, n) b[i] = a[i];
  for (auto [x, y] : L) b[x] = a[y], b[y] = a[x];
  int cur = get(b);
  solve(L, cur), solve(R, sum - cur);
}

void play(int _n) {
  n = _n;
  if (n == 1) return check(vector<int>({0})), void();
  rep (i, 1, n) a[i] = i;
  while (true) {
    shuffle(a + 1, a + n + 1, rnd);
    if (!get(a)) break;
  }
  rep (i, 1, n) cerr << a[i] << " \n"[i == n];
  if (n & 1) {
    rep (d, 1, (n + 1) / 2) {
      int x = d, y = d;
      rep (i, 1, n / 2) {
        x--, y++;
        if (x == 0) x = n;
        if (y > n) y = 1;
        vec[d].emplace_back(x, y);
      }
    }
    rep (d, 1, n / 2) {
      int x = d + 1, y = d;
      rep (i, 1, n / 2) {
        x--, y++;
        if (x == 0) x = n;
        if (y > n) y = 1;
        vec[d + (n + 1) / 2].emplace_back(x, y);
      }
    }
  } else {
    rep (d, 1, n / 2) {
      int x = d, y = d;
      rep (i, 1, n / 2 - 1) {
        x--, y++;
        if (x == 0) x = n;
        if (y > n) y = 1;
        vec[d].emplace_back(x, y);
      }
    }
    rep (d, 1, n / 2) {
      int x = d + 1, y = d;
      rep (i, 1, n / 2) {
        x--, y++;
        if (x == 0) x = n;
        if (y > n) y = 1;
        vec[d + n / 2].emplace_back(x, y);
      }
    }
  }
  rep (d, 1, n) {
    rep (i, 1, n) b[i] = a[i];
    for (auto [x, y] : vec[d]) b[x] = a[y], b[y] = a[x];
    solve(vec[d], get(b));
  }
  rep (x, 1, n) if (!ans[x]) {
    loop[tot = 1] = x;
    while (true) {
      int nxt = -1;
      for (int x : e[loop[tot]]) if (x != loop[tot - 1]) nxt = x;
      if (nxt == -1 || nxt == loop[1]) break;
      loop[++tot] = nxt;
    }
    rep (i, 1, n) b[i] = a[i];
    rep (i, 1, tot) b[loop[i]] = a[loop[i % tot + 1]];
    if (get(b) == tot) {
      rep (i, 1, tot) ans[loop[i]] = loop[i % tot + 1];
    } else {
      rep (i, 2, tot) ans[loop[i]] = loop[i - 1];
      ans[loop[1]] = loop[tot];
    }
  }
  rep (i, 1, n) b[i] = a[ans[i]];
  vector<int> res;
  rep (i, 1, n) res.emplace_back(b[i] - 1);
  check(res);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 2
Accepted
time: 0ms
memory: 3740kb

input:

1 2 816815200

result:

ok accepted: cnt = 5

Test #2:

score: 0
Time Limit Exceeded

input:

1 3 723182155

result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 4
Accepted
time: 0ms
memory: 3824kb

input:

2 2 931107645

result:

ok accepted: cnt = 5

Test #12:

score: 0
Time Limit Exceeded

input:

2 4 512124670

result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #21:

score: 6
Accepted
time: 0ms
memory: 3828kb

input:

3 2 667362636

result:

ok accepted: cnt = 4

Test #22:

score: 0
Time Limit Exceeded

input:

3 4 890842001

result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #36:

score: 0
Time Limit Exceeded

input:

4 100 6610818

result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #41:

score: 10
Accepted
time: 0ms
memory: 3784kb

input:

5 2 527801655

result:

ok accepted: cnt = 5

Test #42:

score: 0
Time Limit Exceeded

input:

5 5 235665947

result:


Subtask #6:

score: 0
Time Limit Exceeded

Test #51:

score: 10
Accepted
time: 0ms
memory: 3824kb

input:

6 2 183795068

result:

ok accepted: cnt = 5

Test #52:

score: 0
Time Limit Exceeded

input:

6 5 63668012

result:


Subtask #7:

score: 0
Time Limit Exceeded

Test #61:

score: 60
Accepted
time: 1ms
memory: 3952kb

input:

7 2 412859550

result:

ok accepted: cnt = 5

Test #62:

score: 0
Time Limit Exceeded

input:

7 4 892225546

result: