From 1b058a01f3264a892d860232ada411e7872b6f56 Mon Sep 17 00:00:00 2001 From: Philippe Zwietering Date: Mon, 13 Jun 2022 17:10:36 +0200 Subject: [PATCH] CF 798, didnt get far --- codeforces/rounds/798/a.cpp | 85 +++++++++++++++++++++++++++++++++++++ codeforces/rounds/798/b.cpp | 82 +++++++++++++++++++++++++++++++++++ codeforces/rounds/798/c.cpp | 25 +++++++++++ codeforces/rounds/798/d.cpp | 25 +++++++++++ codeforces/rounds/798/e.cpp | 25 +++++++++++ 5 files changed, 242 insertions(+) create mode 100644 codeforces/rounds/798/a.cpp create mode 100644 codeforces/rounds/798/b.cpp create mode 100644 codeforces/rounds/798/c.cpp create mode 100644 codeforces/rounds/798/d.cpp create mode 100644 codeforces/rounds/798/e.cpp diff --git a/codeforces/rounds/798/a.cpp b/codeforces/rounds/798/a.cpp new file mode 100644 index 0000000..1f8ca79 --- /dev/null +++ b/codeforces/rounds/798/a.cpp @@ -0,0 +1,85 @@ +#include + +using namespace std; + +void test_case(int tc){ + int n, m, k; + + cin >> n >> m >> k; + + vector 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; +} \ No newline at end of file diff --git a/codeforces/rounds/798/b.cpp b/codeforces/rounds/798/b.cpp new file mode 100644 index 0000000..0de794d --- /dev/null +++ b/codeforces/rounds/798/b.cpp @@ -0,0 +1,82 @@ +#include + +using namespace std; + +void test_case(int tc){ + int n; + cin >> n; + + if(n == 1){ + cout << "-1\n"; + return; + } + + vector p(n); + array 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 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; +} \ No newline at end of file diff --git a/codeforces/rounds/798/c.cpp b/codeforces/rounds/798/c.cpp new file mode 100644 index 0000000..0c03bec --- /dev/null +++ b/codeforces/rounds/798/c.cpp @@ -0,0 +1,25 @@ +#include + +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; +} \ No newline at end of file diff --git a/codeforces/rounds/798/d.cpp b/codeforces/rounds/798/d.cpp new file mode 100644 index 0000000..0c03bec --- /dev/null +++ b/codeforces/rounds/798/d.cpp @@ -0,0 +1,25 @@ +#include + +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; +} \ No newline at end of file diff --git a/codeforces/rounds/798/e.cpp b/codeforces/rounds/798/e.cpp new file mode 100644 index 0000000..0c03bec --- /dev/null +++ b/codeforces/rounds/798/e.cpp @@ -0,0 +1,25 @@ +#include + +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; +} \ No newline at end of file