QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572056#8952. 解谜游戏wsyear100 ✓40ms8264kbC++233.2kb2024-09-18 11:35:522024-09-18 11:35:54

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 11:35:54]
  • 评测
  • 测评结果:100
  • 用时:40ms
  • 内存:8264kb
  • [2024-09-18 11:35:52]
  • 提交

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;

unsigned long long seed=998244353;
unsigned long long get_rand()
{
	seed^=(seed<<7);
	seed^=(seed>>11);
	seed^=(seed<<17);
	return seed;
}

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) {
    rep (i, 2, n) swap(a[i], a[get_rand() % i + 1]);
    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: 2
Accepted

Test #1:

score: 2
Accepted
time: 1ms
memory: 3812kb

input:

1 2 816815200

result:

ok accepted: cnt = 4

Test #2:

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

input:

1 3 723182155

result:

ok accepted: cnt = 8

Test #3:

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

input:

1 5 971867682

result:

ok accepted: cnt = 13

Test #4:

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

input:

1 3 887042235

result:

ok accepted: cnt = 9

Test #5:

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

input:

1 3 568659743

result:

ok accepted: cnt = 8

Test #6:

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

input:

1 5 930991667

result:

ok accepted: cnt = 11

Test #7:

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

input:

1 5 185481439

result:

ok accepted: cnt = 15

Test #8:

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

input:

1 5 405685705

result:

ok accepted: cnt = 13

Test #9:

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

input:

1 5 693401039

result:

ok accepted: cnt = 10

Test #10:

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

input:

1 5 570594473

result:

ok accepted: cnt = 14

Subtask #2:

score: 4
Accepted

Test #11:

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

input:

2 2 931107645

result:

ok accepted: cnt = 4

Test #12:

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

input:

2 4 512124670

result:

ok accepted: cnt = 7

Test #13:

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

input:

2 4 793864173

result:

ok accepted: cnt = 8

Test #14:

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

input:

2 7 322910591

result:

ok accepted: cnt = 21

Test #15:

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

input:

2 9 316192686

result:

ok accepted: cnt = 27

Test #16:

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

input:

2 10 350886420

result:

ok accepted: cnt = 31

Test #17:

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

input:

2 10 914937911

result:

ok accepted: cnt = 29

Test #18:

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

input:

2 10 68729974

result:

ok accepted: cnt = 28

Test #19:

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

input:

2 10 15788440

result:

ok accepted: cnt = 30

Test #20:

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

input:

2 10 950846282

result:

ok accepted: cnt = 38

Subtask #3:

score: 6
Accepted

Test #21:

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

input:

3 2 667362636

result:

ok accepted: cnt = 9

Test #22:

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

input:

3 4 890842001

result:

ok accepted: cnt = 7

Test #23:

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

input:

3 3 225277415

result:

ok accepted: cnt = 5

Test #24:

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

input:

3 26 235413642

result:

ok accepted: cnt = 108

Test #25:

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

input:

3 25 139642984

result:

ok accepted: cnt = 92

Test #26:

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

input:

3 30 991911708

result:

ok accepted: cnt = 135

Test #27:

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

input:

3 30 4514256

result:

ok accepted: cnt = 126

Test #28:

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

input:

3 30 157113423

result:

ok accepted: cnt = 124

Test #29:

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

input:

3 30 557648974

result:

ok accepted: cnt = 139

Test #30:

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

input:

3 30 645022468

result:

ok accepted: cnt = 132

Test #31:

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

input:

4 2 427653480

result:

ok accepted: cnt = 9

Test #32:

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

input:

4 3 219860551

result:

ok accepted: cnt = 8

Test #33:

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

input:

4 4 165138325

result:

ok accepted: cnt = 8

Test #34:

score: 6
Accepted
time: 1ms
memory: 3944kb

input:

4 93 525060479

result:

ok accepted: cnt = 566

Test #35:

score: 6
Accepted
time: 1ms
memory: 3904kb

input:

4 99 829735778

result:

ok accepted: cnt = 599

Subtask #4:

score: 8
Accepted

Test #36:

score: 8
Accepted
time: 1ms
memory: 4204kb

input:

4 100 6610818

result:

ok accepted: cnt = 607

Test #37:

score: 8
Accepted
time: 0ms
memory: 4212kb

input:

4 100 653323659

result:

ok accepted: cnt = 579

Test #38:

score: 8
Accepted
time: 1ms
memory: 4200kb

input:

4 100 268513130

result:

ok accepted: cnt = 599

Test #39:

score: 8
Accepted
time: 0ms
memory: 4208kb

input:

4 100 479581529

result:

ok accepted: cnt = 610

Test #40:

score: 8
Accepted
time: 1ms
memory: 3908kb

input:

4 100 119844914

result:

ok accepted: cnt = 609

Subtask #5:

score: 10
Accepted

Test #41:

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

input:

5 2 527801655

result:

ok accepted: cnt = 4

Test #42:

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

input:

5 5 235665947

result:

ok accepted: cnt = 14

Test #43:

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

input:

5 3 648413779

result:

ok accepted: cnt = 5

Test #44:

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

input:

5 272 737778828

result:

ok accepted: cnt = 2032

Test #45:

score: 10
Accepted
time: 4ms
memory: 4644kb

input:

5 278 173436130

result:

ok accepted: cnt = 2040

Test #46:

score: 10
Accepted
time: 4ms
memory: 4556kb

input:

5 300 997862299

result:

ok accepted: cnt = 2240

Test #47:

score: 10
Accepted
time: 4ms
memory: 4572kb

input:

5 300 764271855

result:

ok accepted: cnt = 2237

Test #48:

score: 10
Accepted
time: 4ms
memory: 4500kb

input:

5 300 428892383

result:

ok accepted: cnt = 2236

Test #49:

score: 10
Accepted
time: 4ms
memory: 4788kb

input:

5 300 166706392

result:

ok accepted: cnt = 2258

Test #50:

score: 10
Accepted
time: 4ms
memory: 4688kb

input:

5 300 843444435

result:

ok accepted: cnt = 2253

Subtask #6:

score: 10
Accepted

Test #51:

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

input:

6 2 183795068

result:

ok accepted: cnt = 4

Test #52:

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

input:

6 5 63668012

result:

ok accepted: cnt = 12

Test #53:

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

input:

6 5 990398365

result:

ok accepted: cnt = 12

Test #54:

score: 10
Accepted
time: 9ms
memory: 4892kb

input:

6 488 942578687

result:

ok accepted: cnt = 4000

Test #55:

score: 10
Accepted
time: 9ms
memory: 4856kb

input:

6 475 915148470

result:

ok accepted: cnt = 3837

Test #56:

score: 10
Accepted
time: 10ms
memory: 5112kb

input:

6 500 736505651

result:

ok accepted: cnt = 4119

Test #57:

score: 10
Accepted
time: 11ms
memory: 4980kb

input:

6 500 352417213

result:

ok accepted: cnt = 4131

Test #58:

score: 10
Accepted
time: 10ms
memory: 4928kb

input:

6 500 80534667

result:

ok accepted: cnt = 4095

Test #59:

score: 10
Accepted
time: 9ms
memory: 4868kb

input:

6 500 811975157

result:

ok accepted: cnt = 4096

Test #60:

score: 10
Accepted
time: 6ms
memory: 4916kb

input:

6 500 471392863

result:

ok accepted: cnt = 4143

Subtask #7:

score: 60
Accepted

Test #61:

score: 60
Accepted
time: 0ms
memory: 3860kb

input:

7 2 412859550

result:

ok accepted: cnt = 4

Test #62:

score: 60
Accepted
time: 0ms
memory: 3856kb

input:

7 4 892225546

result:

ok accepted: cnt = 9

Test #63:

score: 60
Accepted
time: 0ms
memory: 4156kb

input:

7 4 577686541

result:

ok accepted: cnt = 10

Test #64:

score: 60
Accepted
time: 28ms
memory: 7540kb

input:

7 902 974849567

result:

ok accepted: cnt = 8195

Test #65:

score: 60
Accepted
time: 30ms
memory: 8008kb

input:

7 939 155203710

result:

ok accepted: cnt = 8572

Test #66:

score: 60
Accepted
time: 38ms
memory: 8168kb

input:

7 1000 253107507

result:

ok accepted: cnt = 9190

Test #67:

score: 60
Accepted
time: 39ms
memory: 8164kb

input:

7 1000 882029420

result:

ok accepted: cnt = 9194

Test #68:

score: 60
Accepted
time: 35ms
memory: 7920kb

input:

7 1000 199421982

result:

ok accepted: cnt = 9149

Test #69:

score: 60
Accepted
time: 39ms
memory: 8260kb

input:

7 1000 749220884

result:

ok accepted: cnt = 9205

Test #70:

score: 60
Accepted
time: 38ms
memory: 8172kb

input:

7 1000 729055050

result:

ok accepted: cnt = 9158

Test #71:

score: 60
Accepted
time: 0ms
memory: 3864kb

input:

7 2 375338281

result:

ok accepted: cnt = 9

Test #72:

score: 60
Accepted
time: 0ms
memory: 3812kb

input:

7 5 914443594

result:

ok accepted: cnt = 13

Test #73:

score: 60
Accepted
time: 0ms
memory: 4144kb

input:

7 5 310479620

result:

ok accepted: cnt = 12

Test #74:

score: 60
Accepted
time: 33ms
memory: 8184kb

input:

7 982 660842623

result:

ok accepted: cnt = 9061

Test #75:

score: 60
Accepted
time: 33ms
memory: 7936kb

input:

7 985 92435101

result:

ok accepted: cnt = 9030

Test #76:

score: 60
Accepted
time: 37ms
memory: 7988kb

input:

7 1000 901527471

result:

ok accepted: cnt = 9101

Test #77:

score: 60
Accepted
time: 38ms
memory: 7936kb

input:

7 1000 891945482

result:

ok accepted: cnt = 9179

Test #78:

score: 60
Accepted
time: 35ms
memory: 7920kb

input:

7 1000 461988571

result:

ok accepted: cnt = 9199

Test #79:

score: 60
Accepted
time: 40ms
memory: 7920kb

input:

7 1000 588921486

result:

ok accepted: cnt = 9178

Test #80:

score: 60
Accepted
time: 39ms
memory: 8264kb

input:

7 1000 819181186

result:

ok accepted: cnt = 9222

Test #81:

score: 60
Accepted
time: 0ms
memory: 3852kb

input:

7 2 509390821

result:

ok accepted: cnt = 4

Test #82:

score: 60
Accepted
time: 0ms
memory: 3856kb

input:

7 3 932973010

result:

ok accepted: cnt = 5

Test #83:

score: 60
Accepted
time: 0ms
memory: 3888kb

input:

7 3 704198002

result:

ok accepted: cnt = 6

Test #84:

score: 60
Accepted
time: 35ms
memory: 8248kb

input:

7 996 844688748

result:

ok accepted: cnt = 9174

Test #85:

score: 60
Accepted
time: 33ms
memory: 7772kb

input:

7 935 983758765

result:

ok accepted: cnt = 8491

Test #86:

score: 60
Accepted
time: 34ms
memory: 7936kb

input:

7 1000 560957955

result:

ok accepted: cnt = 9073

Test #87:

score: 60
Accepted
time: 35ms
memory: 7984kb

input:

7 1000 381616996

result:

ok accepted: cnt = 9171

Test #88:

score: 60
Accepted
time: 40ms
memory: 7980kb

input:

7 1000 607168013

result:

ok accepted: cnt = 9206

Test #89:

score: 60
Accepted
time: 35ms
memory: 7976kb

input:

7 1000 755432541

result:

ok accepted: cnt = 9176

Test #90:

score: 60
Accepted
time: 36ms
memory: 7972kb

input:

7 1000 675700852

result:

ok accepted: cnt = 9209

Test #91:

score: 60
Accepted
time: 0ms
memory: 3892kb

input:

7 2 91873452

result:

ok accepted: cnt = 4

Test #92:

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

input:

7 4 336570576

result:

ok accepted: cnt = 7

Test #93:

score: 60
Accepted
time: 0ms
memory: 3860kb

input:

7 4 617201184

result:

ok accepted: cnt = 9

Test #94:

score: 60
Accepted
time: 28ms
memory: 7644kb

input:

7 904 396880646

result:

ok accepted: cnt = 8251

Test #95:

score: 60
Accepted
time: 32ms
memory: 7552kb

input:

7 906 970970547

result:

ok accepted: cnt = 8190

Test #96:

score: 60
Accepted
time: 35ms
memory: 8000kb

input:

7 1000 960558936

result:

ok accepted: cnt = 9228

Test #97:

score: 60
Accepted
time: 38ms
memory: 7984kb

input:

7 1000 238446836

result:

ok accepted: cnt = 9128

Test #98:

score: 60
Accepted
time: 38ms
memory: 8004kb

input:

7 1000 897094536

result:

ok accepted: cnt = 9125

Test #99:

score: 60
Accepted
time: 34ms
memory: 8168kb

input:

7 1000 820891454

result:

ok accepted: cnt = 9186

Test #100:

score: 60
Accepted
time: 34ms
memory: 7976kb

input:

7 1000 586475353

result:

ok accepted: cnt = 9119