#include "dango3.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int n, m;
const int N = 401;
bool bad[N * 26];
int B = -1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
unordered_map<ll, int> mem;
int qr(vector<int> &f) {
ll it = 163, p = 163, mod = (ll)1e11 + 7, h = 0;
for(int i:f) {
h += it * 1ll * i % mod;
if(h >= mod) h -= mod;
it = it * p % mod;
}
if(mem.count(h)) return mem[h];
return mem[h] = Query(f);
}
vector<int> get(vector<int> &a) {
vector<int> b;
int l = -1,r = (int)a.size() - 1;
while(r - l > 1) {
int mid = (l + r) >> 1;
vector<int> t;
for(int j = 0; j <= mid; j++) {
t.push_back(a[j]);
}
if(qr(t)) {
r = mid;
} else {
l = mid;
}
}
for(int i = 0;i <= r; i++) {
b.push_back(a[i]);
}
reverse(b.begin(), b.end());
vector<int> c;
for(int i = 0; i < (int)b.size(); i++) {
vector<int> t = c;
for(int j = i + 1; j < (int)b.size(); j++) {
t.push_back(b[j]);
}
if(!qr(t)) {
c.push_back(b[i]);
}
}
return c;
}
int timer = 0, vis[N * 26];
void Solve(int _n, int _m) {
n = _n, m = _m;
vector<int> f, bf;
for(int i = 1; i <= n * m; i++) {
f.push_back(i);
}
shuffle(f.begin(), f.end(), rng);
for(int i = 0; i < m; i++) {
timer++;
vector<int> nv = get(f);
Answer(nv);
bf.push_back(nv[0]);
for(int j = 0; j < n; j++) {
vis[nv[j]] = timer;
}
vector<int> sw;
for(int j:f) {
if(vis[j] != timer) {
sw.push_back(j);
}
}
f = sw;
shuffle(f.begin(), f.end(), rng);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
600 KB |
Output is correct |
2 |
Correct |
6 ms |
520 KB |
Output is correct |
3 |
Correct |
7 ms |
600 KB |
Output is correct |
4 |
Correct |
8 ms |
600 KB |
Output is correct |
5 |
Correct |
6 ms |
604 KB |
Output is correct |
6 |
Correct |
7 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
1704 KB |
Output is correct |
2 |
Correct |
91 ms |
1656 KB |
Output is correct |
3 |
Correct |
89 ms |
1636 KB |
Output is correct |
4 |
Correct |
85 ms |
1364 KB |
Output is correct |
5 |
Correct |
98 ms |
1620 KB |
Output is correct |
6 |
Correct |
106 ms |
1716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
420 ms |
2784 KB |
Output is correct |
2 |
Correct |
404 ms |
3016 KB |
Output is correct |
3 |
Correct |
449 ms |
2948 KB |
Output is correct |
4 |
Correct |
514 ms |
2932 KB |
Output is correct |
5 |
Correct |
451 ms |
2988 KB |
Output is correct |
6 |
Correct |
424 ms |
2988 KB |
Output is correct |