CF 797, got stuck on E and had to leave, went pretty well
This commit is contained in:
38
codeforces/rounds/797/a.cpp
Normal file
38
codeforces/rounds/797/a.cpp
Normal 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;
|
||||||
|
}
|
||||||
66
codeforces/rounds/797/b.cpp
Normal file
66
codeforces/rounds/797/b.cpp
Normal 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;
|
||||||
|
}
|
||||||
48
codeforces/rounds/797/c.cpp
Normal file
48
codeforces/rounds/797/c.cpp
Normal 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;
|
||||||
|
}
|
||||||
68
codeforces/rounds/797/d.cpp
Normal file
68
codeforces/rounds/797/d.cpp
Normal 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;
|
||||||
|
}
|
||||||
76
codeforces/rounds/797/e.cpp
Normal file
76
codeforces/rounds/797/e.cpp
Normal 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;
|
||||||
|
}
|
||||||
25
codeforces/rounds/797/f.cpp
Normal file
25
codeforces/rounds/797/f.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/797/g.cpp
Normal file
25
codeforces/rounds/797/g.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