#include <bits/stdc++.h>
using namespace std;
#define ar array
#define sz(v) int(std::size(v))
using i64 = long long;
using pii = pair<int, int>;
int s(int n) {
return n/40;
}
int calc(int l, int r) {
if (s(r) == s(l-1)) return 1;
if (l == r) return 1;
int m = (l+r)/2;
return 1+calc(l,m)+calc(m+1,r);
}
#ifdef LOCAL
int n, m, a[int(1e4)+1];
int Query(vector<int> v) {
vector<int> c(n);
for (int i : v) c[a[i]-1]++;
// for (int i : v) cout << i << ' ';
// cout << "| GOT " << *min_element(begin(c),end(c)) << endl;
return *min_element(begin(c),end(c));
}
void Answer(vector<int> v) {
for (int x : v) cout << x << ' ';
cout << endl;
}
#else
#include "dango3.h"
#endif
mt19937 rng(1234);
vector<int> operator+(const vector<int> one, vector<int> two) {
for (int x : one) two.push_back(x);
return two;
}
void Solve(int n, int m) {
vector<int> v;
for (int i = 1; i <= n*m; i++) v.push_back(i);
for (int it = 0; it < m; it++) {
for (int i = 0; i < sz(v); i++) swap(v[i], v[rng()%(i+1)]);
int low = n, hi = sz(v);
while (low < hi) {
int mid = (low+hi)/2;
if (Query(vector(begin(v), begin(v)+mid))) hi = mid;
else low = mid+1;
}
vector base(begin(v), begin(v)+low);
vector<int> good, bad;
for (int i = low-1; i >= 0; i--) {
int j = v[i];
if (Query(vector(begin(v), begin(v)+i) + good)) bad.push_back(j);
else good.push_back(j);
}
bad = bad + vector(begin(v)+low, end(v));
assert(sz(good) == n);
Answer(good);
v = bad;
}
}
#ifdef LOCAL
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n*m; i++) cin >> a[i];
Solve(n, m);
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
536 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
604 KB |
Output is correct |
2 |
Correct |
38 ms |
600 KB |
Output is correct |
3 |
Correct |
38 ms |
628 KB |
Output is correct |
4 |
Correct |
31 ms |
604 KB |
Output is correct |
5 |
Correct |
36 ms |
604 KB |
Output is correct |
6 |
Correct |
33 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
154 ms |
712 KB |
Output is correct |
2 |
Correct |
161 ms |
764 KB |
Output is correct |
3 |
Correct |
161 ms |
852 KB |
Output is correct |
4 |
Correct |
148 ms |
804 KB |
Output is correct |
5 |
Correct |
175 ms |
604 KB |
Output is correct |
6 |
Correct |
170 ms |
740 KB |
Output is correct |