#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int n;
vector<int>e[9];
pair<int,int>ar[9];
signed main(){
ar[1]={1,1};
ar[2]={1,0};
ar[3]={0,1};
ar[4]={0,0};
ar[5]={-1,1};
ar[6]={-1,0};
ar[7]={1,-1};
ar[8]={0,-1};
cin>>n;
for(int i=1;i<=n;i++){
int typ;
int vl;
cin>>typ>>vl;
e[typ].push_back(vl);
}
for(int i=1;i<=8;i++){
sort(e[i].begin(),e[i].end());
reverse(e[i].begin(),e[i].end());
}
if(e[5].size()+e[6].size()!=1){
cout<<-1;return 0;
}
if(e[7].size()+e[8].size()!=1){
cout<<-1;return 0;
}vector<int>ans;
int lst;
if(e[5].size()){
lst=1;
ans.push_back(e[5][0]);
}else{
lst=0;
ans.push_back(e[6][0]);
}
for(int i=2;i<=n-1;i++){
/*cout<<i<<" ";
for(int j:ans){
cout<<j<<" ";
}cout<<endl;*/
if(lst==1){
if(e[3].size()+e[4].size()==0){cout<<-1;return 0;}
if(!e[4].size()){lst=1;ans.push_back(e[3].back());e[3].pop_back();continue;}
if(!e[3].size()){lst=0;ans.push_back(e[4].back());e[4].pop_back();continue;}
if(e[4].back()>e[3].back()){
lst=1;ans.push_back(e[3].back());e[3].pop_back();continue;
}else{
lst=0;ans.push_back(e[4].back());e[4].pop_back();continue;
}
}
if(e[1].size()+e[2].size()==0){cout<<-1;return 0;}
if(!e[2].size()){lst=1;ans.push_back(e[1].back());e[1].pop_back();continue;}
if(!e[1].size()){lst=0;ans.push_back(e[2].back());e[2].pop_back();continue;}
if(e[2].back()>e[1].back()){
lst=1;ans.push_back(e[1].back());e[1].pop_back();continue;
}else{
lst=0;ans.push_back(e[2].back());e[2].pop_back();continue;
}
}
int ed;
if(e[7].size()){
ed=1;
ans.push_back(e[7][0]);
}else{
ed=0;
ans.push_back(e[8][0]);
}
if(ed+lst!=1){
cout<<-1;return 0;
}
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<" ";
}
}
Compilation message
slagalica.cpp: In function 'int main()':
slagalica.cpp:88:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int i=0;i<ans.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
3648 KB |
Output is correct |
2 |
Correct |
55 ms |
3212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
3468 KB |
Output is correct |
2 |
Correct |
41 ms |
3224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
3016 KB |
Output is correct |
2 |
Incorrect |
42 ms |
3136 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
2836 KB |
Output is correct |
2 |
Correct |
44 ms |
3536 KB |
Output is correct |
3 |
Incorrect |
45 ms |
3312 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
2756 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
3488 KB |
Output is correct |
2 |
Correct |
42 ms |
2956 KB |
Output is correct |
3 |
Incorrect |
43 ms |
3400 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
3144 KB |
Output is correct |
2 |
Incorrect |
40 ms |
3236 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
3436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
3276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
46 ms |
3360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
3140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
38 ms |
3088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |