2023 CCPC Henan Provincial Collegiate Programming Contest

A. Because there are at most 26 cases (a has a maximum of 26 cases) and then violently judge whether b is a palindrome string

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
const int N = 2e5 + 10;
int n,m;
void solve(){
    string s;
    cin>>s;
    vector<int> c(27,0);
    int l=0;
    n=s.size();
    if(n==1){
        cout<<"NaN\
";
        return;
    }
    for(int i=0;i<n;i ++ ){
        int x=s[i]-'a';
        if(c[x]==0)
        {
            int l=i + 1,r=n-1;
            bool f=true;
            while(l<r)
            {
                if(s[l]!=s[r])
                {
                    f=false;
                    break;
                }
                else {
                    l + + ,r--;
                }
            }
            if(f){
                cout<<"HE\
";
                return;
            }
        }
        else {
            break;
        }
        c[x] + + ;
    }
    cout<<"NaN\
";
}
int main()
{
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
    int t;
    cin>>t;
    while(t--)solve();
}

B. First of all, how to judge by fixing a k

Require ascending order=min(a[i:i + m-1])>max(a[1:i])

For multiple k, it is similar to the sieve method to directly judge each k

Complexity Harmonic Levels

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
const int N = 1e6 + 10;
int n,m;
int a[N];
int mn[N],mx[N];
void solve(){
    cin>>n;
    memset(mn,0x3f,sizeof(mn));
    for(int i=1;i<=n;i + + ){
        cin>>a[i];
        mx[i]=max(mx[i-1],a[i]);
    }
    for(int i=n;i>=1;i--)
    {
        //mx[i]=max(mx[i + 1],a[i]);
        mn[i]=min(mn[i + 1],a[i]);
    }
    int cnt=0;
    for(int i=1;i<=n;i + + ){
        bool flag=true;
        for(int j=1;j<=n;j + =i)
        {
            if(mx[j-1]<=mn[j]){
                continue;
            }
            else
            {
                flag=false;
                break;
            }
        }
        if(flag) cnt + + ;
    }
    cout<<cnt<<"\
";
    
}
signed main()
{
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
    int t=1;
    //cin>>t;
    while(t--)solve();
}

F. First select m numbers so that each number min(difference)*max(difference)

Greedy: The smallest difference must be adjacent, so sorting is fine.

Convert to selecting m consecutive numbers to calculate the contribution—sliding window

Then it is necessary to maintain the minimum value of the adjacent difference of each m number. I directly use the multiset to modify while inserting.

Complexity nlogn

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define int long long
const int N = 5e5 + 10;
int n,m;
int a[N];
void solve(){
    cin>>n>>m;
    for(int i=1;i<=n;i + + ) cin>>a[i];
    sort(a + 1,a + 1 + n);
    multiset<int> st;
    int res=0x3f3f3f3f;
    for(int i=2;i<=m;i ++ )
    {
        st.insert(a[i]-a[i-1]);
    }
    res=(a[m]-a[1])*(*st.begin());
    int r = m + 1;
    int l=2;
    while(r<=n)
    {
        st.erase(st.lower_bound(a[l]-a[l-1]));
        st.insert(a[r]-a[r-1]);
        res=min(res,(a[r]-a[r-m + 1])*(*st.begin()));
        l + + ;
        r + + ;
    }
    cout<<res<<"\
";
}
signed main()
{
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
    int t=1;
    //cin>>t;
    while(t--)solve();
}

E: regular dp

k needs to be enumerated in reverse order, similar to the volume of a one-dimensional backpack

Complexity nmk

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
const int N = 1e6 + 10;
int n,m,K;
char a[510][510];
void solve(){
    cin>>n>>m>>K;
    for(int i=1;i<=n;i + + ){
        for(int j=1;j<=m;j++)
            cin>>a[i][j];
    }
    vector<vector<int>> f(m+1,vector<int>(K+1,0));
    //memset(f,0,sizeof(f));
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            for(int k=K;k>=0;k--)
            {
                if(a[i][j]=='0'||a[i][j]=='1')
                {
                    f[j][k]=max(f[j-1][k] + (a[i][j]=='1'),f[j][k] + (a[i][j ]=='1'));
                }
                else
                {
                    f[j][k]=max({f[j][k],f[j][k],f[j-1][k]});
                    if(k)
                    f[j][k]=max({f[j][k],f[j][k-1] + 1,f[j-1][k-1] + 1});
                }
            }
        }
    }
    cout<<f[m][K]<<"\
";
}
signed main()
{
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
    int t=1;
    cin>>t;
    while(t--)solve();
}

G: Analog:

I don’t want to write and give up

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
const int N = 1e6 + 10;
typedef long long LL;
int n,m,K;
string sda[15][15];
string sxiao[15][15];
string deng[15],inf[N];
//The distance from the top is 2 greater than 7*7
//The distance from the top is 1 small 5*5
//The distance from the bottom left is 1
int qmi(int a, int k) // find a^k mod p
{
    int res = 1;
    while (k)
    {
        if (k & amp; 1) res = (LL)res * a ;
        a = (LL)a * a ;
        k >>= 1;
    }
    return res;
}

void solve(){
    LL x,y;
    scanf("%lld^{%lld}", &x, &y);
    
}
signed main()
{
    //cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
    deng[0]=".......";
    deng[1]=".......";
    deng[2]=".......";
    deng[3]=".......";
    deng[4]=".=======";
    deng[5]=".......";
    deng[6]=".=======";
    deng[7]=".......";
    deng[8]=".......";
    deng[9]=".......";

    inf[0]="................................";
    inf[1]="................................";
    inf[2]=".IIIIIII.N.....N.FFFFFFF";
    inf[3]="....I....NN....N.F...";
    inf[4]="....I....N.N...N.F...";
    inf[5]="....I..N..N..N.FFFFFFF";
    inf[6]="....I....N...N.N.F...";
    inf[7]="....I....N....NN.F...";
    inf[8]=".IIIIIII.N.....N.F......";
    inf[9]="................................";

    sda[0][0]=".......",sxiao[0][0]="......";
    sda[0][1]=".......",sxiao[0][1]=".00000";
    sda[0][2]=".0000000", sxiao[0][2]=".0...0";
    sda[0][3]=".0.....0",sxiao[0][3]=".0...0";
    sda[0][4]=".0.....0",sxiao[0][4]=".0...0";
    sda[0][5]=".0.....0", sxiao[0][5]=".00000";
    sda[0][6]=".0.....0", sxiao[0][6]="...";
    sda[0][7]=".0.....0", sxiao[0][7]="...";
    sda[0][8]=".0000000", sxiao[0][8]="...";
    sda[0][9]=".......",sxiao[0][9]="......";

    sda[1][0]=".......",sxiao[1][0]="......";
    sda[1][1]=".....",sxiao[1][1]=".....1";
    sda[1][2]=".....1", sxiao[1][2]=".....1";
    sda[1][3]=".....1", sxiao[1][3]=".....1";
    sda[1][4]=".....1", sxiao[1][4]=".....1";
    sda[1][5]=".....1", sxiao[1][5]=".....1";
    sda[1][6]="....1", sxiao[1][6]="...";
    sda[1][7]="....1", sxiao[1][7]="...";
    sda[1][8]="....1", sxiao[1][8]="...";
    sda[1][9]=".......",sxiao[1][9]="......";
    
    sda[2][0]=".......",sxiao[2][0]="......";
    sda[2][1]=".......",sxiao[2][1]=".22222";
    sda[2][2]=".2222222", sxiao[2][2]=".....2";
    sda[2][3]=".......2", sxiao[2][3]=".22222";
    sda[2][4]="....2", sxiao[2][4]=".2....";
    sda[2][5]=".2222222", sxiao[2][5]=".22222";
    sda[2][6]=".2...", sxiao[2][6]="...";
    sda[2][7]=".2...", sxiao[2][7]="...";
    sda[2][8]=".2222222", sxiao[2][8]="...";
    sda[2][9]=".......",sxiao[2][9]="......";
    
    sda[3][0]=".......",sxiao[3][0]="......";
    sda[3][1]=".......",sxiao[3][1]=".33333";
    sda[3][2]=".3333333", sxiao[3][2]=".....3";
    sda[3][3]=".......3", sxiao[3][3]=".33333";
    sda[3][4]="....3", sxiao[3][4]=".....3";
    sda[3][5]=".3333333", sxiao[3][5]=".33333";
    sda[3][6]="....3", sxiao[3][6]="...";
    sda[3][7]="....3", sxiao[3][7]="...";
    sda[3][8]=".3333333", sxiao[3][8]="...";
    sda[3][9]=".......",sxiao[3][9]="......";

    sda[4][0]=".......",sxiao[4][0]="......";
    sda[4][1]=".....",sxiao[4][1]=".4...4";
    sda[4][2]=".4.....4",sxiao[4][2]=".4...4";
    sda[4][3]=".4.....4", sxiao[4][3]=".44444";
    sda[4][4]=".4.....4",sxiao[4][4]=".....4";
    sda[4][5]=".4444444", sxiao[4][5]=".....4";
    sda[4][6]="....4", sxiao[4][6]="...";
    sda[4][7]=".......4", sxiao[4][7]="......";
    sda[4][8]="....4", sxiao[4][8]="...";
    sda[4][9]=".......",sxiao[4][9]="......";
    
    sda[5][0]=".......",sxiao[5][0]="......";
    sda[5][1]=".......",sxiao[5][1]=".55555";
    sda[5][2]=".5555555", sxiao[5][2]=".5....";
    sda[5][3]=".5...", sxiao[5][3]=".55555";
    sda[5][4]=".5......",sxiao[5][4]=".....5";
    sda[5][5]=".5555555", sxiao[5][5]=".55555";
    sda[5][6]="...5", sxiao[5][6]="...";
    sda[5][7]=".......5", sxiao[5][7]="......";
    sda[5][8]=".5555555", sxiao[5][8]="...";
    sda[5][9]=".......",sxiao[5][9]="......";
    
    sda[6][0]=".......",sxiao[6][0]="......";
    sda[6][1]=".......",sxiao[6][1]=".66666";
    sda[6][2]=".6666666", sxiao[6][2]=".6....";
    sda[6][3]=".6...", sxiao[6][3]=".66666";
    sda[6][4]=".6...",sxiao[6][4]=".6...6";
    sda[6][5]=".6666666", sxiao[6][5]=".66666";
    sda[6][6]=".6.....6", sxiao[6][6]="...";
    sda[6][7]=".6.....6", sxiao[6][7]="...";
    sda[6][8]=".6666666", sxiao[6][8]="...";
    sda[6][9]=".......",sxiao[6][9]="......";
    
    sda[7][0]=".......",sxiao[7][0]="......";
    sda[7][1]=".......",sxiao[7][1]=".77777";
    sda[7][2]=".7777777", sxiao[7][2]=".....7";
    sda[7][3]="....7", sxiao[7][3]=".....7";
    sda[7][4]="....7", sxiao[7][4]=".....7";
    sda[7][5]="....7", sxiao[7][5]=".....7";
    sda[7][6]="....7", sxiao[7][6]="...";
    sda[7][7]="....7", sxiao[7][7]="...";
    sda[7][8]="....7", sxiao[7][8]="...";
    sda[7][9]=".......",sxiao[7][9]="......";


    sda[8][0]=".......",sxiao[8][0]="...";
    sda[8][1]=".......",sxiao[8][1]=".88888";
    sda[8][2]=".8888888", sxiao[8][2]=".8...8";
    sda[8][3]=".8.....8", sxiao[8][3]=".88888";
    sda[8][4]=".8...8", sxiao[8][4]=".8...8";
    sda[8][5]=".8888888", sxiao[8][5]=".88888";
    sda[8][6]=".8.....8", sxiao[8][6]="...";
    sda[8][7]=".8.....8", sxiao[8][7]="...";
    sda[8][8]=".8888888", sxiao[8][8]="...";
    sda[8][9]=".......",sxiao[8][9]="...";

    sda[9][0]=".......",sxiao[9][0]="...";
    sda[9][1]=".......",sxiao[9][1]=".99999";
    sda[9][2]=".9999999", sxiao[9][2]=".9...9";
    sda[9][3]=".9.....9", sxiao[9][3]=".99999";
    sda[9][4]=".9.....9", sxiao[9][4]=".....9";
    sda[9][5]=".9999999", sxiao[9][5]=".99999";
    sda[9][6]=".......9", sxiao[9][6]="......";
    sda[9][7]=".......9", sxiao[9][7]="......";
    sda[9][8]=".9999999", sxiao[9][8]="...";
    sda[9][9]=".......",sxiao[9][9]="......";

    int t=1;
    cin>>t;
    while(t--)solve();
}

H.

Topic….Do not explain Real numbers have a decimal point, add up k real numbers=n and 0<=every real number<=n

hand can be found

When k>2*n: Let every 2*n number be 0.5, and then the other numbers are 0, so that the maximum sum is determined, and the minimum is that each number is 0.49999, and then because (k*0.5) is taken down The integer must be >=n, so the minimum value is 0, and the maximum value is 2*n

When k==2*n: Let every 2*n number be 0.5, and then the other numbers are all 0, so that the maximum sum is sure, and the minimum is that each number is 0.49999, but because k=n*2 all K-1 numbers go to 0.4999, and the remaining number must be greater than >0.5, so the minimum value is 0, and the maximum value is 2*n

Other situations: In fact, it is also the same as taking 0.5 as much as possible, and the remaining numbers can only be taken as n-(k-1)*0.5, and the maximum value is n + k/2 (two 1s of 0.5, so (k)/2, is Because there is one number left, note that the remaining number may also be xxx.5, so it is also counted), and the minimum value is 0.4999, the same reason

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
const int N = 1e6 + 10;
typedef long long LL;
int n,m,k;

int qmi(int a, int k) // find a^k mod p
{
    int res = 1;
    while (k)
    {
        if (k & amp; 1) res = (LL)res * a ;
        a = (LL)a * a ;
        k >>= 1;
    }
    return res;
}

void solve(){
    LL x,y;
    cin>>n>>k;
    if(k>2*n)
    {
        cout<<"0 "<<2*n<<"\
";
    }
    else if(k==n*2)
    {
        cout<<"1 "<<2*n<<"\
";
    }
    else {
        cout<<n-(k-1)/2<<" "<<n + k/2<<"\
";
    }
    
    
}
signed main()
{
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
    int t=1;
    cin>>t;
    while(t--)solve();
}

C; My idea is to enumerate length directly violently and then judge whether there are repeated strings in the back

import random
import sys
import os
import math
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from itertools import accumulate, combinations, permutations
from heapq import nsmallest, nlargest, heapify, heappop, heappush
from io import BytesIO, IOBase
from copy import deepcopy
import threading
import bisect

# from sortedcontainers import SortedList
BUFSIZE = 4096


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self. newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\
") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self. writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\
")


def I():
    return input()


def II():
    return int(input())


def MI():
    return map(int, input(). split())


def LI():
    return list(input(). split())


def LII():
    return list(map(int, input(). split()))


def GMI():
    return map(lambda x: int(x) - 1, input(). split())


def LGMI():
    return list(map(lambda x: int(x) - 1, input(). split()))




def solve():
    s=I()
    for i in range(1000,10000 + 1):
        if len(s)%i!=0: continue
        if t in s[i:]:
            print("NO")
            return
    print("YES")
#2 0-59

# Press the green button in the gap to run the script.
if __name__ == '__main__':
    for _ in range(1):
        solve()
# Visit https://www.jetbrains.com/help/pycharm/ for PyCharm help

K:

First type table 1-10 to get the result

Well, there is no obvious rule

Then let the number of arrangements be the largest, and the adjacent difference must be 2

The rest of the numbers can be directly brute force to find out which values to insert

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
const int N = 1e6 + 10;
typedef long long LL;
int n,m,k;
int a[N];
bool st[N];
bool check(int n){
    if(n<=3) return n>1;
    if(n%6!=1 & amp; & amp;n%6!=5) return false;
    for(int i=5;i<=n/i;i + =6){
        if(n%i==0||n%(i + 2)==0) return false;
    }
    return true;
}
void solve(){
    cin>>n;
    for(int i=1;i<=n;i + + ) a[i]=i;
    if(n<=4){
        cout<<"-1\
";
        return;
    }
    if(n<=10)
    {
        do
        {
            a[n + 1]=a[1];
            bool f=true;
            for(int i=2;i<=n + 1;i + + ){
                int x=abs(a[i]-a[i-1]);
                if(!check(x)){
                    f=false;
                    break;
                }
            }
            if(f){
                for(int i=1;i<=n;i + + ){
                    cout<<a[i]<<" ";
                }
                cout<<"\
";
                return;
            }
        }while(next_permutation(a+1,a+1+n));
    }
    vector<int> b;
    k=(n &1)?0:-1;
        for(int i=1;i<=n + k;i + =2)
        {
            st[i]=true;
            b. push_back(i);
        }
        for(int i=n-3 + k;i>=4;i-=2){
            st[i]=true;
            b. push_back(i);
        }

    vector<int> res;
    for(int i=1;i<=n;i + + ){
        if(!st[i]) res.push_back(i);
    }
    while(res. size()){
        int x = res.back();
        res. pop_back();
        vector<int>c;
        bool f=true;
        for(int i=0;i<b. size()-1;i ++ )
        {
            c.push_back(b[i]);
            if(!f) continue;
            if(check(abs(b[i]-x)) & amp; & amp;check(abs(b[i + 1]-x))){
                f=false;
                c.push_back(x);
            }
        }
        c.push_back(b.back());
        b=c;
    }
    for(auto &x:b) cout<<x<<" ";
    
}
signed main()
{
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
    int t=1;
    //cin>>t;
    while(t--)solve();
}