#include <bits/stdc++.h>
using namespace std;
int block_type[9][2]={{0,0},{1,1},{1,-1},{-1,1},{-1,-1},{0,1},{0,-1},{1,0},{-1,0}};
vector<int> block[9];
int pos[9];
vector<int> ans;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
int left_bump=0,left_hole=0,right_bump=0,right_hole=0,start_type,end_type;
for(int i=0;i<n;i++){
int type,number;
cin>>type>>number;
if(type==5){
start_type=5;
}
else if(type==6){
start_type=6;
}
else if(type==7){
end_type=7;
}
else{
end_type=8;
}
if(block_type[type][0]==1){
left_bump++;
}
else if(block_type[type][0]==-1){
left_hole++;
}
if(block_type[type][1]==1){
right_bump++;
}
else if(block_type[type][1]==-1){
right_hole++;
}
block[type].push_back(number);
}
for(int i=1;i<9;i++){
sort(block[i].begin(),block[i].end());
}
if(left_bump!=right_hole||right_bump!=left_hole){
cout<<"-1\n";
return 0;
}
ans.push_back(block[start_type][0]);
if(start_type==5){
right_bump--;
}
else{
right_hole--;
}
pos[start_type]++;
int now=start_type;
for(int i=0;i<n-1;i++){
int next_type;
int idx=-1;
for(int j=1;j<=8;j++){
if(block_type[now][1]+block_type[j][0]==0&&pos[j]!=block[j].size()){
if(idx==-1||block[idx][pos[j]]>block[j][pos[j]]){
if(!(i!=n-3&&((block_type[j][1]==1&&left_hole==1&&end_type==8)||(block_type[j][1]==-1&&left_bump==1&&end_type==7)))){
idx=j;
}
}
}
}
if(idx==-1){
cout<<"-1\n";
return 0;
}
ans.push_back(block[idx][pos[idx]]);
pos[idx]++;
if(block_type[idx][0]==1){
left_bump--;
}
else if(block_type[idx][0]==-1){
left_hole--;
}
if(block_type[idx][1]==1){
right_bump--;
}
else if(block_type[idx][1]==-1){
right_hole--;
}
now=idx;
}
for(int i=0;i<n;i++){
cout<<ans[i]<<" \n"[i==n-1];
}
return 0;
}
Compilation message
slagalica.cpp: In function 'int main()':
slagalica.cpp:66:62: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | if(block_type[now][1]+block_type[j][0]==0&&pos[j]!=block[j].size()){
| ~~~~~~^~~~~~~~~~~~~~~~~
slagalica.cpp:63:13: warning: unused variable 'next_type' [-Wunused-variable]
63 | int next_type;
| ^~~~~~~~~
slagalica.cpp:68:130: warning: 'end_type' may be used uninitialized in this function [-Wmaybe-uninitialized]
68 | if(!(i!=n-3&&((block_type[j][1]==1&&left_hole==1&&end_type==8)||(block_type[j][1]==-1&&left_bump==1&&end_type==7)))){
| ~~~~~~~~^~~
slagalica.cpp:60:19: warning: 'start_type' may be used uninitialized in this function [-Wmaybe-uninitialized]
60 | pos[start_type]++;
| ~~~~~~~~~~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
41 ms |
2108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
2048 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1664 KB |
Output is correct |
2 |
Incorrect |
24 ms |
1796 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1508 KB |
Output is correct |
2 |
Correct |
33 ms |
2644 KB |
Output is correct |
3 |
Incorrect |
28 ms |
1744 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
2788 KB |
Output is correct |
2 |
Correct |
29 ms |
1604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
2640 KB |
Output is correct |
2 |
Correct |
23 ms |
1596 KB |
Output is correct |
3 |
Correct |
35 ms |
2752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
1708 KB |
Output is correct |
2 |
Incorrect |
36 ms |
2472 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
2220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
2120 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
34 ms |
3008 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
2780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
2160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |