#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());
map<vector<int> , int> mem;
int qr(vector<int> f) {
sort(f.begin(), f.end());
if(mem.count(f)) {
return mem[f];
}
return mem[f] = Query(f);
}
vector<int> get(vector<int> &a, vector<int> &b) {
for(int j:a) {
bad[j] = 0;
}
int lst = 0;
vector<int> ret;
int new_B = -1;
for(int i = 0; i < m; i++) {
int l = lst - 1, r = (int)a.size() - 1;
if(B != -1 && i == 0) {
r = B;
}
int left = m - i;
if(left == (int)a.size() - lst) {
for(int j = lst; j < (int)a.size(); j++) {
ret.push_back(a[j]);
}
break;
}
while(r - l > 1) {
int mid = (l + r) >> 1;
vector<int> t = b;
for(int j = 0; j <= mid; j++) {
if(!bad[a[j]])t.push_back(a[j]);
}
if(qr(t)) {
r = mid;
} else {
l = mid;
}
}
lst = r + 1;
ret.push_back(a[r]);
bad[a[r]] = 1;
if(i == 0 && B == -1) {
new_B = r - 1;
}
}
B = new_B;
return ret;
}
vector<int> res[N];
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 < n; i++) {
timer++;
vector<int> nv = get(f, bf);
bf.push_back(nv[0]);
for(int j = 0; j < m; j++) {
// cout << nv[j] << ' ';
res[j].push_back(nv[j]);
vis[nv[j]] = timer;
}
// cout << '\n';
vector<int> sw;
for(int j:f) {
if(vis[j] != timer) {
sw.push_back(j);
}
}
f = sw;
}
for(int i = 0; i < m; i++) {
Answer(res[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
11348 KB |
Output is correct |
2 |
Correct |
98 ms |
11088 KB |
Output is correct |
3 |
Correct |
80 ms |
7504 KB |
Output is correct |
4 |
Correct |
77 ms |
8160 KB |
Output is correct |
5 |
Correct |
68 ms |
11088 KB |
Output is correct |
6 |
Correct |
86 ms |
11092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2756 ms |
287308 KB |
Output is correct |
2 |
Correct |
2926 ms |
288760 KB |
Output is correct |
3 |
Correct |
5027 ms |
289472 KB |
Output is correct |
4 |
Correct |
5331 ms |
300628 KB |
Output is correct |
5 |
Correct |
2041 ms |
287120 KB |
Output is correct |
6 |
Correct |
1990 ms |
285084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9515 ms |
847048 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |