/**
_ _ __ _ _ _ _ _ _
|a ||t ||o d | |o |
| __ _| | _ | __| _ |
| __ |/_ | __ /__\ / _\|
**/
#include <bits/stdc++.h>
#include "dango3.h"
using namespace std;
typedef long long ll;
int Query (const vector <int> &x);
void Answer (const vector <int> &a);
void Solve (int N, int M) {
int A[N * M + 2];
fill(A + 1, A + N * M + 1, 0);
int l = 1, r = N * M;
while (l < r) {
int mid = (l + r) / 2;
vector <int> x;
for (int i = 1; i <= mid; i++) {
x.push_back(i);
}
if (Query(x) > 0) {
r = mid;
} else {
l = mid + 1;
}
}
bool in[N * M + 2];
fill(in + 1, in + N * M + 1, false);
for (int i = 1; i <= l; i++) {
in[i] = true;
}
vector <int> group;
for (int i = N * M; i >= 1; i--) {
if (in[i] == true) {
in[i] = false;
vector <int> x;
for (int j = 1; j <= N * M; j++) {
if (in[j] == true) {
x.push_back(j);
}
}
if (Query(x) == 0) {
in[i] = true;
}
}
}
for (int i = 1; i <= N * M; i++) {
if (in[i] == true) {
group.push_back(i);
A[i] = (int) group.size();
}
}
for (int i = 1; i <= N * M; i++) {
if (A[i] == 0) {
int l = 1, r = N;
while (l < r) {
int mid = (l + r) / 2;
vector <int> x;
for (int j = 1; j <= N * M; j++) {
if ((in[j] == false || A[j] <= mid) && j != i) {
x.push_back(j);
}
}
if (Query(x) == M - 1) {
r = mid;
} else {
l = mid + 1;
}
}
A[i] = l;
}
}
vector <int> of_color[N + 2];
for (int i = 1; i <= N * M; i++) {
of_color[A[i]].push_back(i);
}
for (int t = 1; t <= M; t++) {
vector <int> a;
for (int c = 1; c <= N; c++) {
a.push_back(of_color[c].back());
of_color[c].pop_back();
}
Answer(a);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
492 KB |
Output is correct |
2 |
Correct |
27 ms |
348 KB |
Output is correct |
3 |
Correct |
31 ms |
348 KB |
Output is correct |
4 |
Correct |
31 ms |
504 KB |
Output is correct |
5 |
Correct |
27 ms |
348 KB |
Output is correct |
6 |
Correct |
27 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
780 ms |
596 KB |
Output is correct |
2 |
Correct |
779 ms |
564 KB |
Output is correct |
3 |
Correct |
943 ms |
568 KB |
Output is correct |
4 |
Correct |
948 ms |
848 KB |
Output is correct |
5 |
Correct |
753 ms |
600 KB |
Output is correct |
6 |
Correct |
756 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2005 ms |
656 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |