#include <bits/stdc++.h>
using namespace std;
int n;
void solve() {
cin >> n;
vector<int> ref(n);
iota(ref.begin(), ref.end(), 0);
vector<vector<int>> queries;
for (int src = 0; src < (n + 1) / 2; ++src) {
int i = src + 1, j = (src - 1 + n) % n;
vector<int> query(n, 0);
int num_colors = 1;
while (i != j) {
query[ref[i]] = query[ref[j]] = num_colors;
swap(ref[i], ref[j]);
num_colors += 1;
i = (i + 1) % n;
j = (j - 1 + n) % n;
if ((j + 1) % n == i) break;
}
queries.push_back(query);
}
for (int src = 0; src < (n + 1) / 2; ++src) {
int i = src + 1, j = src;
vector<int> query(n, 0);
int num_colors = 1;
while (i != j) {
query[ref[i]] = query[ref[j]] = num_colors;
swap(ref[i], ref[j]);
num_colors += 1;
i = (i + 1) % n;
j = (j - 1 + n) % n;
if (i == (j + 1) % n) break;
}
queries.push_back(query);
}
auto p = [&](vector<int> s) { s.resize(n); for (auto c : s) cout << c << " "; cout << "\n"; };
cout << queries.size() << "\n";
for (auto q : queries) p(q);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
solve();
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:49:9: warning: unused variable 't' [-Wunused-variable]
49 | int t = 1;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
If people start at 0 and 2, then they can avoid each other |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
If people start at 0 and 2, then they can avoid each other |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
If people start at 0 and 2, then they can avoid each other |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
If people start at 0 and 2, then they can avoid each other |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
If people start at 0 and 2, then they can avoid each other |
3 |
Halted |
0 ms |
0 KB |
- |