| Task: | Järjestys |
| Sender: | Lieska |
| Submission time: | 2025-09-06 02:58:28 +0300 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| #4 | WRONG ANSWER | 0 |
| #5 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 1, 4, 5 | details |
| #2 | ACCEPTED | 0.00 s | 1, 4, 5 | details |
| #3 | WRONG ANSWER | 0.00 s | 1, 4, 5 | details |
| #4 | WRONG ANSWER | 0.00 s | 1, 4, 5 | details |
| #5 | WRONG ANSWER | 0.00 s | 1, 4, 5 | details |
| #6 | ACCEPTED | 0.00 s | 1, 2, 4, 5 | details |
| #7 | WRONG ANSWER | 0.00 s | 1, 3, 4, 5 | details |
| #8 | ACCEPTED | 0.00 s | 1, 4, 5 | details |
| #9 | WRONG ANSWER | 0.02 s | 2, 4, 5 | details |
| #10 | WRONG ANSWER | 0.03 s | 3, 4, 5 | details |
| #11 | ACCEPTED | 0.03 s | 4, 5 | details |
| #12 | WRONG ANSWER | 0.04 s | 4, 5 | details |
| #13 | WRONG ANSWER | 0.04 s | 4, 5 | details |
| #14 | WRONG ANSWER | 0.03 s | 4, 5 | details |
| #15 | WRONG ANSWER | 0.21 s | 2, 5 | details |
| #16 | WRONG ANSWER | 0.36 s | 3, 5 | details |
| #17 | ACCEPTED | 0.41 s | 5 | details |
| #18 | WRONG ANSWER | 0.41 s | 5 | details |
| #19 | WRONG ANSWER | 0.42 s | 5 | details |
| #20 | WRONG ANSWER | 0.34 s | 5 | details |
| #21 | WRONG ANSWER | 0.36 s | 5 | details |
| #22 | WRONG ANSWER | 0.38 s | 5 | details |
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int, int> group_node_indices[1004]; //Tells the indices of first and last pairs in a chain (or group).
int order[501];
bool test(multiset<pair<int, int>> &s){
int diff=0;
if (s.size()==0) return true;
for (auto u:s){
if (u.first%2==1) diff-=1;
else diff+=1;
//cout << u.first << " " << diff << "\n";
if (diff < -1) return false;
}
return true;
}
int g(int first, int second, bool which, int group){
// If first==second, we want to encounter the starting value first.
// If multiple groups have same value first==second, we want to vary between starts and ends.
if (first== second){
if (!which){
return 2004*second+2*group+1;
}
else return 2004*second+2*group+2;
}
else{
if (which){
return 2004*second;
}
else return 2004*(first+1)-1;
}
}
void f(multiset<pair<int, int>> &s, int group1, int group2, set<int> &indices,
int &running_group_index, bool &okay, vector<pair<int, int>> v){
int index_group2_first = group_node_indices[group2].first, index_group2_last = group_node_indices[group2].second;
int index_group1_first = group_node_indices[group1].first, index_group1_last = group_node_indices[group1].second;
int int_group2_first = v[index_group2_first].first, int_group2_last = v[index_group2_last].second;
int int_group1_first = v[index_group1_first].first, int_group1_last = v[index_group1_last].second;
//We only need to erase middle elements at this point.
pair<int, int> erased1, erased2, erased3, erased4, added1, added2;
erased1 = {g(int_group1_first, int_group1_last, true, group1), group1};
erased2 = {g(int_group2_first, int_group2_last, false, group2), group2};
erased3 = {g(int_group2_first, int_group2_last, true, group2), group2};
erased4 = {g(int_group1_first, int_group1_last, false, group1), group1};
added1 = {g(int_group1_first, int_group2_last, true, running_group_index), running_group_index};
added2 = {g(int_group1_first, int_group2_last, false, running_group_index), running_group_index};
s.erase(erased1);
s.erase(erased2);
s.erase(erased3);
s.erase(erased4);
s.insert(added1);
s.insert(added2);
if (test(s) == true){
//cout << "here 3 " << group1 << " " << group2 << " " << int_group2_last << " " << int_group1_first << "\n";
//for (auto u: s) cout << u.first << " " << u.second << " ";
//cout << "\n";
indices.erase(group1);
indices.erase(group2);
// Create new group.
group_node_indices[running_group_index] = {index_group1_first, index_group2_last};
indices.insert(running_group_index);
running_group_index++;
// Record order of middle nodes.
order[index_group1_last] = index_group2_first;
//cout << "here again " << index_group1_last << " " << index_group2_first << "\n";
okay = true;
}
else{
s.insert(erased1);
s.insert(erased2);
s.insert(erased3);
s.insert(erased4);
s.erase(added1);
s.erase(added2);
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for (int i=1; i<=t; ++i){
int n;
cin >> n;
vector<pair<int, int>> v;
multiset<pair<int, int>> s;
set<int> indices;
for (int j=0; j<n; ++j){
int a, b;
cin >> a >> b;
v.push_back({a,b});
//We want end points to be before starting points.
s.insert({g(a, b, false, j), j});
s.insert({g(a, b, true, j), j});
indices.insert(j);
}
//cout << "here\n";
for (int j=0; j<=n; ++j) order[j] = -1;
for (int j=0; j<n; ++j) group_node_indices[j] = {j, j};
for (int j=n; j<=2*n+2; ++j) group_node_indices[j] = {-1,-1};
int running_group_index = n;
while (true){
//cout << "hello " << indices.size() << "\n";
if (indices.size()==1) break;
bool okay = false;
bool next_is_first = true;
int a=0;
for (auto u:indices){
if (next_is_first){
a = u;
next_is_first = false;
continue;
}
// a and u are group indeces.
int index_a_first = group_node_indices[a].first, index_a_last = group_node_indices[a].second;
int index_u_first = group_node_indices[u].first, index_u_last = group_node_indices[u].second;
int int_a_first = v[index_a_first].first, int_a_last = v[index_a_last].second;
int int_u_first = v[index_u_first].first, int_u_last = v[index_u_last].second;
if (int_u_first >= int_a_last){
f(s, a, u, indices, running_group_index, okay, v);
if (okay) break;
}
if (int_a_first >= int_u_last && okay==false){
f(s, u, a, indices, running_group_index, okay, v);
if (okay) break;
}
}
//for (auto u:s) cout << u.first << " " << u.second << "\n";
//cout << "here2 " << okay << "\n";
//for (auto u:indices) cout << u << " ";
//cout << "\n";
if (okay == false) break;
if (indices.size()==1) break;
}
if (indices.size() > 1){
cout << "NO\n";
}
else {
cout << "YES\n";
//for (int i=0; i<=12; ++i) cout << order[i] << " ";
//cout << "\n";
int find_first[n] = {};
for (int j=0; j<n; ++j){
if (order[j]!=-1){
find_first[order[j]] = -1;
}
}
int place = -1;
for (int j=0; j<n; ++j)
if (find_first[j]==0){
cout << v[j].first << " " << v[j].second << "\n";
place = j;
break;
}
while (order[place]!=-1){
place = order[place];
cout << v[place].first << " " << v[place].second << "\n";
}
}
}
}Test details
Test 1
Group: 1, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 1 74 75 1 100 43 ... |
| correct output |
|---|
| YES 74 75 YES 100 43 YES ... |
| user output |
|---|
| YES 74 75 YES 100 43 YES ... Truncated |
Test 2
Group: 1, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 2 80 54 51 61 2 ... |
| correct output |
|---|
| YES 51 61 80 54 YES 2 64 ... |
| user output |
|---|
| YES 51 61 80 54 YES 2 64 ... Truncated |
Test 3
Group: 1, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 3 3 74 91 45 100 24 ... |
| correct output |
|---|
| YES 3 74 100 24 91 45 YES ... |
| user output |
|---|
| YES 3 74 91 45 100 24 YES ... Truncated |
Test 4
Group: 1, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 4 88 50 62 41 12 86 ... |
| correct output |
|---|
| YES 12 86 88 50 62 41 66 93 ... |
| user output |
|---|
| YES 12 86 88 50 62 41 66 93 ... Truncated |
Test 5
Group: 1, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 5 82 80 80 92 5 22 ... |
| correct output |
|---|
| YES 5 22 94 13 82 80 80 92 ... |
| user output |
|---|
| YES 5 22 94 13 82 80 80 92 ... Truncated |
Test 6
Group: 1, 2, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 5 34 38 26 30 1 6 ... |
| correct output |
|---|
| YES 1 6 12 22 26 30 34 38 ... |
| user output |
|---|
| YES 1 6 12 22 26 30 34 38 ... Truncated |
Test 7
Group: 1, 3, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 5 50 40 28 25 51 7 ... |
| correct output |
|---|
| YES 51 7 50 40 47 1 17 11 ... |
| user output |
|---|
| YES 51 7 17 11 47 1 28 25 ... Truncated |
Test 8
Group: 1, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 5 2 2 2 1 1 1 ... |
| correct output |
|---|
| YES 1 2 2 1 2 1 1 1 ... |
| user output |
|---|
| YES 1 1 1 2 2 1 2 2 ... Truncated |
Test 9
Group: 2, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 175870020 296379324 248160539 883842002 21934885 781732852 ... |
| correct output |
|---|
| NO YES 4976156 6890135 10553287 11923223 14617057 17728163 ... |
| user output |
|---|
| NO NO NO NO NO ... Truncated |
Test 10
Group: 3, 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 447597377 314433951 700232436 691277009 937268439 708165426 ... |
| correct output |
|---|
| YES 998963839 391778929 995772196 257222033 995754704 553123757 994629465 247775824 ... |
| user output |
|---|
| NO NO NO NO NO ... Truncated |
Test 11
Group: 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 100 1 1 1 2 2 1 ... |
| correct output |
|---|
| YES 1 2 2 1 1 2 2 2 ... |
| user output |
|---|
| YES 1 2 2 2 2 1 2 1 ... Truncated |
Test 12
Group: 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 7 1 6 3 10 9 ... |
| correct output |
|---|
| YES 6 7 7 8 9 10 10 10 ... |
| user output |
|---|
| YES 2 1 8 4 6 7 9 7 ... Truncated |
Test 13
Group: 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 51 5 85 77 91 84 ... |
| correct output |
|---|
| YES 100 24 100 25 100 3 100 6 ... |
| user output |
|---|
| NO NO NO YES 28 48 ... Truncated |
Test 14
Group: 4, 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 823828194 863717310 593641073 340054211 420481158 965069109 ... |
| correct output |
|---|
| YES 999289319 634855378 996775156 433726648 983657502 55234695 981890636 112877413 ... |
| user output |
|---|
| NO NO NO NO NO ... Truncated |
Test 15
Group: 2, 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 500 88724450 89315226 266915464 267648621 189301651 189661541 ... |
| correct output |
|---|
| YES 764920 1459946 1936195 2832987 3691481 4085931 4991808 5840928 ... |
| user output |
|---|
| NO NO NO NO NO ... Truncated |
Test 16
Group: 3, 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 500 763682761 317584504 756010800 260162861 435911339 78070399 ... |
| correct output |
|---|
| YES 998768285 3307355 998714926 628486754 997115613 820932481 993320616 554600893 ... |
| user output |
|---|
| NO NO NO NO NO ... Truncated |
Test 17
Group: 5
Verdict: ACCEPTED
| input |
|---|
| 100 500 2 2 2 1 1 2 ... |
| correct output |
|---|
| YES 1 2 2 2 2 1 1 2 ... |
| user output |
|---|
| YES 1 1 2 2 2 1 2 1 ... Truncated |
Test 18
Group: 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 500 10 6 10 10 9 10 ... |
| correct output |
|---|
| YES 2 3 3 4 4 5 5 6 ... |
| user output |
|---|
| YES 1 5 10 6 8 8 10 7 ... Truncated |
Test 19
Group: 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 500 85 87 89 70 70 92 ... |
| correct output |
|---|
| YES 96 97 100 67 100 10 100 97 ... |
| user output |
|---|
| NO NO NO NO NO ... Truncated |
Test 20
Group: 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 500 861154169 119512584 569086662 606567153 288230434 322196278 ... |
| correct output |
|---|
| YES 999945324 969534372 999738857 240617694 999244114 722161553 999207839 557351400 ... |
| user output |
|---|
| NO NO NO NO NO ... Truncated |
Test 21
Group: 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 500 116439250 401518028 280329609 193466222 674040956 209050570 ... |
| correct output |
|---|
| NO YES 773701149 773852119 987509190 315670966 977413249 510418200 ... |
| user output |
|---|
| NO NO NO NO NO ... Truncated |
Test 22
Group: 5
Verdict: WRONG ANSWER
| input |
|---|
| 100 500 934181189 942499518 684836806 395802802 957884803 570946201 ... |
| correct output |
|---|
| YES 999772640 505132174 999111650 140844643 999028633 888134186 999020109 291046771 ... |
| user output |
|---|
| NO NO NO NO NO ... Truncated |
