# Codeforces Round #784 (Div. 4)第一次打额，来个笔记 ## A： Division?

Codeforces separates its users into 4 divisions by their rating:

• For Division 1: 1900≤rating
• For Division 2: 1600≤rating≤1899
• For Division 3: 1400≤rating≤1599
• For Division 4: rating≤1399

Given a rating, print in which division the rating belongs.

    #include<bits/stdc++.h>

using namespace std;

char c = getchar();
long long x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}

void solve() {
cout<<"Division 1"<<endl;
cout<<"Division 2"<<endl;
cout<<"Division 3"<<endl;
}else{
cout<<"Division 4"<<endl;
}
}

int main() {
int T = 1;
cin >> T;
while (T--) {
solve();
}
}

## B：Triple

Given an array a of n elements, print any value that appears at least three times or print -1 if there is no such value.

#include<bits/stdc++.h>

using namespace std;

char c = getchar();
long long x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}

void solve() {
map<int,int> mp;
for(int i = 0;i<n;i++){
}
int ans=-1;
for(auto &i: mp){
if(i.second>=3){
ans=i.first;
}
}
cout<<ans<<endl;
}

int main() {
int T = 1;
cin >> T;
while (T--) {
solve();
}
}

## C：Odd/Even Increments

Given an array a=[a1,a2,…,an] of n positive integers, you can do operations of two types on it:

Add 1 to every element with an odd index. In other words change the array as follows: a1:=a1+1,a3:=a3+1,a5:=a5+1,…

Add 1 to every element with an even index. In other words change the array as follows: a2:=a2+1,a4:=a4+1,a6:=a*6+1,….

Determine if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers. In other words, determine if you can make all elements of the array have the same parity after any number of operations.

Note that you can do operations of both types any number of times (even none). Operations of different types can be performed a different number of times.

#include<bits/stdc++.h>

using namespace std;

char c = getchar();
long long x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}

void solve() {
vector<int> mp(n);
for(int i = 0;i<n ;i++){
}
bool a=true;
if(mp%2==1){
for(int i =2;i<n;i+=2){
if(mp[i]%2!=1){
a=false;
break;
}
}
}else{
for(int i =2;i<n;i+=2){
if(mp[i]%2!=0){
a=false;
break;
}
}
}
bool b=true;
if(mp%2==1){
for(int i =3;i<n;i+=2){
if(mp[i]%2!=1){
b=false;
break;
}
}
}else{
for(int i =3;i<n;i+=2){
if(mp[i]%2!=0){
b=false;
break;
}
}
}
if( a&&b){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}

int main() {
int T = 1;
cin >> T;
while (T--) {
solve();
}
}

## D: Colorful Stamp

A row of n cells is given, all initially white. Using a stamp, you can stamp any two neighboring cells such that one becomes red and the other becomes blue. A stamp can be rotated, i.e. it can be used in both ways: as BR and as RB

During use, the stamp must completely fit on the given n cells (it cannot be partially outside the cells). The stamp can be applied multiple times to the same cell. Each usage of the stamp recolors both cells that are under the stamp.

For example, one possible sequence of stamps to make the picture BRBBW could be WWWWW→WWRB–––W→BR–––RBW→BRB–––BW. Here W, R, and B represent a white, red, or blue cell, respectively, and the cells that the stamp is used on are marked with an underline.

Given a final picture, is it possible to make it using the stamp zero or more times?

#include<bits/stdc++.h>

#define endl '\n'
#define ll long long
using namespace std;

char c = getchar();
long long x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}

void solve() {
string s;
cin >> s;
s = "W" + s + "W";
string now;
vector<string> mp;
for (int i = 0; i < s.size(); ++i) {
if(s[i]=='W'&&now.size()!=0){
mp.push_back(now);
now="";
}else if (s[i]!='W'){
now+=s[i];
}
}
for(auto &str : mp){
if(str.find('R')==str.npos){
cout<<"NO"<<endl;
return;
}
if(str.find('B')==str.npos){
cout<<"NO"<<endl;
return;
}
}
cout<<"YES"<<endl;

}

int main() {
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}

## E： 2-Letter Strings

Given n strings, each of length 2, consisting of lowercase Latin alphabet letters from 'a' to 'k', output the number of pairs of indices (i,j) such that i<j and the i-th string and the j-th string differ in exactly one position.

In other words, count the number of pairs (i,j) (i<j) such that the i-th string and the j-th string have exactly one position p (1≤p≤2) such that sipsjp.

The answer may not fit into 32-bit integer type, so you should use 64-bit integers like long long in C++ to avoid integer overflow.

#include<bits/stdc++.h>

#define endl '\n'
#define ll long long
using namespace std;

char c = getchar();
long long x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int a;
void solve() {
long long  n,ans=0;
cin>>n;
memset(a,0,sizeof a);
for(int i=0;i<n;i++)
{
string s;
cin>>s;
for(int j=0;j<2;j++)
for(char c='a';c<='k';c++)
{
if(c==s[j])continue;
string t=s;t[j]=c;
ans+=a[t-'a'][t-'a'];
}
++a[s-'a'][s-'a'];
}
cout<<ans<<'\n';
}

int main() {
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}

## F：Eating Candies

There are n candies put from left to right on a table. The candies are numbered from left to right. The i-th candy has weight wi. Alice and Bob eat candies.

Alice can eat any number of candies from the left (she can't skip candies, she eats them in a row).

Bob can eat any number of candies from the right (he can't skip candies, he eats them in a row).

Of course, if Alice ate a candy, Bob can't eat it (and vice versa).

They want to be fair. Their goal is to eat the same total weight of candies. What is the most number of candies they can eat in total?**

#include<bits/stdc++.h>

#define endl '\n'
#define ll long long
using namespace std;

char c = getchar();
long long x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}

void solve() {
vector<int> mp(n);
for (int i = 0; i < n; ++i) {
}
vector<int> ls(n);
ls = mp;
vector<int> rs(n);
rs[n - 1] = mp[n - 1];
map<int, vector<int>> m;
m[mp].push_back(1);
m[mp[n - 1]].push_back(1);
for (int i = 1; i < n; i++) {
ls[i] = ls[i - 1] + mp[i];
m[ls[i]].push_back(i+1);
}
for (int i = n - 2; i >= 0; i--) {
rs[i] = rs[i + 1] + mp[i];
m[rs[i]].push_back(n-i);
}
int ans=0;
for(auto & l : m){
if(l.second.size()>=2){
if(l.second+l.second>ans&&l.second+l.second<=n){
ans=l.second+l.second;
}
}
}
cout << ans << endl;
}

int main() {
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}

## G： Fall Down

There is a grid with n rows and m

columns, and three types of cells:

An empty cell, denoted with '.'.
A stone, denoted with '*'.
An obstacle, denoted with the lowercase Latin letter 'o'.


All stones fall down until they meet the floor (the bottom row), an obstacle, or other stone which is already immovable. (In other words, all the stones just fall down as long as they can fall.)

Simulate the process. What does the resulting grid look like?

#include<bits/stdc++.h>

#define endl '\n'
#define ll long long
using namespace std;

char c = getchar();
long long x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}

void solve() {
vector<string> mp(n);
for (int i = 0; i < n; i++) {
cin >> mp[i];
}
for (int i = 0; i < m; i++) {
int pos = n - 1;
for (int j = n - 1; j >= 0; j--) {
if (mp[j][i] == '*') {
mp[j][i] = '.';
mp[pos][i]='*';
pos--;
} else if (mp[j][i] == 'o') {
pos = j - 1;
}
}

}
for (int i = 0; i < n; i++) {
cout << mp[i] << endl;
}
}

int main() {
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}