CF 797, got stuck on E and had to leave, went pretty well

This commit is contained in:
2022-06-07 21:38:41 +02:00
parent a2acadbf3e
commit 6de228cf8a
7 changed files with 346 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
#include <bits/stdc++.h>
using namespace std;
void test_case(int tc){
int n;
cin >> n;
int result = n / 3 + 2;
if(n % 3 == 0) {
result = n / 3 + 1;
}
int r2 = result - 1;
if(n == 7){
r2 = 2;
}
int lowest = n - result - r2;
cout << r2 << " " << result << " " << lowest << '\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;
}

View File

@@ -0,0 +1,66 @@
#include <bits/stdc++.h>
using namespace std;
void test_case(int tc){
int n;
cin >> n;
vector<int> a(n);
vector<int> b(n);
for (size_t i = 0; i < n; i++){
cin >> a[i];
}
for (size_t i = 0; i < n; i++){
cin >> b[i];
}
bool result = true;
int exactdif = INT32_MAX;
int hightestdif = 0;
bool onlyzeroes = true;
for(size_t i = 0; i < n; ++i){
auto ax = a[i], bx = b[i];
auto d = ax - bx;
if(bx == 0){
hightestdif = max(hightestdif, d);
} else {
onlyzeroes = false;
if(exactdif == INT32_MAX){
exactdif = d;
} else if(exactdif != d){
result = false;
break;
}
}
}
if(hightestdif > exactdif){
result = false;
}
cout << (result || onlyzeroes ? "YES" : "NO") << '\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;
}

View File

@@ -0,0 +1,48 @@
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
void test_case(int tc){
int n;
cin >> n;
vector<int> s(n);
vector<int> f(n);
for(size_t i = 0; i < n; ++i){
cin >> s[i];
}
for(size_t i = 0; i < n; ++i){
cin >> f[i];
if(i != 0){
cout << f[i] - max(s[i], f[i-1]) << " ";
} else {
cout << f[i] - s[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;
}

View File

@@ -0,0 +1,68 @@
#include <bits/stdc++.h>
using namespace std;
void test_case(int tc){
int n, k;
cin >> n >> k;
vector<bool> strip;
int blacks = 0;
int whites = 0;
for(int i = 0; i < k; ++i){
char c;
cin >> c;
if(c == 'B'){
blacks++;
strip.push_back(true);
} else{
whites++;
strip.push_back(false);
}
}
int min_whites = whites;
for(int i = 0; i < n - k; ++i){
char c;
cin >> c;
if(strip[i]){
blacks--;
} else {
whites--;
}
if(c == 'B'){
blacks++;
strip.push_back(true);
} else {
whites++;
strip.push_back(false);
}
min_whites = min(min_whites, whites);
}
cout << min_whites << '\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;
}

View File

@@ -0,0 +1,76 @@
#include <bits/stdc++.h>
using namespace std;
void test_case(int tc){
int n, k;
cin >> n >> k;
vector<vector<int>> modulos(k);
for(int i = 0; i < n; ++i){
int s;
cin >> s;
modulos[s % k].push_back(s);
}
for(auto v : modulos){
sort(v.begin(), v.end());
}
unsigned long long result = 0;
for(int i = k - 1; i > 0; i--){
while(!modulos[i].empty() && !modulos[k-i].empty()){
int a = modulos[i].back(), b = modulos[k - 1].back();
modulos[i].pop_back();
modulos[k-1].pop_back();
result += (a + b) / k;
}
}
while(modulos[0].size() > 1){
int a = modulos[0].back();
modulos[0].pop_back();
int b = modulos[0].back();
modulos[0].pop_back();
result += (a + b) / k;
}
for(int i = 0; i < k; ++i){
for(int j = i + 1; j < k; ++j){
while(!modulos[i].empty() && !modulos[j].empty()){
int a = modulos[i].back(), b = modulos[j].back();
modulos[i].pop_back();
modulos[j].pop_back();
result += (a + b) / k;
}
}
}
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;
}

View 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;
}

View 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;
}