#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define sz(v) int(std::size(v))
using i64 = long long;
const int MAXN = 2e5;
int N, K;
// int L[MAXN], R[MAXN], U[MAXN], D[MAXN];
ar<int, 4> V[MAXN];
int order[MAXN], __[MAXN];
vector<int> breaks;
bool done[MAXN];
// vector<int> X, Y;
ar<int, 2> solutions[4];
ar<int, 4> operator+(const ar<int, 4> one, const ar<int, 4> two) {
if (one[0] == -1 || two[0] == -1 || max(one[0], two[0]) > min(one[1], two[1]) || max(one[2], two[2]) > min(one[3], two[3])) return {-1, -1, -1, -1};
return {max(one[0], two[0]), min(one[1], two[1]), max(one[2], two[2]), min(one[3], two[3])};
}
mt19937 rng(1234);
int marbles[MAXN];
void shuf() {
reverse(order, order + N);
for (int i = 0; i < N; i++) {
int p = i;
int num = __lg(marbles[order[i]]) + 1;
for (int rep = 0; rep < num; rep++) {
int q = rng() % (p + 1);
swap(order[p], order[q]), p = q;
}
}
reverse(order, order + N);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> K;
for (int i = 0; i < N; i++) {
int l, r, u, d;
cin >> l >> d >> r >> u;
V[i] = {l, r, d, u};
// cin >> L[i] >> R[i] >> U[i] >> D[i];
/*
X.push_back(L[i]);
X.push_back(R[i]);
Y.push_back(U[i]);
Y.push_back(D[i]);
*/
order[i] = i;
marbles[i] = 1;
}
/*
sort(begin(X), end(X));
X.erase(unique(begin(X), end(X)), end(X));
sort(begin(Y), end(Y));
Y.erase(unique(begin(Y), end(Y)), end(Y));
*/
shuf();
while (1) {
fill(done, done + N, false);
int i = 0;
for (int rep = 0; rep < K; rep++) {
while (i < N && done[i]) i++;
if (i == N) {
while (rep < K)
solutions[rep++] = {1, 1};
break;
}
done[i] = 1;
auto v = V[order[i]];
for (int j = i + 1; j < N; j++) if (!done[j] && (v + V[order[j]])[0] != -1) {
v = v + V[order[j]];
done[j] = 1;
}
solutions[rep] = {v[0], v[2]};
}
for (int i = 0; i < N; i++) if (done[i])
marbles[i]++;
if (!count(done, done + N, false)) {
for (int i = 0; i < K; i++)
cout << solutions[i][0] << " " << solutions[i][1] << '\n';
break;
}
shuf();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
2 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
4636 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
17 ms |
4532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4440 KB |
Output is correct |
2 |
Correct |
8 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4440 KB |
Output is correct |
4 |
Correct |
2 ms |
4580 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4596 KB |
Output is correct |
8 |
Correct |
961 ms |
4696 KB |
Output is correct |
9 |
Correct |
55 ms |
4444 KB |
Output is correct |
10 |
Correct |
190 ms |
4640 KB |
Output is correct |
11 |
Correct |
7 ms |
4440 KB |
Output is correct |
12 |
Correct |
64 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4440 KB |
Output is correct |
2 |
Correct |
10 ms |
4444 KB |
Output is correct |
3 |
Correct |
4 ms |
4444 KB |
Output is correct |
4 |
Correct |
3 ms |
4444 KB |
Output is correct |
5 |
Correct |
13 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
1515 ms |
4632 KB |
Output is correct |
8 |
Correct |
290 ms |
4444 KB |
Output is correct |
9 |
Correct |
2693 ms |
4628 KB |
Output is correct |
10 |
Correct |
2938 ms |
4624 KB |
Output is correct |
11 |
Execution timed out |
3009 ms |
4440 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
2 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4572 KB |
Output is correct |
5 |
Correct |
66 ms |
12316 KB |
Output is correct |
6 |
Correct |
70 ms |
12372 KB |
Output is correct |
7 |
Correct |
65 ms |
12312 KB |
Output is correct |
8 |
Correct |
79 ms |
12224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
4636 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
17 ms |
4532 KB |
Output is correct |
5 |
Correct |
1669 ms |
12492 KB |
Output is correct |
6 |
Execution timed out |
3083 ms |
12240 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4440 KB |
Output is correct |
2 |
Correct |
8 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4440 KB |
Output is correct |
4 |
Correct |
2 ms |
4580 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4596 KB |
Output is correct |
8 |
Correct |
961 ms |
4696 KB |
Output is correct |
9 |
Correct |
55 ms |
4444 KB |
Output is correct |
10 |
Correct |
190 ms |
4640 KB |
Output is correct |
11 |
Correct |
7 ms |
4440 KB |
Output is correct |
12 |
Correct |
64 ms |
4444 KB |
Output is correct |
13 |
Correct |
542 ms |
12492 KB |
Output is correct |
14 |
Correct |
2180 ms |
12256 KB |
Output is correct |
15 |
Correct |
2932 ms |
12256 KB |
Output is correct |
16 |
Execution timed out |
3036 ms |
12116 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4440 KB |
Output is correct |
2 |
Correct |
10 ms |
4444 KB |
Output is correct |
3 |
Correct |
4 ms |
4444 KB |
Output is correct |
4 |
Correct |
3 ms |
4444 KB |
Output is correct |
5 |
Correct |
13 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
1515 ms |
4632 KB |
Output is correct |
8 |
Correct |
290 ms |
4444 KB |
Output is correct |
9 |
Correct |
2693 ms |
4628 KB |
Output is correct |
10 |
Correct |
2938 ms |
4624 KB |
Output is correct |
11 |
Execution timed out |
3009 ms |
4440 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |