CF 798, didnt get far
This commit is contained in:
85
codeforces/rounds/798/a.cpp
Normal file
85
codeforces/rounds/798/a.cpp
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void test_case(int tc){
|
||||||
|
int n, m, k;
|
||||||
|
|
||||||
|
cin >> n >> m >> k;
|
||||||
|
|
||||||
|
vector<char> x, y;
|
||||||
|
for (size_t i = 0; i < n; i++){
|
||||||
|
char c;
|
||||||
|
cin >> c;
|
||||||
|
x.push_back(c);
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < m; i++){
|
||||||
|
char c;
|
||||||
|
cin >> c;
|
||||||
|
y.push_back(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
int k_counter = 0;
|
||||||
|
string result = "";
|
||||||
|
// We need to keep track of the last one for optimal placement I think
|
||||||
|
bool lastChoice = x.front() < y.front();
|
||||||
|
|
||||||
|
sort(x.begin(), x.end());
|
||||||
|
reverse(x.begin(), x.end());
|
||||||
|
|
||||||
|
sort(y.begin(), y.end());
|
||||||
|
reverse(y.begin(), y.end());
|
||||||
|
|
||||||
|
while(!x.empty() && !y.empty()){
|
||||||
|
char cx = x.back(), cy = y.back();
|
||||||
|
|
||||||
|
if(lastChoice != (cx < cy)){
|
||||||
|
k_counter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lastChoice == (cx < cy) && k_counter == k){
|
||||||
|
k_counter = 0;
|
||||||
|
lastChoice = cx >= cy;
|
||||||
|
|
||||||
|
if(cx < cy){
|
||||||
|
y.pop_back();
|
||||||
|
result.push_back(cy);
|
||||||
|
} else {
|
||||||
|
x.pop_back();
|
||||||
|
result.push_back(cx);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lastChoice = cx < cy;
|
||||||
|
|
||||||
|
if(cx < cy){
|
||||||
|
x.pop_back();
|
||||||
|
result.push_back(cx);
|
||||||
|
} else{
|
||||||
|
y.pop_back();
|
||||||
|
result.push_back(cy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
k_counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << result << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
ios::sync_with_stdio(0);
|
||||||
|
cin.tie(0);
|
||||||
|
|
||||||
|
int t;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
for(int tc = 1; tc <= t; ++tc){
|
||||||
|
test_case(tc);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << flush;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
82
codeforces/rounds/798/b.cpp
Normal file
82
codeforces/rounds/798/b.cpp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void test_case(int tc){
|
||||||
|
int n;
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
if(n == 1){
|
||||||
|
cout << "-1\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<int> p(n);
|
||||||
|
array<bool, 10> numbers;
|
||||||
|
|
||||||
|
for(int i = 1; i < 10; ++i){
|
||||||
|
numbers[i] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < n; ++i){
|
||||||
|
cin >> p[i];
|
||||||
|
numbers[p[i]] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<int> result;
|
||||||
|
|
||||||
|
for(int i = 0; i < n - 2; ++i){
|
||||||
|
for(int j = 1; j < 10; ++j){
|
||||||
|
if(j != p[i] && numbers[j]){
|
||||||
|
numbers[j] = false;
|
||||||
|
result.push_back(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int a, b;
|
||||||
|
for(int j = 1; j < 10; ++j){
|
||||||
|
if(numbers[j]){
|
||||||
|
a = j;
|
||||||
|
numbers[j] = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int j = 1; j < 10; ++j){
|
||||||
|
if(numbers[j]){
|
||||||
|
b = j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(a == p[n - 2]){
|
||||||
|
swap(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.push_back(b);
|
||||||
|
result.push_back(a);
|
||||||
|
|
||||||
|
for(int i : result){
|
||||||
|
cout << i << " ";
|
||||||
|
} cout << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
ios::sync_with_stdio(0);
|
||||||
|
cin.tie(0);
|
||||||
|
|
||||||
|
int t;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
for(int tc = 1; tc <= t; ++tc){
|
||||||
|
test_case(tc);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << flush;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
25
codeforces/rounds/798/c.cpp
Normal file
25
codeforces/rounds/798/c.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void test_case(int tc){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
ios::sync_with_stdio(0);
|
||||||
|
cin.tie(0);
|
||||||
|
|
||||||
|
int t;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
for(int tc = 1; tc <= t; ++tc){
|
||||||
|
test_case(tc);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << flush;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
25
codeforces/rounds/798/d.cpp
Normal file
25
codeforces/rounds/798/d.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void test_case(int tc){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
ios::sync_with_stdio(0);
|
||||||
|
cin.tie(0);
|
||||||
|
|
||||||
|
int t;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
for(int tc = 1; tc <= t; ++tc){
|
||||||
|
test_case(tc);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << flush;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
25
codeforces/rounds/798/e.cpp
Normal file
25
codeforces/rounds/798/e.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void test_case(int tc){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
ios::sync_with_stdio(0);
|
||||||
|
cin.tie(0);
|
||||||
|
|
||||||
|
int t;
|
||||||
|
cin >> t;
|
||||||
|
|
||||||
|
for(int tc = 1; tc <= t; ++tc){
|
||||||
|
test_case(tc);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << flush;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user