This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#define endl '\n'
#define fi first
#define se second
constexpr int maxn = 2e5 + 5;
constexpr int inf = 2e9;
constexpr int mod = 1e9 + 7;
using namespace std;
using lint = long long;
using pii = pair<int, int>;
int n;
int typ[maxn], a[maxn];
vector<int> v[10];
vector<int> ans;
int typl, typr, al, ar;
signed main() {
#ifdef Local
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> typ[i] >> a[i];
typl = typ[i] == 5 || typ[i] == 6 ? typ[i] : typl;
al = typ[i] == 5 || typ[i] == 6 ? a[i] : al;
typr = typ[i] == 7 || typ[i] == 8 ? typ[i] : typr;
ar = typ[i] == 7 || typ[i] == 8 ? a[i] : ar;
v[typ[i]].push_back(a[i]);
}
for(int i = 1; i <= 8; i++)
sort(v[i].begin(), v[i].end(), greater<int>());
bool bad = false;
bad |= typl == 5 && typr == 7 && v[4].empty();
bad |= typl == 6 && typr == 8 && v[1].empty();
bad |= typl == 5 && typr == 8 && v[4].size() != v[1].size();
bad |= typl == 6 && typr == 7 && v[4].size() != v[1].size();
if(bad) {
cout << -1 << endl;
return 0;
}
int toput = typl - 5;
ans.push_back(al);
while(ans.size() < n - 1) {
if(toput == 1) {
if(v[2].empty() || (v[1].size() != 1 && v[2].back() < v[1].back())) {
ans.push_back(v[1].back());
v[1].pop_back();
toput = 0;
}
else {
ans.push_back(v[2].back());
v[2].pop_back();
toput = 1;
}
}
else {
if(v[3].empty() || (v[4].size() != 1 && v[4].back() < v[3].back())) {
ans.push_back(v[4].back());
v[4].pop_back();
toput = 1;
}
else {
ans.push_back(v[3].back());
v[3].pop_back();
toput = 0;
}
}
}
ans.push_back(ar);
for(int x : ans)
cout << x << " ";
cout << endl;
}
Compilation message (stderr)
slagalica.cpp: In function 'int main()':
slagalica.cpp:47:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
47 | while(ans.size() < n - 1) {
| ~~~~~~~~~~~^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |