1201A - Important Exam - CodeForces Solution


implementation strings *900

Please click on ads to support us..

Python Code:

n,m = map(int,input().split())
li = []
for i in range(n):
    li.append(input())
score_arr = list(map(int,input().split()))
score = 0
for i in range(m):
    a,b,c,d,e = 0,0,0,0,0
    for j in range(n):
        if li[j][i]=='A':
            a+=1 
        elif li[j][i]=='B':
            b+=1 
        elif li[j][i]=='C':
            c+=1 
        elif li[j][i]=='D':
            d+=1 
        else:
            e+=1
    score = score+max(a,b,c,d,e)*score_arr[i]
print(score)

C++ Code:

#include<iostream>
#include<bits/stdc++.h>
#define el endl
#define ll long long
#define du double
#define all(v) v.begin(),v.end()
#define forme for(int i=0;i<x;i++){cin>>arr[i];}
#define fast ios_base::sync_with_stdio(false),cout.tie(NULL),cin.tie(NULL);
#define Omar_Ahmed_O_H_M codeforce
const int N = 1e9 + 5;
using namespace std;
int main(){
fast;
ll a,x,y,ans=0;
cin>>x>>y;
string s;
ll arr[20001][6],vec[y];
memset(arr,0,sizeof arr);
for(int i=0;i<x;i++)
  {cin>>s;
   for(int j=0;j<y;j++)
      arr[j][s[j]]++;
  }
  for(int i=0;i<y;i++){
        cin>>vec[i];
  }
for(int i=0;i<y;i++)
 {
  ll sum=0;
  for(char j='A';j<='E';j++)
    sum=max(sum,arr[i][j]);
  ans+=sum*vec[i];
 }
cout<<ans<<el;
}


Comments

Submit
0 Comments
More Questions

1330A - Dreamoon and Ranking Collection
1692B - All Distinct
1156C - Match Points
1675A - Food for Animals
1328C - Ternary XOR
1689A - Lex String
1708B - Difference of GCDs
863A - Quasi-palindrome
1478A - Nezzar and Colorful Balls
1581B - Diameter of Graph
404A - Valera and X
908A - New Year and Counting Cards
146A - Lucky Ticket
1594C - Make Them Equal
1676A - Lucky
1700B - Palindromic Numbers
702C - Cellular Network
1672C - Unequal Array
1706C - Qpwoeirut And The City
1697A - Parkway Walk
1505B - DMCA
478B - Random Teams
1705C - Mark and His Unfinished Essay
1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats