#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> vec[10], g[10];
for (int i = 0; i < n; i ++){
int x, y;
cin >> x >> y;
vec[x].push_back(y);
}
for (int i = 1; i <= 8; i ++)
sort(vec[i].rbegin(), vec[i].rend());
g[5] = {3, 4};
g[6] = {1, 2};
g[1] = {3, 4};
g[2] = {1, 2};
g[3] = {3, 4};
g[4] = {1, 2};
vector<int> answer, types;
for (int x : vec[5]){
answer.push_back(x);
types.push_back(5);
}
for (int x : vec[6]){
answer.push_back(x);
types.push_back(6);
}
while (1){
int last = types.back();
int min_t = -1;
for (int t : g[last]){
if (vec[t].size() == 0) continue;
if (t == 3 and vec[1].size() == 0){
min_t = 3;
break;
}
if (t == 1 and vec[1].size() == 1 and vec[2].size() > 0) continue;
if (vec[t].size() and (min_t == -1 or vec[min_t].back() > vec[t].back()))
min_t = t;
}
bool all = 1;
for (int i = 1; i <= 4; i ++)
all &= (vec[i].size() == 0);
if (all) break;
if (!all and min_t == -1){
cout << -1 << endl;
return 0;
}
types.push_back(min_t);
answer.push_back(vec[min_t].back());
vec[min_t].pop_back();
}
int last = types.back();
int have = 7;
if (vec[8].size()) have = 8;
if ((have == 7 and (last == 2 or last == 4)) or (have == 8 and (last == 1 or last == 3)))
answer.push_back(vec[have][0]);
else{
cout << -1 << endl;
return 0;
}
for (int x : answer)
cout << x << " ";
cout << endl;
}
# |
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 |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
3440 KB |
Output is correct |
2 |
Correct |
33 ms |
2684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3292 KB |
Output is correct |
2 |
Correct |
32 ms |
2676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
2468 KB |
Output is correct |
2 |
Correct |
34 ms |
3320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
2168 KB |
Output is correct |
2 |
Correct |
34 ms |
3464 KB |
Output is correct |
3 |
Correct |
44 ms |
3848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3324 KB |
Output is correct |
2 |
Correct |
31 ms |
2300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
3532 KB |
Output is correct |
2 |
Correct |
28 ms |
2308 KB |
Output is correct |
3 |
Correct |
39 ms |
3636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
2772 KB |
Output is correct |
2 |
Correct |
33 ms |
3464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
3924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
3232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
3788 KB |
Output is correct |
2 |
Correct |
32 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3272 KB |
Output is correct |
2 |
Correct |
35 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
3268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |