# Codeforces round (Div. 3) - ABCD questions

The first cf problem solving report of konjaku

Title:
1X1 blocks, each column has a different number of blocks, you can use any number of blocks with a length of 2X1, can you change each column into the same number;
It can be found that after filling, each column must be the same height as the highest column. The maximum value can be found first. If each column needs to reach the maximum number of squares, the difference between each type and the maximum value is required to be a multiple of 2. If one column is not, the target cannot be reached

```#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
const int inf=0x3f3f3f3f;
int a[maxn];
int main()
{
int T,n,maxs;
cin>>T;
while(T--)
{
scanf("%d",&n);
maxs=-inf;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
maxs=max(maxs,a[i]);
}
int flag=1;
for(int i=1;i<=n;i++)
{
if((maxs-a[i])%2==1)
flag=0;
}
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
```

Is there a palindrome substring longer than 3 in a sequence.

If each element appears only once, it is impossible to form a palindrome string;

If a number appears three times or more, we can use these three numbers to form a text string, regardless of the position;

If an element appears twice, if the two times are not consecutive, then a palindrome string can be formed by the two elements and any element in the middle

```#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int maxn=1e6+5;
#define ll long long
{
int x=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s<='9'&&s>='0'){x=x*10+s-'0';s=getchar();}
return x*f;
}
int a[maxn];
map<int ,int >mp;
int main()
{
int T,n;
cin>>T;
while(T--)
{
int flag=0;
cin>>n;
for(int i=1;i<=n;i++)
for(int i=1;i<=n;i++)
{
mp[a[i]]++;
if(mp[a[i]]==2)
{
if(a[i-1]!=a[i])
flag=1;
}
if(mp[a[i]]>2)
flag=1;
}
if(flag)
printf("YES\n");
else
printf("NO\n");
mp.clear();
}
}
```

Meaning: each sequence composed of L and R represents one unit. L can walk to the left, R can walk to the right, and at most d units u can be walked each time. Ask 0 to go to the end of the string, and the minimum value of the maximum once crossing distance d;
When we see the minimization of the maximum distance, we first think of dichotomy
It can be considered that if you want to go to the end, the middle l must cross all the way, because when you get to L, you have to go to the left, and you have to cross a section of L to go to the end;
So we only need to find the longest continuous segment L

```#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int maxn=1e6+5;
const int inf=0x3f3f3f3f;
#define ll long long
{
int x=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s<='9'&&s>='0'){x=x*10+s-'0';s=getchar();}
return x*f;
}
char a[maxn];
int main()
{
int T;
cin>>T;
getchar();
while(T--)
{
scanf("%s",a);
int len=strlen(a);
//cout<<len<<endl;
int ans=1;
int t=1;
int maxs=-inf;
for(int i=0;i<len;i++)
{
if(a[i]=='L')
t++;
else
{
maxs=max(maxs,t);
t=1;
}
}
maxs=max(maxs,t);
printf("%d\n",maxs);
}
}
```

Calculating AI + AJ > Bi + BJ; that is, AI Bi + AJ BJ > 0
Calculate c[i]=a[i]-b[i], and then sort c[i]. If the above conditions are met, there should be c[i] + C [J] = a [i] - B [i] + a [J] - B [J] > 0. Use two pointers l and r to calculate the number of pairs.
I thought I was in order, but later I found out that I was not. I was killed on the spot

```#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int maxn=1e6+5;
const int inf=0x3f3f3f3f;
#define ll long long
{
int x=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s<='9'&&s>='0'){x=x*10+s-'0';s=getchar();}
return x*f;
}
ll a[maxn],b[maxn],c[maxn];
int main()
{
ll n;
cin>>n;
for(int i=1;i<=n;i++)
for(int i=1;i<=n;i++)
for(int i=1;i<=n;i++)
c[i]=a[i]-b[i];
sort(c+1,c+1+n);
int l=1,r=n;
ll ans=0;
while(l!=r)
{
if(c[l]+c[r]>0)
{
ans+=r-l;
r--;
}
else
l++;

}
cout<<ans<<endl;
return 0;
}
```
Published 5 original articles, won praise 9, visited 175

Posted on Fri, 13 Mar 2020 01:08:20 -0400 by Ron Woolley