prob_desc_description stringlengths 63 3.8k | prob_desc_output_spec stringlengths 17 1.47k ⌀ | lang_cluster stringclasses 2 values | src_uid stringlengths 32 32 | code_uid stringlengths 32 32 | lang stringclasses 7 values | prob_desc_output_to stringclasses 3 values | prob_desc_memory_limit stringclasses 19 values | file_name stringclasses 111 values | tags listlengths 0 11 | prob_desc_created_at stringlengths 10 10 | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_notes stringlengths 4 3k ⌀ | exec_outcome stringclasses 1 value | difficulty int64 -1 3.5k ⌀ | prob_desc_input_from stringclasses 3 values | prob_desc_time_limit stringclasses 27 values | prob_desc_input_spec stringlengths 28 2.42k ⌀ | prob_desc_sample_outputs stringlengths 2 796 | source_code stringlengths 42 65.5k | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils. | In the first line print a single real number with exactly one decimal place — the minimum total price of the items, including the discounts. In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≤ bj ≤ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input. If there are multiple optimal distributions, you are allowed to print any of them. | C | 06c7834aa4d06d6fcebfa410054f1b8c | a5bc2c7a72a779854864a61740d13356 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"sortings",
"greedy"
] | 1331478300 | ["3 2\n2 1\n3 2\n3 1", "4 3\n4 1\n1 2\n2 2\n3 2"] | NoteIn the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2·0.5 + (3 + 3·0.5) = 1 + 4.5 = 5.5. | PASSED | 1,700 | standard input | 3 seconds | The first input line contains two integers n and k (1 ≤ k ≤ n ≤ 103) — the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≤ ci ≤ 109) is an integer denoting the price of the i-th item, ti (1 ≤ ti ≤ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces. | ["5.5\n2 1 2\n1 3", "8.0\n1 1\n2 4 2\n1 3"] | #include<stdio.h>
#include<stdlib.h>
typedef struct Item{
int t,c,i;
}Item;
int cmp(Item* p1, Item *p2){
if(p1->t == p2->t) return -(p1->c - p2->c);
return (p1->t - p2->t);
}
int main(){
int flag=0,i,m,n,k,kf,min,x=0;
double pt=0.0;
scanf("%d %d",&n,&k);
Item a[n];
for(i=0;i<n;i++){
scanf("%d %d",&a[i].c,&a[i].t);
a[i].i = i+1;
if(a[i].t==1) x++;
}
qsort(a,n,sizeof(Item),cmp);
if(x<k) m = x;
else m = k-1;
for(i=0;i<m;i++){
pt+=a[i].c/2.0;
}
kf = m+1;
for(i=m;i<n;i++){
if(kf>=k){
if(a[i].t==1) {
flag = 1;
min = a[i].c;
}
pt+=a[i].c;
}
else{
if(a[i].t==1) pt += a[i].c/2.0;
else pt+=a[i].c;
}
kf++;
}
if(flag==1){
if(min>a[n-1].c) pt-=a[n-1].c/2.0;
else pt-=min/2.0;
}
printf("%.1lf",pt);
for(i=0;i<k-1;i++){
if(i==0)printf("\n");
printf("1 %d",a[i].i);
if(i!=k-2)printf("\n");
}
if(n-k+1!=0){
printf("\n%d",n-k+1);
for(i=k-1;i<n;i++){
printf(" %d",a[i].i);
}
}
return 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 74f99d59d4967df67616d3d8e23d6290 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
#define OPTIONS 5
void read(int *arr, int length, int width) {
char ch;
for (int i=0; i<length; i++) {
for (int j=0; j<width; j++) {
scanf("%c",&ch);
*((arr+i*width)+j)=(ch-'A');
}
scanf("\n");
}
}
void write(int *arr, int length, int width) {
for (int i=0; i<length; i++) {
for (int j=0; j<width; j++) printf("%d",*((arr+i*width)+j));
printf("\n");
}
}
void scan(int *arr, int length) {
for (int i=0; i<length; i++) scanf("%d",(arr+i));
}
void print(int *arr, int length) {
for (int i=0; i<length; i++) printf("%d ",*(arr+i));
}
void initialize(int *arr, int length) {
for (int i=0; i<length; i++) arr[i]=0;
}
int max(int *arr, int length) {
int res=arr[0];
for (int i=1; i<length; i++) {
if (res<arr[i]) res=arr[i];
}
return res;
}
void frequency(int *biarr, int length, int width, int *arr, int opt) {
int hist[opt];
for (int j=0; j<width; j++) {
initialize(hist,opt);
for (int i=0; i<length; i++) hist[*((biarr+i*width)+j)]++;
arr[j]=max(hist,opt);
}
}
long inn(int *x, int *y, int length) {
long res=0;
for (int i=0; i<length; i++) res+=x[i]*y[i];
return res;
}
int main() {
int len,wid;
scanf("%d %d\n",&len,&wid);
int answer[len][wid],point[wid],maxfreq[wid];
read(answer,len,wid);
scan(point,wid);
frequency(answer,len,wid,maxfreq,OPTIONS);
printf("%ld",inn(maxfreq,point,wid));
return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | f2b198d3750a132ad3798ed7888bc634 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<string.h>
int main(){
int n, m;
int points[1100];
char ans[1100][1100];
char correct[1100];
int score =0;
int A[1100];
int B[1100];
int C[1100];
int D[1100];
int E[1100];
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++){
scanf("%s",&ans[i]);
}
for(int j=0;j<m;j++){
scanf("%d",&points[j]);
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(ans[i][j]=='A') A[j]++;
if(ans[i][j]=='B') B[j]++;
if(ans[i][j]=='C') C[j]++;
if(ans[i][j]=='D') D[j]++;
if(ans[i][j]=='E') E[j]++;
}
}
for(int j=0;j<m;j++){
int max =0;
if(A[j]>max){
max = A[j];
correct[j] = 'A';
}
if(B[j]>max){
max = B[j];
correct[j] = 'B';
}
if(C[j]>max){
max = C[j];
correct[j] = 'C';
}
if(D[j]>max){
max = D[j];
correct[j] = 'D';
}
if(E[j]>max){
max = E[j];
correct[j] = 'E';
}
}
// printf("%d",correct[1]);
for(int j=0;j<m;j++){
for(int i=0;i<n;i++){
if(ans[i][j]==correct[j]){
score = score + points[j];
}
}
}
printf("%d\n",score);
return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 677fa0e1f7417564032c14c99c2e65be | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int main(){
int n,m;
scanf("%d%d",&n,&m);
char stch[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)
scanf(" %c",&stch[i][j]);
}
int ms[m];
for(int i=0;i<m;i++)
scanf("%d",&ms[i]);
int c[5];
char tr[m][n];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
tr[i][j]=stch[j][i];
}
}
int sum=0;
for(int i=0;i<m;i++){
for(int j=0;j<5;j++)
c[j]=0;
for(int j=0;j<n;j++){
c[tr[i][j]-65]++;
}
int max=0;
for(int j=0;j<5;j++){
if(c[j]>max)
max=c[j];
}
sum=sum+ms[i]*max;
}
printf("%d",sum);
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 790f76329ebd5af36e136e130bbf9bf0 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<stdlib.h>
#define size 1001
main()
{
long int n,m,i,j,res=0;
scanf("%ld %ld",&n,&m);
char s[size][size];
long int a[size];
long int cnt[5]={0};
for(i=0;i<n;++i)
{
scanf("%s",&s[i]);
}
for(i=0;i<m;++i)
{
scanf("%ld",&a[i]);
}
for(i=0;i<m;++i)
{
long int max=0;
for(long int r=0;r<5;++r)
{
cnt[r]=0;
}
for(j=0;j<n;++j)
{
cnt[s[j][i]-'A']++;
if(cnt[s[j][i]-'A']>max)
{
max=cnt[s[j][i]-'A'];
}
}
res+=(a[i]*max);
}
printf("%ld",res);
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 45e5b12974e3e69948f69707cf7426cf | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<string.h>
int main()
{
int n,m,i,j,p,q,r,s,t;
scanf("%d%d",&n,&m);
int a[m];
char s1[n+1][m+1];
long long int sum=0;
for(i=0; i<n; i++)
scanf("%s",&s1[i]);
for(i=0; i<m; i++)
scanf("%d",&a[i]);
for(i=0; i<m; i++)
{
p=q=r=s=t=0;
for(j=0; j<n; j++)
{
if(s1[j][i]=='A')
p++;
if(s1[j][i]=='B')
q++;
if(s1[j][i]=='C')
r++;
if(s1[j][i]=='D')
s++;
if(s1[j][i]=='E')
t++;
}
if(p>=q&&p>=r&&p>=s&&p>=t)
sum=sum+a[i]*p;
else if(q>=p&&q>=r&&q>=s&&q>=t)
sum=sum+a[i]*q;
else if(r>=q&&r>=p&&r>=s&&r>=t)
sum=sum+a[i]*r;
else if(t>=q&&t>=r&&t>=s&&t>=p)
sum=sum+a[i]*t;
else
sum=sum+a[i]*s;
}
printf("%d\n",sum);
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 47c8a0f982e4f2ba8f3b173957ab7bc4 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<string.h>
int main()
{
int q,i,j,pos,marks,res=0,max,count,st;
scanf("%d%d",&st,&q);
char s[q];
int a[q][5];
for(i=0;i<q;i++)
{
for(j=0;j<=4;j++)
a[i][j]=0;
}
for(i=0;i<st;i++)
{
scanf("%s",s);
count=0;
for(j=0;j<q;j++)
{
int asci=(int)s[j];
pos=asci-65;
a[count][pos]+=1;
count+=1;
}
}
for(i=0;i<q;i++)
{
scanf("%d",&marks);
max=a[i][0];
for(j=0;j<=4;j++)
{
if(a[i][j]>max)
max=a[i][j];
}
res+=marks*max;
}
printf("%d",res);
return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 1b573e3bba42a3dd082947347b535522 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<string.h>
int main()
{
int q,i,j,pos,marks,res=0,max,count,st;
scanf("%d%d",&st,&q);
char s[q];
int a[q][5];
for(i=0;i<q;i++)
{
for(j=0;j<=4;j++)
a[i][j]=0;
}
for(i=0;i<st;i++)
{
scanf("%s",s);
count=0;
for(j=0;j<q;j++)
{
int asci=(int)s[j];
pos=asci-65;
a[count][pos]+=1;
count+=1;
}
}
for(i=0;i<q;i++)
{
scanf("%d",&marks);
max=a[i][0];
for(j=0;j<=4;j++)
{
if(a[i][j]>max)
max=a[i][j];
}
res+=marks*max;
}
printf("%d",res);
return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 0d2107760aab3642ce2db9b385a88321 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<string.h>
int main()
{
int n,m,i,j,a,b,c,d,e,sum=0;
n--;
scanf("%d", &n);
scanf("%d", &m);
char str[n][m];
int ara[m];
for(i=0; i<n; i++)
{
scanf("%s\n", &str[i]);
}
for(i=0; i<m; i++)
{
scanf("%d", &ara[i]);
}
for(i=0; i<m; i++)
{
a=0;b=0;c=0;d=0;e=0;
for(j=0; j<n; j++)
{
if(str[j][i]=='A')
a++;
else if(str[j][i]=='B')
b++;
else if(str[j][i]=='C')
c++;
else if(str[j][i]=='D')
d++;
else if(str[j][i]=='E')
e++;
}
if(a>=b && a>=c && a>=d && a>=e)
sum=sum+a*ara[i];
else if(b>=a && b>=c && b>=d && b>=e)
sum=sum+b*ara[i];
else if(c>=b && c>=a && c>=d && c>=e)
sum=sum+c*ara[i];
else if(d>=b && d>=c && d>=a && d>=e)
sum=sum+d*ara[i];
else if(e>=b && e>=c && e>=d && e>=a)
sum=sum+e*ara[i];
}
printf("%d", sum);
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | e89aff27ec056c9fe9a1cf84353e90a1 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<string.h>
int main()
{
int n,m,i,j,a,b,c,d,e,sum=0;
scanf("%d", &n);
scanf("%d", &m);
char str[n][m];
int ara[m];
for(i=0; i<n; i++)
{
scanf("%s\n", &str[i]);
}
for(i=0; i<m; i++)
{
scanf("%d", &ara[i]);
}
for(i=0; i<m; i++)
{
a=0;b=0;c=0;d=0;e=0;
for(j=0; j<n; j++)
{
if(str[j][i]=='A')
a++;
else if(str[j][i]=='B')
b++;
else if(str[j][i]=='C')
c++;
else if(str[j][i]=='D')
d++;
else if(str[j][i]=='E')
e++;
}
if(a>=b && a>=c && a>=d && a>=e)
sum=sum+a*ara[i];
else if(b>=a && b>=c && b>=d && b>=e)
sum=sum+b*ara[i];
else if(c>=b && c>=a && c>=d && c>=e)
sum=sum+c*ara[i];
else if(d>=b && d>=c && d>=a && d>=e)
sum=sum+d*ara[i];
else if(e>=b && e>=c && e>=d && e>=a)
sum=sum+e*ara[i];
}
printf("%d", sum);
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 0f272ee0ab892fb07c92c394926cac16 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int comp(const void * a,const void * b)
{
return (*(int*)a - *(int*)b);
}
int main()
{
int t,n,m,i,j,k,l,arr[1009][6]={},max[1009]={},sum,p,q;
char c[1009][1009];
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
scanf("%s",&c[i]);
for(i=0;i<m;i++){
for(j=0;j<n;j++){
if(c[j][i]=='A')
arr[i][1]++;
else if(c[j][i]=='B')
arr[i][2]++;
else if(c[j][i]=='C')
arr[i][3]++;
else if(c[j][i]=='D')
arr[i][4]++;
else if(c[j][i]=='E')
arr[i][5]++;
}
}
for(i=0;i<m;i++){
sum=0;
for(j=1;j<=5;j++){
if(arr[i][j]>sum)
sum=arr[i][j];
}
max[i]=sum;
}
sum=0;
for(i=0;i<m;i++){
scanf("%d",&k);
t=k*max[i];
sum+=t;
}
printf("%d",sum);
printf("");
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | f565b82107855a8ad65ba79e2eb256b7 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<stdlib.h>
int comp(const void*x,const void*y)
{
return(*(int*)x-*(int*)y);
}
int main()
{
int n,m,b,i,j,sum=0,x;
char s[1005][1005]={};
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%s",s[i]);
}
for(i=0;i<m;i++)
{
int count[5]={0};
scanf("%d",&b);
for(j=0;j<n;j++)
{
x=s[j][i]-65;
count[x]++;
}
qsort(count, 5, sizeof(int), comp);
sum=sum+(count[4]*b);
}
printf("%d\n",sum);
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 63d0f62f8b93b0ee762305d903aa55d5 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
int main ()
{
int n, m;
scanf("%d%d", &n, &m);
char input[n][m + 1];
int max[m];
int cnt[5];
for (int i = 0; i < n; i++)
{
scanf("%s", input[i]);
}
for (int j = 0; j < m; j++)
{
for (int i = 0; i < 5; i++)
cnt[i] = 0;
for (int k = 0; k < n; k++)
{
for (int i = 0; i < 5; i++)
{
if (input[k][j] == 'A' + i)
cnt[i]++;
}
}
max[j] = 0;
for (int i = 0; i < 5; i++)
{
if (max[j] < cnt[i])
max[j] = cnt[i];
}
}
long sum = 0;
for (int i = 0; i < m; i++)
{
int a;
scanf("%d", &a);
sum += (long)a * max[i];
}
printf("%ld", sum);
return 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | dbbbe9b87354cad2fb9d071c111e8928 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int main()
{
int n,m,tot_mrk=0;
scanf("%d %d",&n,&m);
char s[n][m+1];
for(int i=0;i<n;i++)
{
scanf(" %[^\n]",s[i]);
}
int mrk[m];
for(int i=0;i<m;i++)
{
scanf("%d",&mrk[i]);
}
for(int j=0;j<m;j++)
{
int mx=0;
int num[5]={0};
for(int k=0;k<n;k++)
{
num[s[k][j]-65]++;
}
for(int m=0;m<5;m++)
{
if(num[m]>mx)
mx=num[m];
}
tot_mrk+=mx*mrk[j];
}
printf("%d",tot_mrk);
return 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | d8bb08dc03e385e16a6c7c20400a01ac | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
int main()
{
int max,n,m,a[1001],b[5]={0,},c=0;
char s[1001][1001];
scanf("%d %d",&n,&m);
for(int i=0; i<n; i++){
scanf(" %s",s[i]);
}
for(int i=0; i<m; i++){
scanf("%d",&a[i]);
}
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
b[(s[j][i]-'A')]++;
}
max=0;
for(int j=0; j<5; j++){
if(max < b[j]) max=b[j];
b[j]=0;
}
c+=max*a[i];
}
printf("%d",c);
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | cb552356ce66660d773611ac37434a12 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int n,m;
int i,j,d;
char a[1500][1500];
int b[1500][10]={0};
int point[1500];
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%s",a[i]);
for(j=0;j<m;j++)
{
d=a[i][j]-'A';
b[j][d]++;
}
}
for(i=0;i<m;i++)
scanf("%d",&point[i]);
int max,sum=0;
for(i=0;i<m;i++)
{ max=0;
for(j=0;j<=5;j++)
{
if(max<b[i][j])
max=b[i][j];
}
sum+=max*point[i];
}
printf("%d",sum);
return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 6fb2dc202aab8b241b3d3192d8480511 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int main()
{
int n,m,i,k,j,sum=0,a[1000],b[5]={0},max=0;
scanf("%d%d",&n,&m);
char c[1000][1000],d[1000];
for(i=0;i<n;i++)
{
scanf("%s",c[i]);
}
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(c[j][i]=='A')
{
b[0]++;
}
else if(c[j][i]=='B')
{
b[1]++;
}
else if(c[j][i]=='C')
{
b[2]++;
}
else if(c[j][i]=='D')
{
b[3]++;
}
else if(c[j][i]=='E')
{
b[4]++;
}
}
max=b[0];
for(k=1;k<5;k++)
{
if(max<b[k])
{
max=b[k];
}
}
if(max==b[0])
{
d[i]='A';
}
else if(max==b[1])
{
d[i]='B';
}
else if(max==b[2])
{
d[i]='C';
}
else if(max==b[3])
{
d[i]='D';
}
else if(max==b[4])
{
d[i]='E';
}
//printf("%c ",d[i]);
b[0]=0;
b[1]=0;
b[2]=0;
b[3]=0;
b[4]=0;
max=0;
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(c[i][j]==d[j])
{
sum+=a[j];
}
}
}
printf("\n%d",sum);
return 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | cebf8b2f008d94dc660bbe29e5a08f6b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int main()
{
int n,m,i,j,x=0,sum=0,k,max=0;
char ch;
scanf("%d%d%c",&n,&m,&ch);
char ara[n][m+1];
int ara2[m];
for(i=0;i<n;i++){
gets(&ara[i][0]);
}
for(i=0;i<m;i++){
scanf("%d",&ara2[i]);
}
for(i=0;i<m;i++){
for(j=0;j<n;j++){
for(k=j;k<n;k++){
if(ara[k][i]==ara[j][i]){
x++;
}
}
if(x>max){
max=x;
//l=k;
}
x=0;
}
sum=sum+(max*ara2[i]);
max=0;
}
printf("%d",sum);
return 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | a568e057f1100b949c66eff9b8cc328b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int main(){
int n,m,sum=0;
scanf("%d %d",&n,&m);
int val[m];
char arr[n][m];
for(int i=0;i<n;i++){
scanf("%s",arr[i]);
}
for(int j=0;j<m;j++)
scanf("%d",&val[j]);
for(int i=0;i<m;i++)
{
int alph[26],max =0;
for(int j=0;j<26;j++)
alph[j] = 0;
for(int j=0;j<n;j++)
{
alph[arr[j][i]-65]++;
}
for(int j=0;j<26;j++)
if(alph[j]>max)
max = alph[j];
sum += max*val[i];
}
printf("%d",sum);
return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | c270feb9d705fcae99661a1ead5ad31c | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int main()
{
long long int n,m,i,j=0;
long long int sum=0;
scanf("%lld %lld",&n,&m);
char s[n][m+1];
long long int a[m];
for(i=0;i<n;i=i+1)
{
scanf("%s",&s[i]);
}
for(i=0;i<m;i=i+1)
{
scanf("%lld",&a[i]);
}
while(j<m)
{
long long int b=0,c=0,d=0,e=0,f=0;
for(i=0;i<n;i=i+1)
{
if(s[i][j]=='A')
{
b=b+1;
}
else if(s[i][j]=='B')
{
c=c+1;
}
else if(s[i][j]=='C')
{
d=d+1;
}
else if(s[i][j]=='D')
{
e=e+1;
}
else if(s[i][j]=='E')
{
f=f+1;
}
}
if(b>=c && b>=d && b>=e && b>=f)
{
sum=sum+(b*(a[j]));
}
else if(c>=b && c>=d && c>=e && c>=f)
{
sum=sum+(c*(a[j]));
}
else if(d>=c && d>=b && d>=e && d>=f)
{
sum=sum+(d*(a[j]));
}
else if(e>=c && e>=d && e>=b && e>=f)
{
sum=sum+(e*(a[j]));
}
else if(f>=c && f>=d && f>=e && f>=b)
{
sum=sum+(f*(a[j]));
}
j=j+1;
}
printf("%lld",sum);
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 5f921c4aa854b42a16508ef67156c126 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int main(){
int n,m,total=0;
scanf("%d %d",&n,&m);
getchar();
char a[n][m];
char s[m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
scanf("%c",&a[i][j]);
}
getchar();
}
int score[m];
for(int j=0;j<m;j++)
scanf("%d",score+j);
for(int j=0;j<m;j++){
int option[5] = {0};
for(int i=0;i<n;i++){
if(a[i][j] == 'A')
option[0]++;
else if(a[i][j] == 'B')
option[1]++;
else if(a[i][j] == 'C')
option[2]++;
else if(a[i][j] == 'D')
option[3]++;
else if(a[i][j] == 'E')
option[4]++;
}
int max = option[0];
for(int k=0;k<5;k++){
if(option[k] > max)
max = option[k];
}
total = total + max*score[j];
}
printf("%d",total);
return 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | d15722e8c733a4736517a8b5d510d425 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
int main(){
int students, questions,maxScore = 0,tmp = 0;
scanf("%d %d",&students, &questions);
int calculate[5][questions];
char answer[questions+1];
int qScore[questions];
for(int i=0;i<5;i++){
for(int j=0;j<questions;j++){
calculate[i][j]=0;
}
}
for(int i=0;i<students;i++){
scanf("%s",answer);
for(int j=0;j<questions;j++){
calculate[answer[j]-'A'][j]++;
}
}
for (int j=0;j<questions;j++){
scanf("%d",&qScore[j]);
}
for(int j=0;j<questions;j++){
for(int i=0;i<5;i++){
if(calculate[i][j] > tmp)
tmp = calculate[i][j];
}
maxScore=maxScore+tmp*qScore[j];
tmp = 0;
}
printf("%d\n",maxScore);
return 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | dd4d848bb45ad7b2b89289dff4aabf2b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int max(int counter_a,int counter_b,int counter_c,int counter_d,int counter_e)
{
int max=0;
if(max<counter_a)
max=counter_a;
if(max<counter_b)
max=counter_b;
if(max<counter_c)
max=counter_c;
if(max<counter_d)
max=counter_d;
if(max<counter_e)
max=counter_e;
return max;
}
int main(void)
{
int n,m,l=0,sum=0;
scanf("%d %d",&n,&m);
scanf("%*c");
char str[n][m+1];
int ara[m],ara1[1001];
int i,j,k;
int counter_a,counter_b,counter_c,counter_d,counter_e;
for(i=0; i<n; i++)
{
scanf("%s",str[i]);
}
for(i=0; i<m; i++)
scanf("%d",&ara[i]);
for(i=0; i<m+1; i++)
{
counter_a=counter_b=counter_c=counter_d=counter_e=0;
for(j=0; j<n; j++)
{
if(str[j][i]=='A')
{
counter_a++;
}
else if(str[j][i]=='B')
{
counter_b++;
}
else if(str[j][i]=='C')
counter_c++;
else if(str[j][i]=='D')
counter_d++;
else
counter_e++;
}
ara1[l++]=max(counter_a,counter_b,counter_c,counter_d,counter_e);
}
for(i=0; i<l-1 ; i++)
sum=sum+ara1[i]*ara[i];
printf("%d",sum);
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 614ec1af2648ad3582b18549e81796ae | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
#define MAX 1000
int max(int x, int y) {
return (x > y) ? x : y;
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
char ans[MAX];
int pts[MAX];
int result = 0;
int a[MAX] = {0};
int b[MAX] = {0};
int c[MAX] = {0};
int d[MAX] = {0};
int e[MAX] = {0};
for (int i = 0; i < n; i++) {
scanf("%s", ans);
for (int j = 0; j < m; j++) {
if (ans[j] == 'A') a[j]++;
else if (ans[j] == 'B') b[j]++;
else if (ans[j] == 'C') c[j]++;
else if (ans[j] == 'D') d[j]++;
else e[j]++;
}
}
for (int i = 0; i < m; i++) {
scanf("%d", &pts[i]);
}
for (int i = 0; i < m; i++) {
result += max(max(max(max(pts[i] * a[i], pts[i] * b[i]), pts[i] * c[i]), pts[i] * d[i]), pts[i] * e[i]);
}
printf("%d\n", result);
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 0bd0bf2ba92a300e2791503f47eb954a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MIN(a,b) a<b?a:b
#define MAX(a,b) a>b?a:b
#define rep(i,a,b) for(i=a;i<b;i++)
#define rev(i,a,b) for(i=a;i>b;i--)
#define sf(a) scanf("%d",&(a))
#define pf(a) printf("%d",(a))
#define sfll(a) scanf("%lld",&(a))
#define pfll(a) printf("%lld",(a))
#define ssf(a) scanf("%s",(a))
#define spf(a) printf("%s",(a))
#define spc printf(" ");
#define nl printf("\n")
#define play int main()
#define out return
typedef int I;
typedef long long LL;
typedef char S;
typedef float F;
typedef double D;
/*int cmp(const void *a,const void *b)
{
return (*(int*)b-*(int*)a);
}*/
play
{
I n,m,i,j,a[1000],mx=0,k,b[5];
sf(n),sf(m);
S str[n][m+1];
rep(i,0,n)
ssf(str[i]);
rep(i,0,m)
sf(a[i]);
LL s=0;
rep(j,0,m)
{
memset(b,0,sizeof(b));
rep(i,0,n)
b[str[i][j]-'A']++;
rep(k,0,5)
mx=MAX(mx,b[k]);
s+=(mx*a[j]);
mx=0;
}
pfll(s);
nl;
out 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 34d7392a3b178cf143646d073dcaad5d | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int n, m;
scanf("%d %d", &n, &m);
int i, j;
char s[1003];
int count[1003][5];
for (i = 0; i < 1003; i++)
{
for (j = 0; j < 5; j++)
{
count[i][j] = 0;
}
}
for (i = 0; i < n; i++)
{
scanf("%s", s);
for (j = 0; j < m; j++)
{
count[j][s[j] - 'A']++;
}
}
int max, ans = 0;
int a[1003];
for (i = 0; i < m; i++)
{
scanf("%d", &a[i]);
}
for (i = 0; i < m; i++)
{
max = 0;
for (j = 0; j < 5; j++)
{
if (max < count[i][j])
{
max = count[i][j];
}
}
ans += max * a[i];
}
printf("%d\n", ans);
return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 9d3faf67a89c59ac562e2621c4186147 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
//==============================================================================
//==============================================================================
FILE *pfin;
#ifdef CODEBLOCKS
#define SELECT_INPUT pfin = fopen("in.txt", "r");
#else
#define SELECT_INPUT pfin = stdin;
#endif
//==============================================================================
//==============================================================================
#define MIN(A, B) (((A) < (B)) ? (A) : (B))
typedef unsigned long long ULL;
//==============================================================================
//==============================================================================
void prep();
void clean();
void test();
//==============================================================================
//==============================================================================
int main()
{
SELECT_INPUT
prep();
// int tt; for(fscanf(pfin, "%d\n", &tt); tt; tt--)
test();
clean();
fclose(pfin);
return(0);
}
//==============================================================================
//==============================================================================
void prep()
{
}
//==============================================================================
//==============================================================================
void clean()
{
}
//==============================================================================
//==============================================================================
int mos[1005][5];
int pun[1005];
//==============================================================================
//==============================================================================
void test()
{
int tstu, tte, is, i, sum, mx, j;
char ans[1005];
fscanf(pfin, "%d %d", &tstu, &tte);
for(i = 0; i < tte; i++)
{
for(j = 0; j < 5; j++)
mos[i][j] = 0;
}
for(is = 0; is < tstu; is++)
{
fscanf(pfin, "%s", ans);
for(i = 0; i < tte; i++)
{
mos[i][ans[i] - 'A']++;
}
}
for(i = 0; i < tte; i++)
fscanf(pfin, "%d", &pun[i]);
sum = 0;
for(i = 0; i < tte; i++)
{
mx = mos[i][0];
for(j = 1; j < 5; j++)
{
if(mos[i][j] > mx)
mx = mos[i][j];
}
sum += (mx*pun[i]);
}
printf("%d\n", sum);
}
//==============================================================================
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 7b6b39d5ac62ac15468fd812e4dc9885 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
int main(){
int n , m;
scanf("%d %d", &n , &m);
char answers[n][m];
getchar();
for(int i = 0;i<n;i++)
{
for(int j = 0;j<m;j++)
{
scanf("%c" , &answers[i][j]);
}
getchar();
}
// for(int i = 0;i < n;i++)
// {
// for(int j = 0;j<m;j++)
// {
// printf("a[%d][%d] is: %c\n" , i , j ,answers[i][j]);
// }
// }
int points[m];
for(int i = 0;i<m;i++)
{
scanf("%d" , &points[i]);
}
int A , B , C , D , E;
A = B = C = D = E = 0;
int max = 0;
int ans = 0;
for(int j = 0 ;j < m;j++)
{
for(int i =0;i<n;i++)
{
// printf("a[%d][%d] = %c" , i , j ,answers[i][j]);
if (answers[i][j] == 'A') A++;
if (answers[i][j] == 'B') B++;
if (answers[i][j] == 'C') C++;
if (answers[i][j] == 'D') D++;
if (answers[i][j] == 'E') E++;
}
if(A > max) max = A;
if(B > max) max = B;
if(C > max) max = C;
if(D > max) max = D;
if(E > max) max = E;
// printf("max = %d\n", max);
ans += max*points[j];
A = B = C = D = E = 0;
max = 0;
}
printf("%d", ans);
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 2b808ab903356bf8d6bf98856a2bd7f4 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
#define MAX 1005
int max(int *p, int len) {
int ret = 0;
for (int i = 0; i < len; i++) {
ret = p[i] > ret ? p[i] : ret;
}
return ret;
}
int main() {
int n, m, weight;
char row[MAX];
int counts[MAX][5] = {0};
long long score = 0;
scanf("%d %d\n", &n, &m);
for (int i = 0; i < n; i++) {
fgets(row, MAX, stdin);
for (int j = 0; j < m; j++) {
counts[j][row[j] - 'A'] += 1;
}
}
for (int p = 0; p < m; p++) {
scanf("%d", &weight);
score += max(counts[p], 5) * weight;
}
printf("%lld\n", score);
return 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | e2f0689ce630971f32ba1dab62a50188 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int maxi(int a, int b, int c)
{
int r;
if(a>b)
{
if(a>c)
r=a;
else
r=c;
}
else
{
if(b>c)
r=b;
else
r=c;
}
return r;
}
int main()
{
int n, m, sum=0, i, j,r, aa, b, c, d, e;
scanf("%d%d", &n, &m);
char s[n+1][m+1];
int a[m];
for(i=0;i<n;i++)
scanf("%s", &s[i]);
for(i=0;i<m;i++)
scanf("%d", &a[i]);
for(i=0;i<m;i++)
{
aa=0, b=0, c=0, d=0, e=0;
for(j=0;j<n;j++)
{
if(s[j][i]=='A')
aa++;
else if(s[j][i]=='B')
b++;
else if(s[j][i]=='C')
c++;
else if(s[j][i]=='D')
d++;
else
e++;
}
r=maxi(aa, b, c);
r=maxi(r,d,e);
sum+=r*a[i];
}
printf("%d\n", sum);
return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 2bba63db8055a0d343fb5fe062d57e12 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int n,m;
int total = 0;
scanf("%d %d",&n,&m);
char str[n][m+1];
int pts[m];
int arr_cnt[5];
for (int i = 0; i < n; ++i)
{
scanf("%s",str[i]);
}
for (int i = 0; i < m; ++i)
{
scanf("%d",&pts[i]);
}
for (int i = 0; i < m; ++i)
{
for (int i = 0; i < 5; ++i)
{
arr_cnt[i] = 0;
}
for (int j = 0; j < n; ++j)
{
if (str[j][i] == 'A')
{
arr_cnt[0] ++;
}
else if (str[j][i] == 'B')
{
arr_cnt[1] ++;
}
else if (str[j][i] == 'C')
{
arr_cnt[2] ++;
}
else if (str[j][i] == 'D')
{
arr_cnt[3] ++;
}
else
{
arr_cnt[4] ++;
}
}
int max = arr_cnt[0];
int index = 0;
for (int k = 0; k < 5; ++k)
{
if (arr_cnt[k]>max)
{
max = arr_cnt[k];
index = k;
}
}
total+= max * pts[i];
// for (int k = 0; k < 5; ++k)
// {
// printf("%d ",arr_cnt[k]);
// }
//printf("\n");
}
printf("%d",total);
return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 1014d9a0e9c6994cf846ff377edc09e9 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
#include <stdlib.h>
int main(void){
int n,m;
int *a,*d;
int i,j;
char **s;
int answer=0;
scanf("%d %d",&n,&m);
s=(char**)calloc(n,sizeof(char*));
a=(int*)calloc(m,sizeof(int));
d=(int*)calloc(n,sizeof(int));
for(i=0;i<n;i++){
s[i]=(char*)calloc(m+1,sizeof(char));
scanf("%s",s[i]);
}
for(i=0;i<m;i++) scanf("%d",&a[i]);
for(i=0;i<m;i++){
int c[5]={0};
int max=0;
for(j=0;j<n;j++) c[s[j][i]-'A']++;
for(j=0;j<5;j++) if(c[j]>max) max=c[j];
answer+=max*a[i];
}
printf("%d\n",answer);
for(i=0;i<n;i++) free(s[i]);
free(s);
free(a);
free(d);
return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 8f18232b48fc6125d1a848b7716cab90 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
void get_marks(char myanswer[],int len , long long int mat[][5])
{
int i;
for(i=0;i<len;i++)
{
mat[i][myanswer[i]-65]++;
}
}
int max_in_row(long long int mat[][5],int row)
{
int i,max=0;
for(i=0;i<5;i++)
{
if(mat[row][max]<mat[row][i])
max=i;
}
return max;
}
int main()
{
int student,question,i ,max;
char myanswer[1000];
long long int sum=0,mat[1000][5]={0},marks[1000];
scanf("%d",&student);
scanf("%d",&question);
for(i=0;i<student;i++)
{
scanf("%s",myanswer);
get_marks(myanswer,question,mat);
}
for(i=0;i<question;i++)
scanf("%I64d",&marks[i]);
for(i=0;i<question;i++)
{
max=max_in_row(mat,i);
sum+=mat[i][max]*marks[i];
}
printf("%I64d",sum);
return 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 46e985046facd941ae88b1d260af9f5e | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
int main()
{
int n, m, i, j, a, b, c, d, e, max; scanf("%d%d",&n,&m);
char s[n][m+1], s1[m+1];
int p[m], ss, sum=0;
for(i=0;i<n;i++)
scanf("%s",s[i]);
for(i=0;i<m;i++)
scanf("%d",&p[i]);
for(j=0;j<m;j++)
{
a=0;b=0;c=0;d=0;e=0; max=0;
for(i=0;i<n;i++)
{
if(s[i][j]=='A') a++;
if(max<a){max=a;s1[j]='A';}
if(s[i][j]=='B') b++;
if(max<b){max=b;s1[j]='B';}
if(s[i][j]=='C') c++;
if(max<c){max=c;s1[j]='C';}
if(s[i][j]=='D') d++;
if(max<d){max=d;s1[j]='D';}
if(s[i][j]=='E') e++;
if(max<e){max=e;s1[j]='E';}
}
}
for(i=0;i<n;i++)
{
ss=0;
for(j=0;j<m;j++)
{
if(s[i][j]==s1[j]) ss+=p[j];
}
sum+=ss;
}
printf("%d",sum);
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | cf9f1c4d2f83ee94a7704cf0177fc9c3 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
long long maxx(long long a,long long b,long long c,long long d,long long e)
{
long long m,n;
if(a>b)
{
if(a>c)
m=a;
else
m=c;
}
else
{
if(b>c)
m=b;
else
m=c;
}
if(d>e)
n=d;
else
n=e;
if(n>m)
return n;
else
return m;
}
int main()
{
int n,m;
long long y,sum=0;
scanf("%d%d",&n,&m);
char ar[n+1][m+1];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
scanf(" %c",&ar[i][j]);
}
long long arr[m],r[5][m];
for(int i=0;i<m;i++)
scanf("%lld",&arr[i]);
for(int i=0;i<m;i++)
{
r[0][i]=0;
r[1][i]=0;
r[2][i]=0;
r[3][i]=0;
r[4][i]=0;
for(int j=0;j<n;j++)
{
if(ar[j][i]=='A')
r[0][i]++;
else if(ar[j][i]=='B')
r[1][i]++;
else if(ar[j][i]=='C')
r[2][i]++;
else if(ar[j][i]=='D')
r[3][i]++;
else if(ar[j][i]=='E')
r[4][i]++;
}
}
for(int i=0;i<m;i++)
{
y=maxx(r[3][i],r[4][i],r[0][i],r[1][i],r[2][i]);
sum+=y*(arr[i]);
//printf("%d ",arr[i]);
}
printf("%lld",sum);
return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 3cc77728a3eb1cc3741fafd77bb82b44 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
int main()
{
int n,m,i,j; unsigned int sum=0;
scanf("%d %d",&n,&m);
int maxscore[1000]={0};
int classify[5][1000]={0};
char answers[n][m];
for(i=0;i<n;i++) scanf("%s",answers[i]);
int scores[m];
for(i=0;i<m;i++) scanf("%d",&scores[i]);
for(i=0;i<n;i++) for(j=0;j<m;j++)
{
switch(answers[i][j])
{
case 'A': { classify[0][j]++; break; }
case 'B': { classify[1][j]++; break; }
case 'C': { classify[2][j]++; break; }
case 'D': { classify[3][j]++; break; }
case 'E': { classify[4][j]++; break; }
default: break;
}
}
for(i=0;i<m;i++) for(j=0;j<5;j++)
{
if(classify[j][i]*scores[i] > maxscore[i])
maxscore[i] = classify[j][i]*scores[i];
}
i=0;
while(i<m)
{
sum += maxscore[i]; i++;
}
printf("%u",sum); return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | b322179b64a1bc6988f18c775e000c3c | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int main(){
int n,m;
scanf("%d%d",&n,&m);
int a[m];
char p[n][m];
int c[m][5];
for(int i = 0;i<n;i++){
int g;
scanf("%c",&g);
for(int j = 0;j<m;j++){
scanf("%c",&p[i][j]);
}
}
for(int i = 0;i<m;i++){
scanf("%d",&a[i]);
c[i][0]=0;
c[i][1]=0;
c[i][2]=0;
c[i][3]=0;
c[i][4]=0;
}
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
c[j][p[i][j]-65]++;
}
}
int s = 0;
for(int i = 0;i<m;i++){
int max = c[i][0];
for(int j = 1;j<5;j++) max = max<c[i][j]?c[i][j]:max;
a[i]*=max;
s+=a[i];
}
printf("%d ",s);
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 9b3bf80e723584aa2c6492280da6ccc4 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int main(){
int n,m,score=0;
scanf("%d %d",&n,&m);
char ch[n][m];
int ar[m];
for (int i=0;i<n;i++)
scanf("%s",ch[i]);
for (int i=0;i<m;i++)
scanf("%d",&ar[i]);
for(int i=0;i<m;i++){
int temp=0;
for(char c='A';c<'F';c++){
//printf("%c\n",c);
int cnt=0;
for(int j=0;j<n;j++){
if(ch[j][i]==c)
cnt++;
//printf("%d\n",cnt);
}
//printf("%d\n",temp);
if(temp<cnt)
temp= cnt;
if(temp==n)
break;
//printf("%d\n",temp);
}
score+=temp*ar[i];
//printf("%d\n",score);
}
printf("%d",score);
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | faab3f2643f18b63d409ac887dab1f63 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
#include <string.h>
char str[1010][1010];
int cnt[1010][5];
int main(){
int n, m, res = 0;
scanf("%d%d", &n, &m);
int a[m];
for(int i = 0; i < n; i++){
scanf("%s", str[i]);
}
for(int i = 0; i < m; i++) scanf("%d", &a[i]);
for(int i = 0; i < m; i++){
int ma = 0;
for(int j = 0; j < n; j++){
cnt[i][str[j][i] - 'A']++;
}
for(int j = 0; j < 5; j++){
if(cnt[i][j] > ma) ma = cnt[i][j];
}
res += ma * a[i];
}
printf("%d\n", res);
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 94de37beeb8fa5583d45a40c93b3bb13 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int main(){
int l,k,i=0,j=0,n,m,ar[10000],h[1000],count=0;
char arr[1000][1000];
scanf("%d %d",&n,&m);
k=n;l=m;
while(k--){
scanf("%s",arr[i]);
i++;
}
i=0;
while(l--){
scanf("%d",&ar[i]);
i++;
}
for(i=0;i<m;i++){
for(j=0;j<n;j++){
char c=arr[j][i];
int x=c-65;
// printf("%d\n",x);
h[x]++;
}
int x =-1;
for(int ll=0;ll<26;ll++){
if(x<h[ll])
x=h[ll];
}
// printf("max%d\n",x);
count=x*ar[i]+count;
for(int ll=0;ll<26;ll++){
h[ll]=0;
}
}
printf("%d\n",count);
return 0;
} | |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 64f5e002e86317bb14f733d7026faa69 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
int main()
{
int n, m, i, j, scr[1111]={0}, cnt[1111]={0}, ans=0;
char inp[1111][1111], c;
scanf("%d%d%*c", &n, &m);
for (i=0; i<n; i++)
{
for (j=0; j<m; j++) scanf("%c", &inp[i][j]);
scanf("%c", &c);
}
for (i=0; i<m; i++) scanf("%d", &scr[i]);
for (j=0; j<m; j++)
{
int a=0, b=0, c=0, d=0, e=0;
for (i=0; i<n; i++)
{
if (inp[i][j]=='A') a++;
if (inp[i][j]=='B') b++;
if (inp[i][j]=='C') c++;
if (inp[i][j]=='D') d++;
if (inp[i][j]=='E') e++;
}
if (cnt[j]<a) cnt[j]=a;
if (cnt[j]<b) cnt[j]=b;
if (cnt[j]<c) cnt[j]=c;
if (cnt[j]<d) cnt[j]=d;
if (cnt[j]<e) cnt[j]=e;
}
for (i=0; i<m; i++) ans+=(scr[i]*cnt[i]);
printf("%d\n", ans);
return 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 905d3ec0659c8dc98bde7beb20892ea8 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<string.h>
int main()
{
int q,i,j,pos,marks,res=0,max,count,st;
scanf("%d%d",&st,&q);
char s[q];
int a[q][5];
for(i=0;i<q;i++)
{
for(j=0;j<=4;j++)
a[i][j]=0;
}
for(i=0;i<st;i++)
{
scanf("%s",s);
count=0;
for(j=0;j<q;j++)
{
int asci=(int)s[j];
pos=asci-65;
a[count][pos]+=1;
count+=1;
}
}
for(i=0;i<q;i++)
{
scanf("%d",&marks);
max=a[i][0];
for(j=0;j<=4;j++)
{
if(a[i][j]>max)
max=a[i][j];
}
res+=marks*max;
}
printf("%d",res);
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 54eaf6a1613b88ede898bafa426a097f | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>
int main()
{
int n,m,i,k,j,a=0,b=0,c=0,d=0,e=0,sum=0;
scanf("%d %d",&n,&m);
int A[m];
char S[n][m];
for(i=0; i<n; i++)
{
scanf("%s",&S[i]);
}
for(i=0; i<m; i++)
{
scanf("%d",&A[i]);
}
for(j=0; j<m; j++)
{
for(i=0; i<n; i++)
{
if(S[i][j]=='A')
{
a++;
}
else if(S[i][j]=='B')
{
b++;
}
else if(S[i][j]=='C')
{
c++;
}
else if(S[i][j]=='D')
{
d++;
}
else if(S[i][j]=='E')
{
e++;
}
}
if(a>=b&&a>=c&&a>=d&&a>=e)
{
k=a;
}
else if(b>=a&&b>=c&&b>=d&&b>=e)
{
k=b;
}
else if(c>=a&&c>=b&&c>=d&&c>=e)
{
k=c;
}
else if(d>=a&&d>=b&&d>=c&&d>=e)
{
k=d;
}
else
{
k=e;
}
sum=sum+A[j]*k;
a=0;
b=0;
c=0;
d=0;
e=0;
}
printf("%d\n",sum);
return 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 1c8d25a49c7f8c5da5a5b813654ccba4 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
int max(int m,char s[][m],int k,int n){
int A[5];
int i;
for(i=0;i<5;i++){
A[i]=0;
}
for(i=0;i<n;i++){
switch(s[i][k]){
case 'A' : A[0]++;
break;
case 'B' : A[1]++;
break;
case 'C' : A[2]++;
break;
case 'D' : A[3]++;
break;
case 'E' : A[4]++;
break;
}
}
int sum=A[0];
for(i=0;i<5;i++){
if(sum<=A[i])
sum=A[i];
}
return sum;
}
int main(){
int n,m;
scanf("%d %d",&n,&m);
char s[n][m];
int i;
for(i=0;i<n;i++){
scanf("%s",s[i]);
}
int a[m];
for(i=0;i<m;i++){
scanf("%d",(a+i));
}
int sum=0;
for(i=0;i<m;i++){
sum+=(a[i]*max(m,s,i,n));
}
printf("%d",sum);
return 0;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | 3fc6031cf442b39ff292007098d2654c | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include <stdio.h>
#include <string.h>
void add(char* s, int a, int num[a][5]);
int max_5(int* table);
int main()
{
int n, m, max_score = 0;
scanf("%d %d\n", &n, &m);
int optimal[1010][5] = {0};
for(int i=0; i<n; i++){
char answers[1010];
scanf("%s\n", answers);
add(answers, m, optimal);
}
int points[1010];
for(int i=0; i<m; i++){
scanf("%d", &points[i]);
}
for(int i=0; i<m; i++){
max_score += max_5(optimal[i]) * points[i];
}
printf("%d\n", max_score);
return 0;
}
void add(char* s, int a, int num[a][5]){
for(int i=0; i<a; i++){
switch (s[i]) {
case 'A':
num[i][0]++;
break;
case 'B':
num[i][1]++;
break;
case 'C':
num[i][2]++;
break;
case 'D':
num[i][3]++;
break;
case 'E':
num[i][4]++;
break;
}
}
}
int max_5(int* table){
int max=0;
for(int i=0; i<5; i++){
max = table[i]>max?table[i]:max;
}
return max;
}
| |
A class of students wrote a multiple-choice test.There are $$$n$$$ students in the class. The test had $$$m$$$ questions, each of them had $$$5$$$ possible answers (A, B, C, D or E). There is exactly one correct answer for each question. The correct answer for question $$$i$$$ worth $$$a_i$$$ points. Incorrect answers are graded with zero points.The students remember what answers they gave on the exam, but they don't know what are the correct answers. They are very optimistic, so they want to know what is the maximum possible total score of all students in the class. | Print a single integer — the maximum possible total score of the class. | C | 2022f53e5a88d5833e133dc3608a122c | fca47401f1d5273b01f728c3e20d9156 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"strings"
] | 1564936500 | ["2 4\nABCD\nABCE\n1 2 3 4", "3 3\nABC\nBCD\nCDE\n5 4 12"] | NoteIn the first example, one of the most optimal test answers is "ABCD", this way the total number of points will be $$$16$$$.In the second example, one of the most optimal test answers is "CCC", this way each question will be answered by exactly one student and the total number of points is $$$5 + 4 + 12 = 21$$$. | PASSED | 900 | standard input | 1 second | The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of students in the class and the number of questions in the test. Each of the next $$$n$$$ lines contains string $$$s_i$$$ ($$$|s_i| = m$$$), describing an answer of the $$$i$$$-th student. The $$$j$$$-th character represents the student answer (A, B, C, D or E) on the $$$j$$$-th question. The last line contains $$$m$$$ integers $$$a_1, a_2, \ldots, a_m$$$ ($$$1 \le a_i \le 1000$$$) — the number of points for the correct answer for every question. | ["16", "21"] | #include<stdio.h>
int main(void)
{
int i,j,n,m,max;
scanf("%d %d",&n,&m);
int array[m],total=0;
char string[n][m+2];
for(i=0;i<n;i++)
scanf("%s",string[i]);
for(i=0;i<m;i++)
scanf("%d",&array[i]);
for(i=0;i<m;i++)
{
int freq[26]={0};
for(j=0,max=0;j<n;j++)
{
freq[string[j][i]-65]++;
if(max<freq[string[j][i]-65])
max=freq[string[j][i]-65];
}
total+=max*array[i];
}
printf("%d\n",total);
}
| |
Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that ). You are given two integers n and k and n closed intervals [li, ri] on OX axis and you have to find: In other words, you should find the sum of the number of integer points in the intersection of any k of the segments. As the answer may be very large, output it modulo 1000000007 (109 + 7).Mike can't solve this problem so he needs your help. You will help him, won't you? | Print one integer number — the answer to Mike's problem modulo 1000000007 (109 + 7) in the only line. | C | 900c85e25d457eb8092624b1d42be2a2 | 94da845ba29fb807c2749365ce31a090 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"geometry",
"combinatorics",
"implementation",
"data structures"
] | 1467822900 | ["3 2\n1 2\n1 3\n2 3", "3 3\n1 3\n1 3\n1 3", "3 1\n1 2\n2 3\n3 4"] | NoteIn the first example: ;;.So the answer is 2 + 1 + 2 = 5. | PASSED | 2,000 | standard input | 3 seconds | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 200 000) — the number of segments and the number of segments in intersection groups respectively. Then n lines follow, the i-th line contains two integers li, ri ( - 109 ≤ li ≤ ri ≤ 109), describing i-th segment bounds. | ["5", "3", "6"] | /* practice with Dukkha */
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define N 200000
#define MD 1000000007
void init_rand() {
struct timeval tv;
gettimeofday(&tv, NULL);
srand(tv.tv_sec ^ tv.tv_usec);
}
int rand_(int n) {
return (rand() * 76543LL + rand()) % n;
}
int compare(const void *a, const void *b) {
int ia = *(int *) a;
int ib = *(int *) b;
return ia == ib ? 0 : ia < ib ? -1 : 1;
}
int ff[N + 1], gg[N + 1];
int x_, y_, d_;
void gcd_(int a, int b) {
if (b == 0) {
d_ = a;
x_ = 1, y_ = 0;
} else {
int tmp;
gcd_(b, a % b);
tmp = x_ - a / b * y_, x_ = y_, y_ = tmp;
}
}
int inv(int a) {
gcd_(a, MD);
if (x_ < 0)
x_ += MD;
return x_;
}
void init(int n) {
int i, f;
for (i = 0, f = 1; i <= n; i++) {
gg[i] = inv(ff[i] = f);
f = (long long) f * (i + 1) % MD;
}
}
int choose(int n, int k) {
return n < k ? 0 : (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}
int main() {
static int aa[N * 2];
int n, k, i, j, l, r, tmp, a, x, x_, y, y_, ans;
init_rand();
scanf("%d%d", &n, &k);
for (i = 0; i < n; i++) {
scanf("%d%d", &l, &r);
aa[i << 1] = l * 2;
aa[i << 1 | 1] = (r + 1) * 2 + 1;
}
for (j = 0; j < n * 2; j++) {
i = rand_(j + 1);
tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
}
qsort(aa, n * 2, sizeof *aa, compare);
init(n);
ans = 0;
x_ = INT_MIN, y_ = 0;
for (i = 0; i < n * 2; ) {
a = aa[i];
if (a % 2 == 0) {
x = a / 2;
y = 1;
} else {
x = (a - 1) / 2;
y = -1;
}
if (x_ != INT_MIN)
ans = (ans + (long long) (x - x_) * choose(y_, k)) % MD;
x_ = x;
while (i < n * 2 && aa[i] == a) {
y_ += y;
i++;
}
}
printf("%d\n", ans);
return 0;
}
| |
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood. King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not. | Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO". | C | d3a0402de1338a1a542a86ac5b484acc | 34184654fb16421248539e7699dd5232 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"number theory",
"math"
] | 1301410800 | ["3\n1 1 1", "6\n1 0 1 1 1 0", "6\n1 0 0 1 0 1"] | null | PASSED | 1,600 | standard input | 0.5 second | The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood. | ["YES", "YES", "NO"] | #include <stdio.h>
int knights[100500], n;
char check(int k) {
int start, j;
if(n / k < 3)
return 0;
for(start = 0; start < k; start++) {
char isHappy = 1;
for(j = start; isHappy && j < n; j += k) {
if(knights[j] == 0) {
isHappy = 0;
}
}
if(isHappy)
return 1;
}
return 0;
}
int main() {
int i, j;
scanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%d", knights + i);
}
for(i = 1; (long long)(i) * i <= n; i++) {
if(n % i)
continue;
if(check(i) || check(n / i)) {
puts("YES");
return 0;
}
}
puts("NO");
return 0;
}
| |
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood. King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not. | Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO". | C | d3a0402de1338a1a542a86ac5b484acc | 4cdcbc5ba9df034c0a0b54aaa6dc116f | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"number theory",
"math"
] | 1301410800 | ["3\n1 1 1", "6\n1 0 1 1 1 0", "6\n1 0 0 1 0 1"] | null | PASSED | 1,600 | standard input | 0.5 second | The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood. | ["YES", "YES", "NO"] | #include<stdio.h>
#include<math.h>
long int n,a[300009];
int check(long int i)
{long int j,cnt=0,k,univ=0;
for(j=0;j<i;j++)
{cnt=0;univ=0;
for(k=j;cnt<n/i;k+=i,cnt++)
{
if(k>n-1)
k-=n;
if(a[k]==0)
{univ=1;break;}
}
if(!univ)
return 1;
}
return 0;
}
int main()
{
long int i,k;
scanf("%ld",&n);long int cans=sqrt(n),cnt=0;
for(i=0;i<n;i++)
scanf("%ld",&a[i]);
for(i=1;i<=cans;i++)
if(n%i==0)
{long int itemp=i;
if((n/i>2 && check(i)) || ( i>2 && check(n/i)))
{
printf("YES\n");return 0;
}
}
printf("NO\n");return 0;
}
| |
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood. King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not. | Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO". | C | d3a0402de1338a1a542a86ac5b484acc | 4735020aabb3b8a855fc0e4dce28c2b2 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"number theory",
"math"
] | 1301410800 | ["3\n1 1 1", "6\n1 0 1 1 1 0", "6\n1 0 0 1 0 1"] | null | PASSED | 1,600 | standard input | 0.5 second | The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood. | ["YES", "YES", "NO"] | #include<stdio.h>
#include<stdlib.h>
int main(void){
int n,*knights,i,j,k,flg;
scanf("%d",&n);
knights=(int *)calloc(n,sizeof(int));
for(i=0;i<n;i++) scanf("%d",knights+i);
for(i=1;i<=n/3;i++){//polygon num
flg=0;
if(n%i!=0){
flg=1;
continue;
}
for(j=0;j<i;j++){//begin from?
flg=0;
for(k=j;k<n;k+=i){
if(knights[k]==0){
flg=1;
break;
}
}
if(flg==0) break;
}
if(flg==0) break;
}
if(flg==0){
puts("YES");
}else{
puts("NO");
}
free(knights);
return 0;
}
| |
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood. King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not. | Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO". | C | d3a0402de1338a1a542a86ac5b484acc | acd0bc48f4bcd05b48e597e20a53a3e8 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"number theory",
"math"
] | 1301410800 | ["3\n1 1 1", "6\n1 0 1 1 1 0", "6\n1 0 0 1 0 1"] | null | PASSED | 1,600 | standard input | 0.5 second | The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood. | ["YES", "YES", "NO"] | #include <stdio.h>
int main()
{
int n, i, j, k;
int a[100000];
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = 3; i <= n; i++) {
if (n % i > 0) continue;
for (j = 0; j < n / i; j++) {
for (k = 0; j + n / i * k < n; k++) {
if (a[j + n / i * k] == 0) break;
}
if (j + n / i * k >= n) {
puts("YES");
return 0;
}
}
}
puts("NO");
return 0;
}
| |
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood. King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not. | Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO". | C | d3a0402de1338a1a542a86ac5b484acc | 35590d85f881c9d28d33b0cbf43eb760 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"number theory",
"math"
] | 1301410800 | ["3\n1 1 1", "6\n1 0 1 1 1 0", "6\n1 0 0 1 0 1"] | null | PASSED | 1,600 | standard input | 0.5 second | The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood. | ["YES", "YES", "NO"] | #include <stdio.h>
#include <stdlib.h>
int n;
int *u;
int deep(int i, int l){
int nb=0;
int j;
int index;
index=(i+l)%n;
j=0;
while (u[(i+l)%n]==1 && nb<n/l){
i+=l;
nb+=1;
j+=1;
}
if (nb==n/l && (i+l)%n==index){
return 1;
}
else{
return 0;
}
}
int main()
{
int i,li;
int exist=0;
scanf("%d",&n);
u=(int *)malloc(n*sizeof(int));
for (i=0;i<n;i++){
scanf("%d",&u[i]);
}
i=0;
while (exist==0 && i<n/3+1){
if (u[i]==1){
li=1;
while (li<n/3+1){
if (u[i+li]==1) {
exist=deep(i,li);
if (exist==1) {
printf("YES");
break;
}
}
li+=1;
}
}
if (i==n/3 && exist==0){
printf("NO");}
i+=1;
}
return 0;
}
| |
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood. King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not. | Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO". | C | d3a0402de1338a1a542a86ac5b484acc | 325c89f7edf061f60bc6b853a2feaf6d | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"number theory",
"math"
] | 1301410800 | ["3\n1 1 1", "6\n1 0 1 1 1 0", "6\n1 0 0 1 0 1"] | null | PASSED | 1,600 | standard input | 0.5 second | The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood. | ["YES", "YES", "NO"] | #include<stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#define MIN(a,b) (a>b?b:a)
int const p=1000000007;
typedef long long ll;
int i,j,n,k,kol,N_nach;
int fl=0;
int flag=0;
ll s,result,min,binom_n;
int mas_del[200]={0},arr[1000000]={0};
ll func_binominal(ll n,ll k)
{
if (k == 0 || n == k)
return 1;
if(k<0)
return 0;
return func_binominal((n-1)%p,(k-1)%p)+func_binominal((n-1)%p,k%p);
}
int gcd (int a, int b) {
if (b == 0)
return a;
else
return gcd (b, a % b);
}
int check(int n)
{
fl=0;
for(k=0;k<N_nach/3;k++)
{
if(flag==1&&fl>=3&&fl==N_nach/n)
{
return 0;
}
if(n<=k)
break;
for(j=k;j<N_nach;j+=n)
{
switch(arr[j])
{
case 0:
flag=0;
fl=0;
break;
case 1:
flag=1;
fl++;
break;
}
if(flag==0)
break;
}
}
return 1;
}
int main()//быстрое возведение в степень
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
N_nach=n;
for(i=0;i<n;i++)
{
if(arr[i]==0)
{
flag=0;
break;
}
else
{
flag=1;
}
}
if(flag==1)
{
printf("YES\n");
return 0;
}
j=0;
for(i=2;i<(n)/3+1;i++)
{
if(n%i==0)
{
mas_del[j]=i;
j++;
}
}
kol=j-1;
flag=0;
for(i=0;i<=kol;++i)
{
if(check(mas_del[i])==0)
{
printf("YES\n");
return 0;
}
if(N_nach/mas_del[i]>=3&&mas_del[i]>=3)
if(check(N_nach/mas_del[i])==0)
{
printf("YES\n");
return 0;
}
}
printf("NO\n");
return 0;
}
| |
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood. King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not. | Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO". | C | d3a0402de1338a1a542a86ac5b484acc | f4e05337667baa97c55a3ffd07b1151a | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"number theory",
"math"
] | 1301410800 | ["3\n1 1 1", "6\n1 0 1 1 1 0", "6\n1 0 0 1 0 1"] | null | PASSED | 1,600 | standard input | 0.5 second | The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood. | ["YES", "YES", "NO"] | #include <stdio.h>
int b[100000];
void solve(int n)
{
int i, j, k;
for (i = 3; i <= n; i ++)
{
if (n % i == 0)
{
for (j = 0; j < n / i; j ++)
{
for (k = j; k < n; k += n / i)
{
if (b[k] == 0)
{
break;
}
}
if (k >= n)
{
printf("YES\n");
return;
}
}
}
}
printf("NO\n");
}
int main()
{
int n, i;
while (scanf("%d", &n) == 1)
{
for (i = 0; i < n; i ++)
{
scanf("%d", &b[i]);
}
solve(n);
}
return 0;
} | |
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood. King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not. | Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO". | C | d3a0402de1338a1a542a86ac5b484acc | 927a60d367f992fb363de1ceadab1e04 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"number theory",
"math"
] | 1301410800 | ["3\n1 1 1", "6\n1 0 1 1 1 0", "6\n1 0 0 1 0 1"] | null | PASSED | 1,600 | standard input | 0.5 second | The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood. | ["YES", "YES", "NO"] | #include <stdio.h>
int v[100000], p[100000];
int main(int argc, char *argv[])
{
int n, k, i, j, l;
scanf("%d", &n);
for(i = 0; i < n; i ++)
scanf("%d", &v[i]);
k = n / 3;
for(i = 1; i <= k; i ++)
if(n % i == 0)
{
l = n / i;
for(j = 0; j < i; j ++)
p[j] = 0;
for(j = 0; j < n; j ++)
p[j % i] += v[j];
for(j = 0; j < i; j ++)
if(p[j] == l)
{
puts("YES");
return 0;
}
}
puts("NO");
return 0;
}
| |
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood. King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not. | Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO". | C | d3a0402de1338a1a542a86ac5b484acc | 193ba7a88175648e4c98ad08f556e7ab | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"number theory",
"math"
] | 1301410800 | ["3\n1 1 1", "6\n1 0 1 1 1 0", "6\n1 0 0 1 0 1"] | null | PASSED | 1,600 | standard input | 0.5 second | The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood. | ["YES", "YES", "NO"] | #include <stdio.h>
int s[100100];
int checker(int l,int d){
int i,k = l/d,answ,z;
for(z=0;z<k;z++){
answ = 1;
for(i=0;i<l;i+=k){ if (!s[i+z]) {answ = 0; break;} }
if (answ) return 1;
}
return 0;
}
/*
* 10
1 1 1 1 0 1 1 1 0 1
*/
int main(){
int n,z,i,d,m=1;
scanf("%d",&n);
z = n/2;
for(i=0;i<n;i++){
scanf("%d",&s[i]);
m = m && s[i];
}
if (m){
printf("YES");
return 0;
}
for(d=3;d<=z;d++)
if (n%d==0)
if (checker(n,d)){
printf("YES");
return 0;
}
printf("NO");
return 0;
}
| |
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood.Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights in a good mood should be located. Otherwise, the next month will bring misfortunes.A convex polygon is regular if all its sides have same length and all his angles are equal. In this problem we consider only regular polygons with at least 3 vertices, i. e. only nondegenerated.On a picture below some examples of such polygons are present. Green points mean knights in a good mood. Red points mean ones in a bad mood. King Arthur knows the knights' moods. Help him find out if the next month will be fortunate or not. | Print "YES" without the quotes if the following month will turn out to be lucky. Otherwise, print "NO". | C | d3a0402de1338a1a542a86ac5b484acc | 3e9984862934888d421564a2f3af6ddc | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"number theory",
"math"
] | 1301410800 | ["3\n1 1 1", "6\n1 0 1 1 1 0", "6\n1 0 0 1 0 1"] | null | PASSED | 1,600 | standard input | 0.5 second | The first line contains number n, which is the number of knights at the round table (3 ≤ n ≤ 105). The second line contains space-separated moods of all the n knights in the order of passing them around the table. "1" means that the knight is in a good mood an "0" means that he is in a bad mood. | ["YES", "YES", "NO"] | #include<stdio.h>
int n,a[100020],z;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",a+i);
for(int i=1;i<=n/3;i++)
if(n%i==0)
{
for(int j=0;j<i;j++)
{
z=1;
for(int k=j;k<n;k+=i)
z&=a[k];
if(z)
{
puts("YES");
return 0;
}
}
}
puts("NO");
return 0;
} | |
Bertown has n junctions and m bidirectional roads. We know that one can get from any junction to any other one by the existing roads. As there were more and more cars in the city, traffic jams started to pose real problems. To deal with them the government decided to make the traffic one-directional on all the roads, thus easing down the traffic. Your task is to determine whether there is a way to make the traffic one-directional so that there still is the possibility to get from any junction to any other one. If the answer is positive, you should also find one of the possible ways to orient the roads. | If there's no solution, print the single number 0. Otherwise, print m lines each containing two integers pi and qi — each road's orientation. That is the traffic flow will move along a one-directional road from junction pi to junction qi. You can print the roads in any order. If there are several solutions to that problem, print any of them. | C | 10dfcd079aaa03070f84f4e5d8f414d7 | d1fbb304c843c4ccfb0cedb953328a97 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"dfs and similar",
"graphs"
] | 1317999600 | ["6 8\n1 2\n2 3\n1 3\n4 5\n4 6\n5 6\n2 4\n3 5", "6 7\n1 2\n2 3\n1 3\n4 5\n4 6\n5 6\n2 4"] | null | PASSED | 2,000 | standard input | 5 seconds | The first line contains two space-separated integers n and m (2 ≤ n ≤ 105, n - 1 ≤ m ≤ 3·105) which represent the number of junctions and the roads in the town correspondingly. Then follow m lines, each containing two numbers which describe the roads in the city. Each road is determined by two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of junctions it connects. It is guaranteed that one can get from any junction to any other one along the existing bidirectional roads. Each road connects different junctions, there is no more than one road between each pair of junctions. | ["1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n4 2\n3 5", "0"] | /* practice with Dukkha */
#include <stdio.h>
#define N 100000
#define M 300000
int min(int a, int b) { return a < b ? a : b; }
int next[1 + M * 2], hh[1 + M * 2];
int link(int l, int h) {
static int l_ = 1;
next[l_] = l;
hh[l_] = h;
return l_++;
}
int ii[M], jj[M];
int ao[N], ta[N], tb[N];
int dfs(int p, int i) {
static int time;
int l, h, j;
ta[i] = tb[i] = ++time;
for (l = ao[i]; l; l = next[l]) {
h = hh[l];
j = i ^ ii[h] ^ jj[h];
if (!ta[j]) {
ii[h] = i, jj[h] = j;
if (dfs(i, j) || tb[j] == ta[j])
return 1;
tb[i] = min(tb[i], tb[j]);
} else if (ta[j] < ta[i] && j != p) {
ii[h] = i, jj[h] = j;
tb[i] = min(tb[i], ta[j]);
}
}
return 0;
}
int main() {
int n, m, h, i, j;
scanf("%d%d", &n, &m);
for (h = 0; h < m; h++) {
scanf("%d%d", &i, &j), i--, j--;
ii[h] = i;
jj[h] = j;
ao[i] = link(ao[i], h);
ao[j] = link(ao[j], h);
}
if (dfs(-1, 0)) {
printf("0\n");
return 0;
}
for (h = 0; h < m; h++)
printf("%d %d\n", ii[h] + 1, jj[h] + 1);
return 0;
}
| |
When Adam gets a rooted tree (connected non-directed graph without cycles), he immediately starts coloring it. More formally, he assigns a color to each edge of the tree so that it meets the following two conditions: There is no vertex that has more than two incident edges painted the same color. For any two vertexes that have incident edges painted the same color (say, c), the path between them consists of the edges of the color c. Not all tree paintings are equally good for Adam. Let's consider the path from some vertex to the root. Let's call the number of distinct colors on this path the cost of the vertex. The cost of the tree's coloring will be the maximum cost among all the vertexes. Help Adam determine the minimum possible cost of painting the tree. Initially, Adam's tree consists of a single vertex that has number one and is the root. In one move Adam adds a new vertex to the already existing one, the new vertex gets the number equal to the minimum positive available integer. After each operation you need to calculate the minimum cost of coloring the resulting tree. | Print n integers — the minimum costs of the tree painting after each addition. | C | dd47f47922a5457f89391beea749242b | 1e4ff50f9e10b8c85b814ebaacdfc4af | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"trees"
] | 1403191800 | ["11\n1 1 1 3 4 4 7 3 7 6 6"] | NoteThe figure below shows one of the possible variants to paint a tree from the sample at the last moment. The cost of the vertexes with numbers 11 and 12 equals 3. | PASSED | 2,600 | standard input | 2 seconds | The first line contains integer n (1 ≤ n ≤ 106) — the number of times a new vertex is added. The second line contains n numbers pi (1 ≤ pi ≤ i) — the numbers of the vertexes to which we add another vertex. | ["1 1 1 1 1 2 2 2 2 2 3"] | #include <stdio.h>
#include <string.h>
#define size 1000001
int max1[size], max2[size], ans[size], parent[size];
void swap(int* i, int*j)
{
int t = *i;
*i = *j;
*j = t;
}
int max(int x, int y)
{
return (x > y) ? x : y;
}
int main(int argc, const char *argv[])
{
int i, n, num = 1, node;
memset(max1, 0, sizeof(max1));
memset(max2, 0, sizeof(max2));
parent[1] = 0;
scanf("%d\n", &n);
for (i = 0; i < n; i++)
{
scanf("%d", parent + (++num));
ans[num] = 1;
node = num;
while (node > 1)
{
int flag = 0;
if (ans[node] > max2[parent[node]])
max2[parent[node]] = ans[node];
if (max2[parent[node]] > max1[parent[node]])
swap(&max1[parent[node]], &max2[parent[node]]);
if (max(max1[parent[node]], max2[parent[node]]+1) >
ans[parent[node]])
{
flag = 1;
ans[parent[node]] = max(max1[parent[node]],
max2[parent[node]]+1);
node = parent[node];
if (max1[1] == max2[1] && node == 1)
ans[1] -= 1;
}
if (!flag)
break;
}
printf("%d ", ans[1]);
}
return 0;
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | fd8dbd00a0e18f395b563c2925c731a0 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include<stdio.h>
int findmax(int a[],int n)
{
int i,max=0;
for(i=1;i<=n;i++)
if(max<a[i])
max=a[i];
return max;
}
int main()
{
int i,j,k,arr[501][501],maximum[501];
int n,m,q,count,a,b;
scanf("%d%d%d",&n,&m,&q);
for(i=1;i<=n;i++){
for(j=1;j<=m;j++)
{scanf("%d",&arr[i][j]);
}
}
int flag,t,max;
for(i=1;i<=n;i++){
t=0;max=0;flag=0;
for(j=1;j<=m;j++){
if(arr[i][j]==1)
{ flag=1;
if(j<m && arr[i][j]==arr[i][j+1])
t++;
}else{
if(flag==1){
t++;
flag=0;
}
if(max<t)
max=t;
t=0;
}
}
if(flag==1){
t++;
flag=0;
}
// printf("%d\n",t);
if(max<t)
max=t;
maximum[i]=max;
}
/* for(i=1;i<=n;i++)
printf("%d ",maximum[i]);
printf("\n");
*/while(q--)
{
scanf("%d%d",&a,&b);
if(arr[a][b]==0){
arr[a][b]=1;
}
else
{arr[a][b]=0;
}
int t=0,max=0,flag=0;
/* for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
printf("%d ",arr[i][j]);
}printf("\n");
}
*/
for(k=1;k<=m;k++){
if(arr[a][k]==1)
{ flag=1;
if(k<m && arr[a][k]==arr[a][k+1])
t++;
}else{
if(flag==1){
t++;
flag=0;
}
if(max<t)
max=t;
t=0;
}
}
if(flag==1){
t++;
flag=0;
}
// printf("%d\n",t);
if(max<t)
max=t;
maximum[a]=max;
/*for(i=1;i<=n;i++)
printf("%d ",maximum[i]);
printf("\n");
*/printf("%d\n",findmax(maximum,n));
}
return 0;
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 1dc5324040ba231bcf5cd0f4d55c90b1 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include <stdio.h>
#include <string.h>
#define max(a, b) (a > b) ? (a) : (b);
int R, C, Q;
int grid[502][502], sum[502];
void init();
int maxConsecutive(int r);
int maxConsecutiveRow(int row);
int main()
{
int i, r, c;
scanf("%d %d %d", &R, &C, &Q);
for(r = 1; r <= R; r++) {
for(c = 1; c <= C; c++) {
scanf("%d", &grid[r][c]);
}
}
init();
for(i = 0; i < Q; i++) {
scanf("%d %d", &r, &c);
grid[r][c] = !(grid[r][c]);
printf("%d\n", maxConsecutiveRow(r));
}
return 0;
}
void init() {
int r;
for(r = 1; r <= R; r++) {
sum[r] = maxConsecutive(r);
}
}
int maxConsecutive(int r) {
int ret = 0, c, cnt;
for(c = 1; c <= C; ) {
if(!grid[r][c]) {
c++;
continue;
}
cnt = 0;
while(grid[r][c]) {
c++;
cnt++;
}
ret = max(ret, cnt);
}
return ret;
}
int maxConsecutiveRow(int row) {
int ret = 0, r, c, cnt, maximum = 0;
sum[row] = maxConsecutive(row);
for(r = 1; r <= R; r++) {
ret = max(ret, sum[r]);
}
return ret;
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 014eaf33b182a5ac7530c5b5aa39a362 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include<stdio.h>
#include<limits.h>
int maxrow;
int maximum(int * k,int n){
int i,max=k[0];
maxrow=1;
for(i=1;i<n;i++){
if(max<k[i]){
max=k[i];
maxrow=i+1;
}
}
return max;
}
int
main ()
{
int n, m, q;
scanf ("%d %d %d", &n, &m, &q);
int max = INT_MIN, i, j, sumrow = 0, max1[n];
int grid[n][m];
for (i = 0; i < n; i++)
{
max1[i]=INT_MIN;
sumrow=0;
for (j = 0; j < m; j++)
{
scanf ("%d", &grid[i][j]);
sumrow += grid[i][j];
if (grid[i][j] == 0)
{
if (max1[i] < sumrow){
max1[i] = sumrow;
}
sumrow = 0;
}
}
if (sumrow>max1[i])
{
max1[i] = sumrow;
}
if (max < max1[i])
{
max = max1[i];
maxrow=i+1;
}
// printf("%d %d %d\n",max1[i],max,maxrow);
}
for(i=0;i<q;i++){
int row,col;
scanf("%d %d",&row,&col);
if(grid[row-1][col-1]==0) grid[row-1][col-1]=1;
else grid[row-1][col-1]=0;
// printf("grid=%d\n",grid[row-1][col-1]);
max1[row-1]=INT_MIN;
sumrow=0;
for(j=0;j<m;j++){
sumrow += grid[row-1][j];
if (grid[row-1][j] == 0)
{
if (max1[row-1] < sumrow){
max1[row-1] = sumrow;
}
sumrow = 0;
}
}
if(sumrow>max1[row-1])
{
max1[row-1]=sumrow;
}
// printf("maxro=%d\n",max1[row-1]);
if(maxrow==row)
{
if(max1[row-1]<max)
max=maximum(max1,n);
else
max=max1[row-1];
}
else{
if(max1[row-1]>max){
max=max1[row-1];
maxrow=row;
}
}
printf("%d\n",max);
}
return 0;
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 580407439debd637c2fb63d24e4f20a8 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include<stdio.h>
int main()
{
int n, m, q;
int a[500][500];
int a_max[500];
int i, j, count, max, ov_max, x, y;
scanf("%d %d %d", &n, &m, &q);
for(i=0; i<n; i++)
{
max = 0;
count = 0;
for(j=0; j<m; j++)
{
scanf("%d", &a[i][j]);
if(a[i][j] == 1)
{
count++;
}
else
{
if(count > max)
max = count;
count = 0;
}
}
if(count > max)
max = count;
a_max[i] = max;
}
ov_max = 0;
for(i=0; i<n; i++)
{
if(a_max[i] > ov_max)
ov_max = a_max[i];
}
while(q--)
{
scanf("%d %d", &x, &y);
x--, y--;
a[x][y] = (a[x][y]+1) % 2;
max = 0;
count = 0;
for(j=0; j<m; j++)
{
if(a[x][j] == 1)
{
count++;
}
else
{
if(count > max)
max = count;
count = 0;
}
}
if(count > max)
max = count;
a_max[x] = max;
ov_max = 0;
for(i=0; i<n; i++)
{
if(a_max[i] > ov_max)
{
ov_max = a_max[i];
}
}
printf("%d\n", ov_max);
}
return 0;
} | |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 07cedcea7c728a928d4ba8a333e58606 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
/* CF305Div2 - B*/
int be[512][512];
int nb[512];
static void
do_bear(int r, int c, int k)
{
int i, j;
int sr, sc;
while (k--) {
int cnt = 0;
int max = 0;
scanf("%d%d", &sr, &sc);
be[sr][sc] ^= 1;
for (i = 1; i <= c; i++) {
if (be[sr][i] == 1) {
++cnt;
} else {
if (cnt > max) {
max = cnt;
}
cnt = 0;
}
}
if (cnt > max) {
max = cnt;
}
nb[sr] = max;
max = 0;
for (i = 1; i <= r; i++) {
if (nb[i] > max) {
max = nb[i];
}
}
printf("%d\n", max);
}
return;
}
int main ()
{
int n, m, k;
int i, j;
scanf ("%d%d%d", &n, &m, &k);
for (i = 1; i <= n; i++) {
int cnt = 0;
int max = 0;
for (j = 1; j <= m; j++) {
scanf("%d", &be[i][j]);
if (be[i][j] == 1) {
++cnt;
} else {
if (cnt > max) {
max = cnt;
}
cnt = 0;
}
}
if (cnt > max) {
max = cnt;
}
nb[i] = max;
}
do_bear (n, m, k);
return 0;
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | fca0a8315651405ae0b1c0bc90b165ff | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include<stdio.h>
int main() {
int n, m, q, M[500][500], A[500], i, j, x, y, rmax, max ,Max;
scanf("%d %d %d", &n, &m, &q);
for(i = 0; i < n; i++) {
rmax = max = 0;
for(j = 0; j < m; j++) {
scanf("%d", &M[i][j]);
if(M[i][j]) {
max++;
} else {
max = 0;
}
if(max > rmax) {
rmax = max;
}
}
A[i] = rmax;
}
for(i = 0; i < q; i++) {
scanf("%d %d", &x, &y);
if(M[x - 1][y - 1]) {
M[x - 1][y - 1] = 0;
} else {
M[x - 1][y - 1] = 1;
}
rmax = max = 0;
for(j = 0; j < m; j++) {
if(M[x - 1][j]) {
max++;
} else {
max = 0;
}
if(max > rmax) {
rmax = max;
}
}
A[x - 1] = rmax;
Max = -1;
for(j = 0; j < n; j++) {
if(A[j] > Max) {
Max = A[j];
}
}
printf("%d\n", Max);
}
return 0;
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | d487b0846c0fab55b995f4bb24279783 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include<stdio.h>
int main()
{
int n,m,q,temp,len,len1,row,i,j,i1,j1,a,rows;
scanf("%d %d %d",&n,&m,&q);
int arr[n+2][m+3];
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
scanf("%d",&arr[i][j]);
}
}
for(a=0; a<q; a++)
{
scanf("%d %d",&i1,&j1);
if(arr[i1][j1]==0)
arr[i1][j1]=1;
else
arr[i1][j1]=0;
rows=-1;
for(i=1; i<=n; i++)
{
temp=0; len1=-1;
for(j=1; j<=m; j++)
{
//printf("value of array %d\n",arr[i][j]);
if (arr[i][j]==1)
temp++;
else
temp = 0;
if (temp>len1)
len1=temp;
}
if(len1>rows)
rows=len1;
//printf("valur of row %d\n",rows);
}
printf("%d\n",rows);
}
return 0;
} | |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 343bb78d709ee0efcd670f9c75177bb7 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include<stdio.h>
#include<math.h>
int aray[510][510];
int m;
int func(int n)
{
int i, j ,sum=0, hold=0, n0=0;
if(m<=2){
if(m==1 && aray[n][0]==0){
return 0;
}
else if(m==1 && aray[n][0]==1){
return 1;
}
else{
if(aray[n][0]==1 && aray[n][1]==1){
return 2;
}
else if(aray[n][0]==0 && aray[n][1]==0){
return 0;
}
else{
return 1;
}
}
}
for(i=0;i<m;i++){
if(aray[n][i]==1 && aray[n][i+1]==1){
sum++;
if(aray[n][i+2]==0 || i+2==m){
sum++;
if(hold<sum){
hold = sum;
}
sum=0;
}
}
}
for(i=0;i<m;i++){
if(aray[n][i]==0){
n0++;
}
}
if(m-n0==1){
return 1;
}
return hold;
}
int main()
{
int n, q, i, j, a, b, c, high=0, x, y;
scanf("%d %d %d", &n, &m, &q);
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%d", &aray[i][j]);
}
aray[i][j]=func(i);
}
for(i=0;i<q;i++){
high=0;
scanf("%d %d", &a, &b);
if(aray[a-1][b-1]==0){
aray[a-1][b-1]=1;
}
else{
aray[a-1][b-1] = 0;
}
aray[a-1][m] = func(a-1);
/*for(x=0;x<n;x++){
for(y=0;y<=m;y++){
printf("%d ", aray[x][y]);
}
printf("\n");
}*/
for(c=0;c<n;c++){
if(aray[c][m]>=high){
high = aray[c][m];
}
}
printf("%d \n", high);
}
return 0;
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 37e0494db0ae755c7cffc84b57382299 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include <stdio.h>
int main (void) {
int atto[501][502];
int a, b, c;
int t1,t2;
int k1, k2;
int j1,j2,nit,pib;
scanf("%d %d %d", &a , &b, &c);
for(t1=1; t1<=a; t1++) {
for(t2=1; t2<=b; t2++) {
scanf("%d", &atto[t1][t2]);
}
}
for(t2=1; t2<=a; t2++) atto[t2][501]=0;
for(t1=1,j2=0; t1<=a; t1++) {
for(t2=1,j1=0,pib=0; t2<=b; t2++) {
nit=atto[t1][t2];
if(nit) j1++;
else j1=0;
if(j1>pib) pib=j1;
atto[t1][501]=pib;
}
}
for( ; c ; c--) {
scanf("%d %d", &k1, &k2);
if(atto[k1][k2]==0) atto[k1][k2]=1;
else if(atto[k1][k2]==1) atto[k1][k2] = 0;
for(t2=1,j1=0,pib=0; t2<=b; t2++) {
nit=atto[k1][t2];
if(nit) j1++;
else j1=0;
if(j1>pib) pib=j1;
atto[k1][501]=pib;
}
for(t1=1, j2=0; t1<=a; t1++) {
if(atto[t1][501]>j2) j2=atto[t1][501];
}
printf("%d\n", j2);
}
return 0;
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 60c811bf4b9ace46aa1defb6111fbc78 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include<stdio.h>
int a[500][500]={0};
int n,m,q;
void printmax(void){
int i,j,k,max=0;
for(i=0;i<n;i++){
for(j=0,k=0;j<m;j++){
if(a[i][j]==1)
k+=a[i][j];
else
k=0;
if(k>=max)
max=k;
}
}
printf("%d\n",max);
return;
}
int main(void){
int i,j,k;
scanf("%d %d %d",&n,&m,&q);
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%d",&a[i][j]);
}
}
for(i=0;i<q;i++){
scanf("%d %d",&j,&k);
if(a[j-1][k-1]==1)
a[j-1][k-1]=0;
else
a[j-1][k-1]=1;
printmax();
}
return 0;
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 40709b6a8af0eab852d729438ec53800 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
typedef long long ll;
int n,m,q;
bool a[500][500];
int ans[500];
int get(int r)
{
int i,j=0,k=0;
for(i=0;i<m;i++)
{
if(a[r][i])j++;
else
{
j=0;
}
if(j>k)k=j;
}
return k;
}
int max()
{
int i,j=0;
for(i=0;i<n;i++)if(ans[i]>j)j=ans[i];
return j;
}
int main(void) {
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
//int tt; scanf("%d",&tt);
//while(tt--)
{
scanf("%d%d%d",&n,&m,&q);
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<n;i++)
ans[i]=get(i);
int x,y;
while(q--)
{
scanf("%d%d",&x,&y);
--x;--y;
a[x][y]=!a[x][y];
ans[x]=get(x);
//for(i=0;i<n;i++)for(puts(""),j=0;j<m;j++)printf("%d ",a[i][j]);
printf("%d\n",max());
}
}//while for test cases
return 0;
} | |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 7ecfb863793d62f8ec3b4b01e9970de6 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int m, n, q, i, j, mmax = 0, x, y, ans;
scanf("%d %d %d", &n, &m, &q);
int arr[n][m], max[n];
for (i = 0; i < n; i++){
max[i] = 0; ans = 0;
for (j = 0; j < m; j++){
scanf("%d", &arr[i][j]);
if (arr[i][j]) ans++;
else ans = 0;
if (ans > max[i]) max[i] = ans;
}
}
while (q--){
scanf("%d %d", &x, &y);
if (arr[x-1][y-1]) arr[x-1][y-1] = 0;
else arr[x-1][y-1] = 1;
ans = 0; max[x-1] = 0;
for (j = 0; j < m; j++){
if (arr[x-1][j]) ans++;
else ans = 0;
if (ans > max[x-1]) max[x-1] = ans;
}
mmax = 0; ans = 0;
for (i = 0; i < n; i++){
if (mmax < max[i]) mmax = max[i];
}
printf("%d\n", mmax);
}
return 0;
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | bd14a191f6a876ef4dad9479cd9d1ba0 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include<stdio.h>
int main()
{
int n,m,q,temp,len,len1,row,i,j,i1,j1,a,rows;
scanf("%d %d %d",&n,&m,&q);
int arr[n+2][m+3];
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
scanf("%d",&arr[i][j]);
}
}
for(a=0; a<q; a++)
{
scanf("%d %d",&i1,&j1);
if(arr[i1][j1]==0)
arr[i1][j1]=1;
else
arr[i1][j1]=0;
rows=-1;
for(i=1; i<=n; i++)
{
temp=0; len1=-1;
for(j=1; j<=m; j++)
{
//printf("value of array %d\n",arr[i][j]);
if (arr[i][j]==1)
temp++;
else
temp = 0;
if (temp>len1)
len1=temp;
}
if(len1>rows)
rows=len1;
//printf("valur of row %d\n",rows);
}
printf("%d\n",rows);
}
return 0;
} | |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 35b1c89d8601853deceda75821ada590 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include<stdio.h>
int a[500][502];
int check(x,m)
{
int count=0,max=0,i;
for(i=0;i<m;i++)
{
if(a[x][i]==1)
{
while(a[x][i]==1)
{
count++;
i++;
}
if(count>max)
max=count;
count=0;
}
}
return max;
}
int main()
{
int n,m,q,i,j,max,x,y,count,ans;
scanf("%d%d%d",&n,&m,&q);
int p[n];;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<n;i++)
{
p[i]=0;
count=0;
for(j=0;j<m;j++)
{
if(a[i][j]==1)
{
while(a[i][j]==1)
{
count++;
j++;
}
if(count>p[i])
p[i]=count;
count=0;
}
}
}
for(i=0;i<q;i++)
{
scanf("%d%d",&x,&y);
if(a[x-1][y-1]==1)
a[x-1][y-1]=0;
else
a[x-1][y-1]=1;
p[x-1]=check(x-1,m);
ans=p[0];
for(j=1;j<n;j++)
{
if(p[j]>ans)
ans=p[j];
}
printf("%d\n",ans);
}
} | |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 2623d37b32ca5978622faa2e0a291bdf | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include <stdio.h>
#include <string.h>
int main()
{
int a,b,c,d,e,f,i,j,k,p=0,q=0,r,count=0,max=0,count1=0,max1=0;
int x[502][502],y[502];
scanf("%d %d %d",&a,&b,&c);
for(i=0;i<502;i++)
{
y[i]=0;
}
for(i=0;i<a;i++)
{
count=0;
for(j=0;j<b;j++)
{
scanf("%d",&x[i][j]);
if(x[i][j]==1)
{
count++;
if(j==b-1)
{
if(count>=y[i])
{
y[i]=count;
}
}
}
if(x[i][j]==0)
{
if(count>=y[i])
{
y[i]=count;
}
count=0;
}
}}
for(i=0;i<c;i++)
{
count1=0;
p=0;
max=0;
scanf("%d %d",&e,&f);
e=e-1;
f=f-1;
if(x[e][f]==0)
{x[e][f]=1;}
else if(x[e][f]==1)
{
x[e][f]=0;
}
for(j=0;j<b;j++)
{
if(x[e][j]==1)
{
count1++;
if(j==b-1)
{
if(count1>=p)
{ p=count1;
y[e]=count1;
}
}
}
else if(x[e][j]==0)
{ if(count1>=p)
{ p=count1;
y[e]=count1;
}
count1=0;
}}
for(k=0;k<a;k++)
{
if(y[k]>=max)
{
max=y[k];
}
}
printf("%d\n",max);
}
return 0;} | |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 50dab3f595459c43c79c69c9936cc414 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include<stdio.h>
#include<string.h>
#define N 550
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int n,m,q;
int i,y,t;
int maxn;
int map[N][N];
int ans[N];
//freopen("in.txt","r",stdin);
scanf("%d%d%d",&n,&m,&q);
memset(ans,0,sizeof(ans));
for(i=1;i<=n;i++)
{
t=0;
for(y=1;y<=m;y++)
{
scanf("%d",&map[i][y]);
if(map[i][y])
t++;
else
t=0;
ans[i]=max(ans[i],t);
}
}
while(q--)
{
scanf("%d%d",&i,&y);
map[i][y]=!map[i][y];
t=0;maxn=0;
for(y=1;y<=m;y++)
{
if(map[i][y])
t++;
else
t=0;
maxn=max(maxn,t);
}
ans[i]=maxn;
maxn=0;
for(i=1;i<=n;i++)
maxn=max(maxn,ans[i]);
printf("%d\n",maxn);
}
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 46ac3e8698c06f3db7b2cd5ceea4c11a | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include<stdio.h>
int main()
{
int i,j,n,m,q,a[510][510],c1,c2,k;
long long int max=0,sum[510],tsum=0;
scanf("%d%d%d",&n,&m,&q);
for(i=1;i<=n;i++)
{
sum[i]=0;
tsum=0;
for(j=1;j<=m;j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]==0)
{
if(sum[i]<tsum)
sum[i]=tsum;
tsum=0;
}
else
tsum++;
}
if(sum[i]<tsum)
sum[i]=tsum;
if(max<sum[i])
max=sum[i];
}
for(i=0;i<q;i++)
{
scanf("%d%d",&c1,&c2);
a[c1][c2]=1-a[c1][c2];
sum[c1]=0;
tsum=0;
for(k=1;k<=m;k++)
{
if(a[c1][k]==0)
{
if(sum[c1]<tsum)
sum[c1]=tsum;
tsum=0;
}
else
tsum++;
}
if(sum[c1]<tsum)
sum[c1]=tsum;
if(max<sum[c1])
max=sum[c1];
else
{
max=0;
for(j=1;j<=n;j++)
if(max<sum[j])
max=sum[j];
}
printf("%lld\n",max);
}
return 0;
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 91a027005f19881963fbf3a021af1b76 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include<stdio.h>
int main()
{
int a[500][500],m,n,i,j,q,max,k,l,p,r;
int b[500]={};
scanf("%d%d%d",&m,&n,&q);
p=n;
r=m;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(i=0;i<m;i++)
{
l=0;
k=0;
for(j=0;j<n;j++)
{
if(k==0&&a[i][j]==1)
k++;
else if(a[i][j]==1&&a[i][j-1]==1)
k++;
else if(a[i][j]==0)
{
if(l<k)
l=k;
k=0;
}
}
if(l<k)
l=k;
b[i]=l;
}
for(i=0;i<q;i++)
{
scanf("%d%d",&m,&n);
if(a[m-1][n-1]==0)
a[m-1][n-1]=1;
else
a[m-1][n-1]=0;
k=0;
l=0;
for(j=0;j<p;j++)
{
if(k==0&&a[m-1][j]==1)
k++;
else if(a[m-1][j]==1&&a[m-1][j-1]==1)
k++;
else if(a[m-1][j]==0)
{
if(l<k)
l=k;
k=0;
}
}
if(l<k)
l=k;
b[m-1]=l;
max=0;
for(j=0;j<r;j++)
if(max<b[j])
max=b[j];
printf("%d\n",max);
}
return 0;
}
| |
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes. They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round. | After each round, print the current score of the bears. | C | 337b6d2a11a25ef917809e6409f8edef | 5698e830f2fd54922357a47e4fd48ae7 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"implementation",
"greedy",
"brute force"
] | 1432658100 | ["5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3"] | null | PASSED | 1,400 | standard input | 2 seconds | The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state. | ["3\n4\n3\n3\n4"] | #include <stdio.h>
int findmax(int *a,int n)
{
int i;
int max=0;
for (i=0;i<n;i++)
{
if (a[i]>max)
{
max = a[i];
}
}
return max;
}
int main()
{
int n,m,q;
scanf("%d %d %d",&n,&m,&q);
int grid[n][m];
int ans[n];
int i,j;
for (i=0;i<n;i++)
{
int max=0;
for (j=0;j<m;j++)
{
scanf("%d",&grid[i][j]);
if (j>0 && grid[i][j]==1)
{
grid[i][j]=grid[i][j-1]+1;
}
if (grid[i][j]>max)
{
max = grid[i][j];
}
}
ans[i]=max;
}
for (i=0;i<q;i++)
{
int x,y;
scanf("%d %d",&x,&y);
x = x-1;
y = y-1;
if (grid[x][y]>=1)
{
int max=0;
grid[x][y]=0;
for (j=y+1;j<m;j++)
{
if (grid[x][j]>=1)
{
grid[x][j] = grid[x][j-1]+1;
}
if (grid[x][j]>max)
{
max=grid[x][j];
}
}
for (j=0;j<y+1;j++)
{
if (grid[x][j]>max)
{
max = grid[x][j];
}
}
ans[x]=max;
}
else
{
if (y==0)
{
grid[x][y]=1;
}
else
{
grid[x][y] = grid[x][y-1]+1;
}
int max=0;
for (j=y+1;j<m;j++)
{
if (grid[x][j]>=1)
{
grid[x][j] = grid[x][j-1]+1;
}
if (grid[x][j]>max)
{
max=grid[x][j];
}
}
for (j=0;j<y+1;j++)
{
if (grid[x][j]>max)
{
max = grid[x][j];
}
}
ans[x]=max;
}
printf("%d\n",findmax(ans,n));
}
return 0;
} | |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | d38094efa6e73e6c5c7f16dfb0ba3f9c | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
scanf("%d",&n);
int arr[n];int ctr1=0,ctr2=0;
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);int temp1=0,temp2=0;
for(int i=0;i<n;i++){
if(arr[i]==0)
ctr1++;
else
ctr2++;
}
for(int i=0;i<n;i++)
{
if(arr[i]==0)
temp1++;
else
temp2++;
if(temp1==ctr1||temp2==ctr2)
{printf("%d",(i+1));
break;}
}
return 0;
}
| |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | 16143100bc2085afc932f6b867069a6a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include<stdio.h>
int main()
{
int n;
scanf("%d", &n);
int a[n], x[2]={0}, y[2]={0}, c=0;
int i=0;
for(i=0;i<n;i++)
scanf("%d", &a[i]);
for(i=0;i<n;i++)
x[a[i]]++;
for(i=0;i<n;i++)
{
y[a[i]]++;
c++;
if(x[0]==y[0] || x[1]==y[1]) break;
}
printf("%d", c);
return 0;
} | |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | ba1085ab2b7f3a13f9aded16e4cf7791 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include<stdio.h>
int main()
{
int i,n,c=0,d=0,nzf[200001],l=0,r=0;
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d",&nzf[i]);
if(nzf[i]==0)
c++;
else if(nzf[i]==1)
d++;
}
for(i=0; i<n; i++)
{
if(nzf[i]==0)
{
l++;
if(l==c)
{
printf("%d ",i+1);
break;
}
}
else if(nzf[i]==1)
{
r++;
if(r==d)
{
printf("%d",i+1);
break;
}
}
}
return 0;
}
| |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | 00ba609363f1adf9583d8c04f9d22c54 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include<stdio.h>
int a[200002];
int main()
{
int i,j,m,n,b=0,c=0;
scanf("%d",&m);
for(i=1;i<=m;i++){
scanf("%d",&a[i]);
if(a[i]==1){
c=i;
}else{
b=i;
}
}
if(b<=c){
printf("%d",b);
}else{
printf("%d",c);
}
return 0;
}
| |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | ab8a2953ee349d8694e3bd4ae41b4c00 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include<stdio.h>
int main()
{
int n,c=0,k=0,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]==0)
{
c=i+1;
}
else if(a[i]==1)
{
k=i+1;
}
}
if(c<k)
printf("%d\n",c);
else
printf("%d\n",k);
return 0;
}
| |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | a047c49902474a11a745fc49162d8228 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include <stdio.h>
#include <stdlib.h>
#define min(a, b) (((a) < (b)) ? (a) : (b))
int main()
{
int a = 0, b = 0, la = 0, lb = 0, i = 0, n, x;
scanf("%d", &n);
for (; i < n; i++)
{
scanf("%d", &x);
if (x == 0) a++, la = i+1;
else b++, lb=i+1;
}
printf("%d\n", min(la, lb));
return 0;
}
| |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | 06b939ba3bf33930699548171e0a7124 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include <stdio.h>
int main(void)
{
int a[200010];
int n, i;
scanf("%d", &n);
for(i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
}
for(i = n-1; i > 0; i--)
{
if(a[i] != a[i+1])
{
printf("%d\n", i);
break;
}
}
return 0;
} | |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | fe9939168352ed6b8003f23885c1c16a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include <stdio.h>
int main()
{
int n, i, num0i, num1i, a;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
scanf("%d", &a);
if (a == 0) num0i = i;
else num1i = i;
}
if (num1i > num0i) num1i = num0i;
printf("%d\n", num1i);
return 0;
}
| |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | 9c982eab7826ae4aa6890f5ff253b4dc | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include<stdio.h>
int main()
{
int t,i,l=0,r=0,x;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
int n;
scanf("%d",&n);
if(n==1)
{
l=i;
}
else
{
r=i;
}
}
x=(l<r)?l:r;
printf("%d\n",x);
return 0;
}
| |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | 644cbc5ca7d725662222258e137e1e39 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include <stdio.h>
int main(void)
{
long long int n,i,j,k,tcount1=0,tcount2=0,count1=0,count2=0;
scanf("%lld",&n);
int array[n+1];
for(i=0;i<n;i++)
{
scanf("%d",&array[i]);
if(array[i]==0)
count1++;
else
count2++;
}
for(i=0;i<n;i++)
{
if(array[i]==0)
tcount1++;
if(tcount1==count1)
{
printf("%lld",i+1);
break;
}
if(array[i]==1)
tcount2++;
if(tcount2==count2)
{
printf("%lld",i+1);
break;
}
}
return 0;
}
| |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | 2e376c1a0ef1d8b69d4516f764233b7e | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
int num,i,count1=0,count0=0,tmp,arr[200000],count1_2=0,count0_2=0;
scanf("%d",&num);
for(i=0;i<num;i++)
{
scanf("%d",&tmp);
arr[i]=tmp;
if(tmp==1)
count1++;
else
count0++;
}
for(i=0;i<num;i++)
{
if(arr[i]==1)
count1_2++;
else
count0_2++;
if(count1_2==count1)
{
printf("%d",i+1);
break;
}
if(count0_2==count0)
{
printf("%d",i+1);
break;
}
}
} | |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | d3984914b59d8796542211e6c33196c1 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[n],i,j,x[2]={0},y[2]={0},c=0,c0=0,c1=0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
x[a[i]]++;
for(i=0;i<n;i++)
{
c++;
y[a[i]]++;
if(y[0]==x[0]||y[1]==x[1]) break;
}
printf("%d",c);
return 0;
}
| |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | f1c14e0a6a2f845a125dded92b7fca33 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include <stdio.h>
int main(void) {
// your code goes here
int n,x,a=0,b=0,y=0,z=0,i;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&x);
if(x==0)
{
a++;
y=i;
}
else
{
z=i;
}
}
if(y<z)
printf("%d",y+1);
else
printf("%d",z+1);
return 0;
}
| |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | 012d4df0832dc1f1b96f837d7d2837ac | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include <stdio.h>
int main ()
{
int n;
int i,left=0,right=0;
int ara[200000];
scanf ("%d",&n);
for (i=0;i<n;i++)
{
scanf ("%d",&ara[i]);
if (ara[i]==0)
left++;
else
right++;
}
for (i=0;i<n;i++)
{
if (ara[i]==0)
{
left--;
}
else
right--;
if (left==0||right==0)
{
printf ("%d",i+1);
break;
}
}
return 0;
}
| |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | c25404f2606dad50ca9910f729de51e1 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include<stdio.h>
int main(void)
{
int i,j,n,left=0,right=0;
scanf("%d",&n);
int array[n],left1=0,right1=0;
for(i=0;i<n;i++)
{
scanf("%d",&array[i]);
if(array[i]==0)
left++;
else
right++;
}
for(i=0;i<n;i++)
{
if(array[i]==0)
left1++;
else
right1++;
if(left1==left||right1==right)
break;
}
printf("%d\n",i+1);
return 0;
}
| |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | e59d5da2091b73c7a3d788a4be56fb27 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include <stdio.h>
int doors, eachdoor[200001];
int main ()
{
//freopen ("cf.in","r",stdin),freopen ("cf.out","w",stdout);
scanf ("%d",&doors);
for (int i=0;i<doors;i++)
{
scanf ("%d",&eachdoor[i]);
}
for (int i=doors-1;i>=0;i--)
{
if (eachdoor[doors-1]==0)
{
if (eachdoor[i]==1)
{
printf ("%d\n",i+1);
break;
}
}
else
{
if (eachdoor[i]==0)
{
printf ("%d\n",i+1);
break;
}
}
}
} | |
Three years have passes and nothing changed. It is still raining in London, and Mr. Black has to close all the doors in his home in order to not be flooded. Once, however, Mr. Black became so nervous that he opened one door, then another, then one more and so on until he opened all the doors in his house.There are exactly two exits from Mr. Black's house, let's name them left and right exits. There are several doors in each of the exits, so each door in Mr. Black's house is located either in the left or in the right exit. You know where each door is located. Initially all the doors are closed. Mr. Black can exit the house if and only if all doors in at least one of the exits is open. You are given a sequence in which Mr. Black opened the doors, please find the smallest index $$$k$$$ such that Mr. Black can exit the house after opening the first $$$k$$$ doors.We have to note that Mr. Black opened each door at most once, and in the end all doors became open. | Print the smallest integer $$$k$$$ such that after Mr. Black opened the first $$$k$$$ doors, he was able to exit the house. | C | 653455bb6762effbf7358d75660a7689 | 19832ebc822d43340e07b63d82fdd3d3 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1553965800 | ["5\n0 0 1 0 0", "4\n1 0 0 1"] | NoteIn the first example the first two doors are from the left exit, so when Mr. Black opened both of them only, there were two more closed door in the left exit and one closed door in the right exit. So Mr. Black wasn't able to exit at that moment.When he opened the third door, all doors from the right exit became open, so Mr. Black was able to exit the house.In the second example when the first two doors were opened, there was open closed door in each of the exit.With three doors opened Mr. Black was able to use the left exit. | PASSED | 800 | standard input | 1 second | The first line contains integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of doors. The next line contains $$$n$$$ integers: the sequence in which Mr. Black opened the doors. The $$$i$$$-th of these integers is equal to $$$0$$$ in case the $$$i$$$-th opened door is located in the left exit, and it is equal to $$$1$$$ in case it is in the right exit. It is guaranteed that there is at least one door located in the left exit and there is at least one door located in the right exit. | ["3", "3"] | #include<stdio.h>
int check(int l,int m){
if(l==0 || m==0)
return 1;
else
return 0;
}
int main() {
int n,x,j;
scanf("%d",&n);
int a[n],c1=0,c2=0,s1=0;
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
if(a[i]==0)
c1++;
else if(a[i]==1)
c2++;
}
for( j=0;j<n;j++){
if(a[j]==0){
c1--;
x= check(c1,c2);
if(x==1)
break;
}
else{
c2--;
x= check(c1,c2);
if(x==1)
break;
}
}
printf("%d",j+1);
} | |
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | C | 9a56288d8bd4e4e7ef3329e102f745a5 | 7af2e9df33b6e20304d8f24f5383a662 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"sortings",
"greedy"
] | 1286802000 | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | ["8", "7"] | #include<stdio.h>
#include<stdlib.h>
int com(void const *a,void const *b)
{
return *(int*)b-*(int *)a;
}
int main(void)
{
int n,m,i,c=0,s=0;
scanf("%d %d",&n,&m);
int a[n],b[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]<0) b[c++]=-a[i];
}
qsort(b,c,4,com);
if(c<m) for(i=0;i<c;i++) s+=b[i];
else for(i=0;i<m;i++) s+=b[i];
printf("%d",s);
return 0;
} | |
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | C | 9a56288d8bd4e4e7ef3329e102f745a5 | 0aa46b9eec537b92165e7367d11c8552 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"sortings",
"greedy"
] | 1286802000 | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | ["8", "7"] | #include <stdio.h>
#include <stdlib.h>
int main(){
int TVatSale, TVBOB, i, j, swap, sum=0;
scanf ("%d %d", &TVatSale, &TVBOB);
int money[TVatSale];
for (i=0; i<(TVatSale) ; i++){
scanf("%d", &money[i]);
}
for (j=0; j<(TVatSale-1); j++){
for (i=0; i<(TVatSale-1); i++){
if (money[i+1]<money[i]){
swap = money[i];
money[i]= money[i+1];
money[i+1] = swap;
}
}
}
for (i=0; i<(TVBOB); i++){
if (money[i]<0)
sum += (-1*money[i]);
}
printf ("%d", sum);
return 0;
}
| |
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | C | 9a56288d8bd4e4e7ef3329e102f745a5 | 43670fd2dfde3601bb0d7efc280d8009 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"sortings",
"greedy"
] | 1286802000 | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | ["8", "7"] | #include<stdio.h>
int main()
{
int n,m;
scanf("%d %d",&n,&m);
int a[n];
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
int count=0;
for(int i=0;(a[i]<=0 && i<m);i++)
{
count+=abs(a[i]);
}
printf("%d",count);
}
| |
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | C | 9a56288d8bd4e4e7ef3329e102f745a5 | f9fb603a75363ccf056477c06da4744a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"sortings",
"greedy"
] | 1286802000 | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | ["8", "7"] | #include "stdio.h"
#define MAX_SET_SIZE 100
#define BASE "%d"
typedef int Base;
void BubbleSort(Base *Array, Base Size)
{
Base tmp = 0;
for (Base i = 0; i < Size; i++)
{
for (Base j = 1; j < Size; j++)
{
if (Array[j] < Array[j - 1])
{
tmp = Array[j];
Array[j] = Array[j - 1];
Array[j - 1] = tmp;
}
}
}
return;
}
int main()
{
Base Amount = 0;
Base Strength = 0;
Base Money = 0;
Base Sets[MAX_SET_SIZE];
scanf(BASE BASE, &Amount, &Strength);
for (Base i = 0; i < Amount; i++)
{
scanf(BASE, &Sets[i]);
}
BubbleSort(Sets, Amount);
for (Base i = 0; i < Strength; i++)
{
if (Sets[i] > 0)
{
break;
}
Money -= Sets[i];
}
printf(BASE"\n", Money);
return 0;
}
| |
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | C | 9a56288d8bd4e4e7ef3329e102f745a5 | 386d0a1e178bc2594ee30302b08b5188 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"sortings",
"greedy"
] | 1286802000 | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | ["8", "7"] | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int n, m;
scanf("%d%d", &n, &m);
int i = 0, ara[n];
while(n--)
{
int temp;
scanf("%d", &temp);
if(temp < 0)
{
ara[i] = temp;
i++;
}
}
int sum = 0;
int size = i;
if(size <= m)
{
for(i = 0; i < size; i++)
sum += ara[i];
printf("%d\n", abs(sum));
return 0;
}
for(i = 0; i < m; i++)
{
int min_index = 0, j;
for(j = 1; j < size; j++)
{
if(ara[j] < ara[min_index])
min_index = j;
}
sum += ara[min_index];
ara[min_index] = 0;
}
printf("%d\n", abs(sum));
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.