#include "dango3.h"
#include <bits/stdc++.h>
using ll = int;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define BIT(mask,i) (((mask) >> (i))&1LL)
#define MASK(i) (1LL<<(i))
#define sz(a) (ll((a).size()))
namespace {
vector <ll> color[401];
mt19937_64 rng(69420);
}
void Solve(int n,int m) {
vector <ll> a(n*m);
iota(a.begin(),a.end(),1);
shuffle(a.begin(),a.end(),rng);
ll rem = m;
set <ll> lft;
for (ll i = 1;i <= n * m;i ++)lft.insert(i);
auto alldif = [&](vector <ll> x) -> bool{
if (sz(x) < 2)return 1;
for (auto y:x)lft.erase(y);
vector <ll> tmp(lft.begin(),lft.end());
for (auto y:x)lft.insert(y);
return (Query(tmp) == rem - 1);
};
for (ll i = 0;i < n * m;i ++){
ll id = a[i];
vector <ll> x;
for (ll j = 1;j <= n;j ++){
if (sz(color[j]))x.push_back(color[j][0]);
}
x.push_back(id);
if (sz(x) <= n && alldif(x)){
for (ll j = 1;j <= n;j ++){
if (!sz(color[j])){color[j].push_back(id);break;}
}
}
else{
x.pop_back();
ll l = 0;
ll r = sz(x) - 1;
ll found = -1;
while (l <= r){
ll mid = (l + r) >> 1;
vector <ll> tmp;
for (ll i = 0;i <= mid;i ++)tmp.push_back(x[i]);
tmp.push_back(id);
if (alldif(tmp)){
l = mid + 1;
}
else{
found = x[mid];
r = mid - 1;
}
}
for (ll j = 1;j <= n;j ++){
if (sz(color[j]) && color[j][0] == found){color[j].push_back(id);break;}
}
}
ll cnt = 0;
for (ll j = 1;j <= n;j ++){
if (sz(color[j]))cnt++;
}
if (cnt == n){
vector <ll> ans;
for (ll j = 1;j <= n;j ++){
ans.push_back(color[j].back());
color[j].pop_back();
}
Answer(ans);
for (auto x:ans)lft.erase(x);
rem--;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
568 KB |
Output is correct |
2 |
Correct |
83 ms |
568 KB |
Output is correct |
3 |
Correct |
95 ms |
544 KB |
Output is correct |
4 |
Correct |
93 ms |
568 KB |
Output is correct |
5 |
Correct |
86 ms |
548 KB |
Output is correct |
6 |
Correct |
87 ms |
572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2407 ms |
832 KB |
Output is correct |
2 |
Correct |
2447 ms |
840 KB |
Output is correct |
3 |
Correct |
2561 ms |
836 KB |
Output is correct |
4 |
Correct |
2464 ms |
808 KB |
Output is correct |
5 |
Correct |
2508 ms |
828 KB |
Output is correct |
6 |
Correct |
2470 ms |
828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9115 ms |
1416 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |