Round 1201 (Codeforces Round (div.2)) Problem Solution

Keywords: PHP

Problem A

meaning of the title

There are n students, m questions. Each question has a score of ai. Each student answered each question (only A,B,C,D,E). They don't know the right answer. Ask the total score of the students in the best case.

thinking

Violence is enough. For each question, enumerate all possible answers, calculate the total score of all students, and add the largest one to the total answer.

# include <bits/stdc++.h>
# define rr register
const int N=1010;
int n,m;
int val[N];
char a[N][N];
char ans[10]={' ','A','B','C','D','E'};
int sum;
int main(void){
    scanf("%d%d",&n,&m);
    for(rr int i=1;i<=n;++i){
        for(rr int j=1;j<=m;++j){
            std::cin>>a[i][j];
        }
    }
    for(rr int i=1;i<=m;++i){
        scanf("%d",&val[i]);
    }
    for(rr int i=1,maxx,tmp;i<=m;++i){
        maxx=-1e9;
        for(rr int k=1;k<=5;++k){
            tmp=0;
            for(rr int j=1;j<=n;++j){
                if(a[j][i]==ans[k]){
                    tmp+=val[i];
                }
            }
            maxx=std::max(maxx,tmp);            
        }
        sum+=maxx;
    }
    printf("%d",sum);
    return 0;
}

Problem B

meaning of the title

Give you an array of length n. The elements of the array are positive integers. You can choose two different elements at a time and subtract them by one. Ask if the elements of the entire array can be changed to zero after several operations.

thinking

The nightmare begins.. This question was handed in three times before passing, and the penalty was 100 points. Heart ache

First, if the sum of the whole array is odd, then it must not work. Because each operation reduces array elements by 2, if the sum of array elements is required to be 0, then the original array and odd numbers are not feasible (odd-even = odd).

In addition, if the largest element in the array is greater than the sum of other elements, it is not possible. Because when all other elements become zero, the largest element cannot be changed to zero.

# include <bits/stdc++.h>
# define rr register
# define int long long
const int N=200010;
int a[N];
int b[N];
int sum;
int n;
signed main(void){
    scanf("%I64d",&n);
    for(rr int i=1;i<=n;++i){
        scanf("%I64d",&a[i]);
        sum+=a[i];
    }
    std::sort(a+1,a+1+n);
    if(sum%2||a[n]>(sum-a[n])){
        printf("NO");
        return 0;
    }else{
        printf("YES");
        return 0;
    }
    return 0;
}

Problem C

Write again in the morning. Sleep first.

Problem D,E1,E2

I haven't seen it. It's too hard.

Posted by FluxNYC on Wed, 09 Oct 2019 22:14:28 -0700