| Task: | Enumeration |
| Sender: | Hornet's Multithreading |
| Submission time: | 2025-11-08 15:16:27 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.02 s | details |
| #2 | ACCEPTED | 0.02 s | details |
| #3 | ACCEPTED | 0.02 s | details |
| #4 | ACCEPTED | 0.02 s | details |
| #5 | ACCEPTED | 0.02 s | details |
| #6 | WRONG ANSWER | 0.03 s | details |
| #7 | WRONG ANSWER | 0.05 s | details |
| #8 | WRONG ANSWER | 0.18 s | details |
| #9 | WRONG ANSWER | 0.80 s | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
Compiler report
input/code.cpp: In function 'void backtrack(int, int, int)':
input/code.cpp:48:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int ii = 1; ii < path.size(); ii++) {
| ~~~^~~~~~~~~~~~~Code
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int n;
vector<array<int, 3>> adj[1 << N];
// 0: open
// 1: close
bool check(int x) {
int s = 0;
for (int i = n - 1; i >= 0; i--) {
if (x >> i & 1) {
s--;
} else {
s++;
}
if (s < 0) {
return false;
}
}
return s == 0;
}
int flip(int val, int x, int y) {
assert(x != y);
val ^= (1 << x);
val ^= (1 << y);
return val;
}
bool vis[1 << N];
vector<pair<int, int>> path;
void backtrack(int u, int i, int j) {
// cerr << u << '\n';
int cnt = 0;
for (auto [v, ii, jj] : adj[u]) {
if (vis[v]) continue;
cnt++;
}
if (cnt == 0) {
cout << string(n/2, '(');
cout << string(n/2, ')');
cout << '\n';
path.emplace_back(i, j);
for (int ii = 1; ii < path.size(); ii++) {
cout << path[ii].first + 1 << ' ' << path[ii].second + 1 << '\n';
}
exit(0);
}
vis[u] = 1;
path.emplace_back(i, j);
for (auto [v, ii, jj]: adj[u]) {
if (vis[v]) continue;
backtrack(v,ii,jj);
}
vis[u] = 0;
path.pop_back();
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int val = 0; val < (1 << n); val++) {
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (check(flip(val, i, j))) {
adj[val].emplace_back(array<int, 3>{flip(val, i, j), i, j});
}
}
}
}
int src = (1 << (n / 2)) - 1;
backtrack(src,0,0);
return 0;
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 2 |
| correct output |
|---|
| () |
| user output |
|---|
| () |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 4 |
| correct output |
|---|
| ()() 2 3 |
| user output |
|---|
| (()) 2 3 |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 6 |
| correct output |
|---|
| ()()() 2 3 4 5 3 2 2 4 |
| user output |
|---|
| ((())) 2 4 2 3 4 5 2 3 |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 8 |
| correct output |
|---|
| ()()()() 2 3 4 5 3 2 2 4 ... |
| user output |
|---|
| (((()))) 2 5 2 3 3 4 2 6 ... |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 10 |
| correct output |
|---|
| ()()()()() 2 3 4 5 3 2 2 4 ... |
| user output |
|---|
| ((((())))) 2 6 2 3 3 4 2 7 ... |
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| 12 |
| correct output |
|---|
| ()()()()()() 2 3 4 5 3 2 2 4 ... |
| user output |
|---|
| (((((()))))) 2 7 2 3 3 4 2 8 ... |
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 14 |
| correct output |
|---|
| ()()()()()()() 2 3 4 5 3 2 2 4 ... |
| user output |
|---|
| ((((((())))))) 2 8 2 3 3 4 2 9 ... |
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 16 |
| correct output |
|---|
| ()()()()()()()() 2 3 4 5 3 2 2 4 ... |
| user output |
|---|
| (((((((()))))))) 2 9 2 3 3 4 2 10 ... |
Test 9
Verdict: WRONG ANSWER
| input |
|---|
| 18 |
| correct output |
|---|
| ()()()()()()()()() 2 3 4 5 3 2 2 4 ... |
| user output |
|---|
| ((((((((())))))))) 2 10 2 3 3 4 2 11 ... |
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 20 |
| correct output |
|---|
| ()()()()()()()()()() 2 3 4 5 3 2 2 4 ... |
| user output |
|---|
| (empty) |
