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
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit?
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
C
ddc9201725e30297a5fc83f4eed75fc9
08d47f7f9e4ad9873d3846c13527ce43
GNU C
standard output
265 megabytes
train_000.jsonl
[ "implementation" ]
1312390800
["0", "10", "991"]
NoteIn the first sample the number already is one-digit β€” Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
PASSED
1,000
standard input
2 seconds
The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
["0", "1", "3"]
#include<stdio.h> #include<string.h> int main() { char s[100100]; int cnt,n,i,t,a; scanf("%s",s); a=strlen(s); if(a==1) {printf("0");return 0;} n=0; for(i=0;i<a;i++) n+=s[i]-'0'; cnt=1; while(n/10!=0) { t=0; while(n!=0) { t+=n%10; n=n/10; } n=t; cnt++; } printf("%d\n",cnt); return 0; }
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit?
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
C
ddc9201725e30297a5fc83f4eed75fc9
5be5093f21381b347631e4d8ea7158a1
GNU C
standard output
265 megabytes
train_000.jsonl
[ "implementation" ]
1312390800
["0", "10", "991"]
NoteIn the first sample the number already is one-digit β€” Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
PASSED
1,000
standard input
2 seconds
The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
["0", "1", "3"]
#include<stdio.h> #include<string.h> int main(void) { int n,cnt,sum,len,i; char s[100001]; scanf("%s" ,s); n=0; len=strlen(s); if(len<=1) printf("0\n"); else{ for(i=0;i<len;i++) n+=s[i]-'0'; cnt=1; while(n>=10){ sum=0; while(n>=10){ sum+=n%10; n/=10; } sum+=n%10; n=sum; cnt++; } printf("%d\n" ,cnt); } return 0; }
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit?
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
C
ddc9201725e30297a5fc83f4eed75fc9
55aa0f35795513133b6238b5ed1d82ae
GNU C
standard output
265 megabytes
train_000.jsonl
[ "implementation" ]
1312390800
["0", "10", "991"]
NoteIn the first sample the number already is one-digit β€” Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
PASSED
1,000
standard input
2 seconds
The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
["0", "1", "3"]
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char ara[100005]; long long s, p = 0, i; scanf("%s", ara); if(strlen(ara) > 1) p = 1; while(1) { s = 0; for(i = 0; i < strlen(ara); i++) { s = s + ara[i] - '0'; } if(s > 9) { itoa(s , ara , 10); p++; } else { break; } } printf("%d\n", p); return 0; }
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit?
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
C
ddc9201725e30297a5fc83f4eed75fc9
194e2e75518b79c535980f46b1a510a1
GNU C
standard output
265 megabytes
train_000.jsonl
[ "implementation" ]
1312390800
["0", "10", "991"]
NoteIn the first sample the number already is one-digit β€” Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
PASSED
1,000
standard input
2 seconds
The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
["0", "1", "3"]
#include <stdio.h> #include <math.h> #include <string.h> int sumDigits(int n) { int sum = 0; while(n > 0) { sum += n%10; n -= n%10; n /=10; } return sum; } main() { char buffer[100000]; int i; int n = 0; int count = 0; gets(buffer); int len = strlen(buffer); //special case: n is a 1 digit number if(len < 2) { printf("%d", count); exit(0); } count = 1; for(i = 0; i < len; i++) n += buffer[i] - '0'; while(n > 9) { n = sumDigits(n); count++; } printf("%d", count); exit(0); }
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit?
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
C
ddc9201725e30297a5fc83f4eed75fc9
654d1e17fe7d90bd47a2bd1815a899c1
GNU C
standard output
265 megabytes
train_000.jsonl
[ "implementation" ]
1312390800
["0", "10", "991"]
NoteIn the first sample the number already is one-digit β€” Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
PASSED
1,000
standard input
2 seconds
The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
["0", "1", "3"]
#include<stdio.h> #include<stdlib.h> #include<string.h> #define MAX_LEN 100010 int main (int argc, char *argv[]){ char n[MAX_LEN]; scanf("%s", n); int i=0, times=0, sum; int len = strlen(n); while (len > 1){ sum=0, i=0; while (i<len){ sum += (n[i] - '0'); i++; } sprintf(n, "%d", sum); //printf("+%d\n", sum); times++; len = strlen(n); } printf("%d\n", times); return EXIT_SUCCESS; }
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit?
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
C
ddc9201725e30297a5fc83f4eed75fc9
e7eabb6c554f15dbf2e43991f8bfdc02
GNU C
standard output
265 megabytes
train_000.jsonl
[ "implementation" ]
1312390800
["0", "10", "991"]
NoteIn the first sample the number already is one-digit β€” Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
PASSED
1,000
standard input
2 seconds
The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
["0", "1", "3"]
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char n[100000]; long long s, p = 0, i; scanf("%s", &n); if(strlen(n) > 1) p = 1; start: s = 0; for(i = 0; i < strlen(n); i++) s = s + n[i] - '0'; if(s > 9) { itoa(s , n , 10); p++; goto start; } printf("%d", p); return 0; }
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit?
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
C
ddc9201725e30297a5fc83f4eed75fc9
26b83b6b7f7aee18ad2a2032ef10f1e9
GNU C
standard output
265 megabytes
train_000.jsonl
[ "implementation" ]
1312390800
["0", "10", "991"]
NoteIn the first sample the number already is one-digit β€” Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
PASSED
1,000
standard input
2 seconds
The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
["0", "1", "3"]
#include <stdio.h> int main() { char c='e'; long sum=0; int so; int count = 0; while (c!='\n') { count++; so = 0; scanf("%c",&c); if (c=='\n') break; so = c - 48; sum = sum + so; } if (count > 2) count = 1; else count = 0; long s = 0; long t = 0; int m; while (sum > 9) { t = sum; s= 0; while (t>0) { m = t % 10; s = s + m; t=t/10; } count++; sum = s; } printf("%d\n", count); return 0; }
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit?
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
C
ddc9201725e30297a5fc83f4eed75fc9
f427b6e078bff014f09c3b707f49ff30
GNU C
standard output
265 megabytes
train_000.jsonl
[ "implementation" ]
1312390800
["0", "10", "991"]
NoteIn the first sample the number already is one-digit β€” Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
PASSED
1,000
standard input
2 seconds
The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
["0", "1", "3"]
#include <stdio.h> #include <stdlib.h> char Str[100001]; int main() { int i,Sum,Cnt; scanf("%s",Str); if(Str[1]=='\0') { puts("0"); return 0; } for(Cnt=1,Sum=i=0; Str[i]!='\0'; ++i) { Sum+=Str[i]-'0'; } while(Sum>9) { itoa(Sum,Str,10); for(Sum=i=0; Str[i]!='\0'; ++i) { Sum+=Str[i]-'0'; } ++Cnt; } printf("%d\n",Cnt); return 0; }
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-digit?
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
C
ddc9201725e30297a5fc83f4eed75fc9
e8873e2b4a18583b0bdf2cb548071a54
GNU C
standard output
265 megabytes
train_000.jsonl
[ "implementation" ]
1312390800
["0", "10", "991"]
NoteIn the first sample the number already is one-digit β€” Herald can't cast a spell.The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
PASSED
1,000
standard input
2 seconds
The first line contains the only integer n (0 ≀ n ≀ 10100000). It is guaranteed that n doesn't contain any leading zeroes.
["0", "1", "3"]
#include<stdio.h> int main() { int i=0,j,k,l,m,n,sum=0,p; char a[100000]; scanf("%s",a); for(i=0;a[i]!='\0';i++) { sum=sum+a[i]-'0'; } if(i==1) { sum=a[0]-'0'; p=0; } else p=1; while(sum>9) { i=sum; sum=0; while(i>0) { sum=sum+i%10; i=i/10; } p++; } printf("%d",p); return 0; }
Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. Each point of initial 8 should belong to exactly one set. It is acceptable for a rectangle from the second set was also a square. If there are several partitions, Petya will be satisfied by any of them. Help him find such partition. Note that the rectangle and the square from the partition should have non-zero areas. The sides of the figures do not have to be parallel to the coordinate axes, though it might be the case.
Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers β€” point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. All printed numbers should be pairwise distinct. If the required partition does not exist, the first line should contain the word "NO" (without the quotes), after which no output is needed.
C
a36fb51b1ebb3552308e578477bdce8f
e7c9f0875ff8611e230bf5037ad8d25b
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "geometry", "brute force" ]
1323443100
["0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2", "0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7", "0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1"]
NotePay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes.
PASSED
1,600
standard input
2 seconds
You are given 8 pairs of integers, a pair per line β€” the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide.
["YES\n5 6 7 8\n1 2 3 4", "NO", "YES\n1 2 3 4\n5 6 7 8"]
#include<stdio.h> #include<string.h> #include<stdlib.h> #define MAX 8 #define length(a,b) ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)) #define line(i,j,k,l) ((a[i].x-a[j].x)*(a[k].y-a[l].y)) #define expand(p,i,j,k) line(p[k],p[i],p[j],p[i]) #define check(p,i,j,k) (expand(p,i,j,k)==expand(p,i,k,j)) struct{ int x,y; }a[MAX]; int cmp(int *a, int *b) { return ((*a)-(*b)); } int col(int i,int *p) { if(check(p,0,1,2)) return 1; if(check(p,0,1,3)) return 1; if(check(p,0,3,2)) return 1; if(check(p,3,1,2)) return 1; /* if(i==16*15) printf("eoig jfire %d\n",check(p,0,1,2)); */ return 0; } int bits(int a) { int ans=0; while(a){ if(a&1) ans++; a>>=1; } return ans; } int main() { int i,n,j,k; int next; int rcnt,cnt; char square; int l[MAX],wh[MAX],rect[MAX]; for(i=0;i<8;i++) scanf("%d%d",&a[i].x,&a[i].y); for(i=0;i<(1<<MAX);i++){ square='n'; if(bits(i)==4){ rcnt=cnt=0; for(j=0;j<MAX;j++) if(i&(1<<j)) wh[cnt++]=j; else rect[rcnt++]=j; next=0; //printf("%d\n",a[wh[k]].x); for(j=0;j<4;j++) for(k=j+1;k<4;k++) l[next++]=length(a[wh[k]],a[wh[j]]); qsort(l,6,sizeof(int),cmp); if((l[0]==l[1])&&(l[1]==l[2])&&(l[2]==l[3])&&(l[3]!=l[4])) if(l[0]+l[1]==l[4]) if(col(i,wh)==0) square='y'; if(square=='y'){ next=0; for(j=0;j<4;j++) for(k=j+1;k<4;k++) l[next++]=length(a[rect[k]],a[rect[j]]); qsort(l,6,sizeof(int),cmp); if((l[0]==l[1])&&(l[2]==l[3])&&(l[3]!=l[4])) if(l[0]+l[2]==l[4]) if(col(i,rect)==0) break; } } square='n'; } if(square=='y'){ printf("YES\n"); for(i=0;i<4;i++) printf("%d ",1+wh[i]); printf("\n"); for(i=0;i<4;i++) printf("%d ",1+rect[i]); printf("\n"); } else printf("NO\n"); return 0; }
Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. Each point of initial 8 should belong to exactly one set. It is acceptable for a rectangle from the second set was also a square. If there are several partitions, Petya will be satisfied by any of them. Help him find such partition. Note that the rectangle and the square from the partition should have non-zero areas. The sides of the figures do not have to be parallel to the coordinate axes, though it might be the case.
Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers β€” point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. All printed numbers should be pairwise distinct. If the required partition does not exist, the first line should contain the word "NO" (without the quotes), after which no output is needed.
C
a36fb51b1ebb3552308e578477bdce8f
be4a800a14ac7662de2799bd2d6b3b55
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "geometry", "brute force" ]
1323443100
["0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2", "0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7", "0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1"]
NotePay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes.
PASSED
1,600
standard input
2 seconds
You are given 8 pairs of integers, a pair per line β€” the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide.
["YES\n5 6 7 8\n1 2 3 4", "NO", "YES\n1 2 3 4\n5 6 7 8"]
#include <stdio.h> int ok = 0, sol[8]; typedef struct po { int x, y; } point; point tab[8]; int prp(b,a,c) { int xa = tab[a].x, ya = tab[a].y; int xb = tab[b].x, yb = tab[b].y; int xc = tab[c].x, yc = tab[c].y; double a1, a2; if (xa != xb && xa != xc) { a1 = ((double) ya-yb)/((double) xa-xb); a2 = ((double) ya-yc)/((double) xa-xc); if (a1*a2 + 1.0 < 0.0000001 && a1*a2 + 1.0 > -0.0000001) return 1; else return 0; } if (xa == xb && ya == yc) return 1; if (xa == xc && ya == yb) return 1; return 0; } int rect(int a[4]) { if (prp(a[0], a[1], a[2]) && prp(a[1], a[2], a[3]) && prp(a[2], a[3], a[0]) && prp(a[3], a[0], a[1]) || prp(a[0], a[1], a[3]) && prp(a[1], a[3], a[2]) && prp(a[3], a[2], a[0]) && prp(a[2], a[0], a[1]) || prp(a[2], a[1], a[3]) && prp(a[1], a[3], a[0]) && prp(a[3], a[0], a[2]) && prp(a[0], a[2], a[1])) return 1; else return 0; } int len(a,b,c) { int xa = tab[a].x, ya = tab[a].y; int xb = tab[b].x, yb = tab[b].y; int xc = tab[c].x, yc = tab[c].y; double lab = (xa-xb)*(xa-xb)+(ya-yb)*(ya-yb); double lac = (xa-xc)*(xa-xc)+(ya-yc)*(ya-yc); double lbc = (xb-xc)*(xb-xc)+(yb-yc)*(yb-yc); if (lab - lac < 0.0000001 && lac - lab < 0.0000001) return 1; if (lbc - lac < 0.0000001 && lac - lbc < 0.0000001) return 1; if (lbc - lab < 0.0000001 && lab - lbc < 0.0000001) return 1; return 0; } int sq(int a[4]) { if (len(a[0], a[1], a[2]) && len(a[1], a[2], a[3])) return 1; else return 0; } void test(int a[4]) { if (ok) return; int i, j, k=0; if (rect(a)) if (sq(a)) { int b[4]; for (i=0; i<8; i++) { int to = 1; for (j=0; j<4; j++) if (i == a[j]) to = 0; if (to) b[k++] = i; } if (rect(b)) { ok = 1; for (i=0; i<4; i++) { sol[i] = a[i]; sol[i+4] = b[i]; } } } return; } int main(void) { int i, j, k, l; for (i=0; i<8; i++) scanf("%d %d", &tab[i].x, &tab[i].y); for (i=0; i<5; i++) for (j=i+1; j<6; j++) for (k=j+1; k<7; k++) for (l=k+1; l<8; l++) { int s[4] = {i,j,k,l}; test(s); } if (ok) { printf("YES\n"); for (i=0; i<8; i++) printf("%d%c", sol[i]+1, i%4 != 3 ? ' ' : '\n'); } else printf("NO\n"); return 0; }
Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. Each point of initial 8 should belong to exactly one set. It is acceptable for a rectangle from the second set was also a square. If there are several partitions, Petya will be satisfied by any of them. Help him find such partition. Note that the rectangle and the square from the partition should have non-zero areas. The sides of the figures do not have to be parallel to the coordinate axes, though it might be the case.
Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers β€” point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. All printed numbers should be pairwise distinct. If the required partition does not exist, the first line should contain the word "NO" (without the quotes), after which no output is needed.
C
a36fb51b1ebb3552308e578477bdce8f
f447ae84b1a90bb1805b476e3d2f14f5
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "geometry", "brute force" ]
1323443100
["0 0\n10 11\n10 0\n0 11\n1 1\n2 2\n2 1\n1 2", "0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7", "0 0\n4 4\n4 0\n0 4\n1 2\n2 3\n3 2\n2 1"]
NotePay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes.
PASSED
1,600
standard input
2 seconds
You are given 8 pairs of integers, a pair per line β€” the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide.
["YES\n5 6 7 8\n1 2 3 4", "NO", "YES\n1 2 3 4\n5 6 7 8"]
#include <stdio.h> #include <stdlib.h> int x[8], y[8]; int length (int p, int q) { return (x[p] - x[q]) * (x[p] - x[q]) + (y[p] - y[q]) * (y[p] - y[q]); } int diamond (int a, int b, int c, int d) { if (length (a, b) == length (a, c) || length (a, b) == length (a, d) || length (a, d) == length (a, c) ) return 1; return 0; } int rectangle (int a, int b, int c, int d) { if (length (a, b) == length (d, c) && length (d, b) == length (a, c) && length (a, d) == length (b, c) ) return 1; return 0; } int main (void) { int i, j, a, b, c, d, other[4]; for (i = 0; i < 8; i++) scanf ("%d%d", &x[i], &y[i]); for (a = 0; a < 5; a++) for (b = a+1; b < 6; b++) for (c = b+1; c < 7; c++) for (d = c+1; d < 8; d++) { j = 0; for (i = 0; j < 4; i++) if (i != a && i != b && i != c && i != d) other[j++] = i; if (diamond (a, b, c, d) == 1 && rectangle (a, b, c, d) == 1 && rectangle (other[0], other[1], other[2], other[3]) == 1) { printf ("YES\n%d %d %d %d\n%d %d %d %d\n", a+1, b+1, c+1, d+1, other[0]+1, other[1]+1, other[2]+1, other[3]+1); exit (0); } } printf ("NO\n"); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
0e3907164d88ba852125e81c9dab0250
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include <stdio.h> #include<string.h> int main() { int i=0,c=0,s=0; char a[102]; while(gets(a)!=NULL) { if(a[0]=='+')c++; else if(a[0]=='-') c--; else {i=0; while(a[i]!=':'){i++;} s+=(strlen(a)-i-1)*c; } } printf("%d",s); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
d18cc6010b341f8114b2c8023d61f6ea
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include<stdio.h> #include<stdlib.h> int main() { char name[1000],count=0; int i,j,result=0; while(gets(name)!='\0') { if(name[0]=='+')count++; else if (name[0]=='-')count--; else { for(i=0;name[i]!=':';i++);i++; for(j=0;name[i]!='\0';j++,i++); result+=count*j; } } printf("%d\n",result); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
61017265b65143c01b6ef7878badcda3
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include<stdio.h> #include<string.h> int main() { int p=0,j,k=0,l=0,r=0,len=0; char X[100]; while(gets(X)!=NULL) { if(X[0]=='+') { p++; } else if(X[0]=='-') { p--; } else { len=0; for(j=0;X[j]!='\0';j++) { len++; } k=0; l=0; for(j=0;X[j]!=':';j++) { k++; } l=len-(k+1); r+=l*p; } } printf("%d\n",r); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
db3b84a8e5ebf015e1ada7f13b1e5e63
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i,l=0,p=0,sum=0,f=0; char s; while(scanf("%c",&s)!=EOF){ if(s=='\n'){ f=0; sum+=p*l; l=0; } else if(s==':'){ f=1; } else if(f==1){ l++; } else if(s=='+'){ p++; f=0; } else if(s=='-'){ p--; f=0; } } printf("%d",sum); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
9afe5678b74fd1d825ac874e6dff7ec4
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include <stdio.h> int len(char *s); int main() { int n = 0, i, j ,k, sum = 0; char str[1000]; while(gets(str)) { if(str[0] == '+') n++; else if(str[0] == '-') n--; else { k = len(str); sum += n * k; } } printf("%d\n",sum); return 0; } int len(char *s) { int i = 0, l = 0; while(s[i] != ':') i++; i++; while(s[i]) { i++; l++; } return l; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
c94ed1e6d00396afdf0eec6c9fb653c7
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include<stdio.h> #include<stdlib.h> #include<string.h> long long result(long long n,long long m) { if(n<m) return 0; int i,t=1,ans=1; for(i=n;i>m;i--)/*Computation of the combination aCb*/ { ans*=i; ans/=t++; } return ans; } char* bitchange(char* ch) { int i,t=0,cnt=0,j,k=0; t=strlen(ch); for(i=t-1;i>=0;i--) { if(ch[i]=='1') cnt++; else { k=i; break; } } // printf("%d %s\n",cnt,ch); if(cnt==t) { ch[0]='1'; ch[t]='0'; ch[t+1]='\0'; k=1; } for(i=k;i<t;i++) { if(ch[i]=='1') ch[i]='0'; else if(ch[i]=='0') ch[i]='1'; // printf("c== %d",ch[i]); } if(cnt!=t) ch[t]='\0'; //printf("\n%d %s\n\n",t,ch); return ch; } int cmpfunc(const void*a,const void*b) { return (*(int*)a - *(int*)b); } int main() { int n,m,i,j,sum=0,chk=0,z=0,k=0,c=':',t=0,s=0,max=0,min=0,d=0; int a[2000005]={0},b[5000]={0}; char ch[1000001],st[1000000]; while(gets(ch)) { // getchar(); // printf("%d\n",strlen(ch)); if(ch[0]=='+') k++; else if(ch[0]=='-') k--; else { //printf("%d\n",strlen(ch)); i=0; while(ch[i]!=58) { i++; // printf("%c ",ch[i]); } t=strlen(ch); chk+=k*(t-(i+1)); //printf("\ni = %d %d\n",i,chk); } // printf("%d\n",chk); // memset(ch,NULL,sizeof(int)); // getchar(); } printf("%d",chk); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
e8fcc9ef58bcace31c86668f8f3982b3
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include <stdio.h> #include <string.h> int main() { int count=0, sum=0, i=0, len=0; char a[10000]; while(gets(a)!='\0') { if(a[0]=='+') { count++; } else if(a[0]=='-') { count--; } else { i=0; while(a[i]!=':') { i++; } //printf("%d", i); sum=sum+(strlen(a)-i-1)*count; } } printf("%d", sum); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
5624ce9d15b3bc7bb92e0b9a6cbdd4ed
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include <stdio.h> #include <string.h> char buffer[1024]; int main (void) { int ans = 0; int num = 0; int len; int l; while (gets(buffer) ) { if (buffer[0] == '+') ++num; else if (buffer[0] == '-') --num; else { len = strlen (buffer); for (l=0;l<len;l++) if (buffer[l] == ':') break; l = len - l -1; ans += num * l; } } printf ("%d",ans); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
a145d72c04cabd2e57a9dc3f1723ae62
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include<stdio.h> #include<string.h> int main() { char c[101]; int n=0,sum=0; while(gets(c)!=NULL) { if(c[0]=='+')n++; else if(c[0]=='-')n--; else { sum = sum + ((c+strlen(c)) - strchr(c,':')-1)*n; } } printf("%d",sum); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
5dc4952078dcf6f0633037fe761e9dfc
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include<stdio.h> #include<string.h> int main() { char cmd[101] ; int byte = 0; int online = 0; int i; while(gets(cmd)) { if(cmd[0]=='+') online++; else if(cmd[0]=='-') online--; else { for(i=0;i<110;i++) if(cmd[i]==':') break; byte +=(strlen(cmd)-1-i)*online; } } printf("%d\n",byte); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
0cafdc5e0dfa35aec3d519fcfa9e71c6
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include<stdio.h> int main() { char s[102][102]; int i,j,d=0,c=0,s1=0; while(gets(s[i])!=NULL) { if(s[i][0]=='+') c++; if(s[i][0]=='-') c--; if(s[i][0]!='+'&&s[i][0]!='-') { d=0; for(j=0;j<strlen(s[i]);j++) { if(s[i][j]==':') { d=j+1; break; } } s1=s1+c*(strlen(s[i])-d); }} printf("%d",s1); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
29dbf15bc07e8502ec590d4ea03100c6
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include <stdio.h> int main(void) { char ch = 0; int no_wait = 0; int people = 0; int symbols = 0; int total = 0; while(1) { ch = getchar(); if (ch != -1) { switch (ch) { case '+': { people++; no_wait = 0; break; } case '-': { people--; no_wait = 0; break; } case ':': { no_wait = 1; break; } case '\n': { if (no_wait){ total += (symbols - 1) * people; symbols = 0; no_wait = 0; break; } } } } else break; if (no_wait) { symbols++; } } printf("%i", total); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
ac60a47cc3c186070885009ee4f8c45b
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include<stdio.h> int main(){ char msg[100]; char t=4; int i; int count,sum,users; sum=0; users=0; while (t!=EOF){ count=0; for (i=0;((t=getchar())!=10)&&(t!=EOF);i++){ msg[i]=t; msg[i+1]=EOF; } if (t==EOF) break; if (msg[0]=='+') { users++; //printf("users:%d\n",users); } else if (msg[0]=='-') users--; else { i--; while (msg[i]!=':'){ count++; i--; } //printf("count:%d\n",count); sum=sum+count*users; } } printf("%d\n",sum); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
a35bc24d6bcff0e74c3b9cb2aa9539e4
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char s[100]; int i,sum=0,res=0,j=0; while(gets(s)!=NULL){ if (s[0]=='+') sum++; else if (s[0]=='-') sum--; else{ j=0; while(s[j]!=':') {j++;} res=res+(strlen(s)-j-1)*sum;} } printf("%d",res); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
2072028db86352b66d16980e3a526b6a
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main() { char ch; int sum=0; char ch2; int res=0; int ress=0; FILE *f; f=fopen("d","w"); while((ch=getchar())!=EOF) { putc(ch,f); } fclose(f); f=fopen("d","r"); while((ch=getc(f))!=EOF) { if(ch=='+') { sum++; } else if(ch=='-') { sum--; } else if(ch==':') { while(ch=getc(f)!='\n') { res++; } res*=sum; ress+=res; res=0; } } printf("%d",ress); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
91ad5b398107accfa6e4339e343c7491
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char ent[150]; int res = 0, p = 0; while(scanf(" %[^\n]", ent) != EOF) { if(ent[0] == '+') p++; else if(ent[0] == '-') p--; else { int i; for(i = 0; i < strlen(ent); ++i) if(ent[i] == ':') break; i++; res += (strlen(ent)-i)*p; } } printf("%d", res); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
a8534494da9a37263bf06cf4d7612465
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(){ char str[120]; int count=0,i,tr=0,len; while(gets(str)!='\0'){ if(str[0]=='+') count++; else if(str[0]=='-') count--; else{ len=strlen(str); for(i=0; ;i++){ if(str[i]!=':') len--; else { len--; break; } } tr+=len*count; } //printf("%d\n",tr); } printf("%d\n",tr); return(0); }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
dc6351480bea812e2560e335e7295ec4
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include<stdio.h> int main(){ int i,j,k,l,n,m,our = 0,ans=0; char c,s[1000]; c = getchar(); while(c!=EOF){ j = 0; s[j] = c; while(c!='\n'){ j++; c = getchar(); s[j] = c; } if(s[0]=='+') our++; else if(s[0]=='-') our--; else{ l = 0; while(s[l]!=':') l++; ans = ans + (our*(j-l-1)); } c = getchar(); } printf("%d\n",ans); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
03f61c481124cd025d6f41864ce1e865
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include <stdio.h> int main() { int n = 0, l = 0, i; char s[105]; while (fgets(s, 105, stdin) != NULL) { if (s[0] == '+') { n++; } else if (s[0] == '-') { n--; } else { for (i = 0; i < strlen(s); i++) { if (s[i] == ':') break; } l += (strlen(s) - i - 2) * n; } } printf("%d\n", l); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
fd1f2ce53dacab2ba7b7f71dec9da0cb
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include<stdio.h> #include<string.h> int main() { int inchat=0,length,data=0,i; char command[110]; while(gets(command)) { if(command[0] == '+') inchat++; else if(command[0] == '-') inchat--; else { length = strlen(command); for(i=0;i<length;i++) if(command[i] == ':') break; length = strlen(command + i +1); //printf("length %d inchat %d\n",length,inchat); data+= length * inchat; } } printf("%d",data); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
86c162ca62a6a17316e6f01b3dae64b5
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
//SORU xx //PROGRAM C #include<stdio.h> #include<string.h> #include<stdlib.h> #include<limits.h> #include<time.h> #include<ctype.h> #define scn(x) fscanf(in,"%d",&x); #define prn(x) fprintf(out,"%d\n",x); #define prn2(x) fprintf(out,"%d",x); #define line() fprintf(out,"\n"); #define wait system("PAUSE"); #define scn2(x,y) scn(x);scn(y); FILE *in,*out; void dosya(){ /*in=fopen("girdi.in","r");*/in=stdin; /*out=fopen("cikti.out","w");*/out=stdout; } int N; char c,t,temp; int A[123][123]; void oku(){ int kisi=0,top=0; while(fscanf(in,"%c",&c)!=EOF){ if(c=='+') kisi++; else if(c=='-') kisi--; else if(c=='\n') continue; else{ while(1){ fscanf(in,"%c",&t); if(t=='\n') break; else if(t==':'){ while(1){ fscanf(in,"%c",&temp); if(temp=='\n') break; if(temp==' '); top+=kisi; } break; break; } } } } prn(top); return; } int main(){ dosya(); oku(); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
104c8b968d79cd69c76d44b2a30c449e
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include<stdio.h> #include<stdlib.h> int main() { int people=0,ans=0,i; char a; int d=0; while(1) { a=getchar(); if(a==-1) { break; } if(a=='+') people++; if(a=='-') people--; if(a==':') { d=1; } else if(a=='\n') d=0; else if(d==1) ans=ans+people; } printf("%d",ans); return 0; }
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands: Include a person to the chat ('Add' command). Remove a person from the chat ('Remove' command). Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command). Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.As Polycarp has no time, he is asking for your help in solving this problem.
Print a single number β€” answer to the problem.
C
d7fe15a027750c004e4f50175e1e20d2
31f280bcbcba01e84557d54977699d80
GNU C
standard output
64 megabytes
train_000.jsonl
[ "implementation" ]
1269100800
["+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate", "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate"]
null
PASSED
1,000
standard input
1 second
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following: +&lt;name&gt; for 'Add' command. -&lt;name&gt; for 'Remove' command. &lt;sender_name&gt;:&lt;message_text&gt; for 'Send' command. &lt;name&gt; and &lt;sender_name&gt; is a non-empty sequence of Latin letters and digits. &lt;message_text&gt; can contain letters, digits and spaces, but can't start or end with a space. &lt;message_text&gt; can be an empty line. It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc. All names are case-sensitive.
["9", "14"]
#include <stdio.h> #include <string.h> #define MAX_SIZE 126 int main() { int users = 0, bytes = 0, colon_position, commands_length; char commands[MAX_SIZE]; while(fgets(commands, MAX_SIZE, stdin)) { commands_length = strlen(commands); if(commands[0] == '+') { users++; } else if(commands[0] == '-') { users--; } else { colon_position = 0; while(colon_position < commands_length) { if(commands[colon_position] == ':') { break; } colon_position++; } bytes += (commands_length-colon_position-2)*users; } } printf("%d\n", bytes); return 0; }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
d29f811b08418022f83f979db214c39e
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include<stdio.h> #include<stdlib.h> int main() { int n,m,i,j,k,win,vot,fin,count=0; scanf("%d%d",&n,&m); int *a=malloc(110*sizeof(int)); for(i=0;i<n;i++)a[i]=0; for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&k); if(j==0) { vot=k;win=0; } if(k>vot) { win=j; vot=k; } } a[win]++; if(a[win]==count&&win<fin) { fin=win; continue; } if(a[win]>count) { fin=win; count=a[win]; } } printf("%d\n",fin+1); return 0; }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
ca63105b323516ef7e1a4a71ea715ced
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include<stdio.h> int main() { int a[111][111],b[111],m,n,j,i,max=0,x=0; scanf("%d%d",&m,&n); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%d",&a[i][j]); } } for(i=1;i<=n;i++) { int max=-1; for(j=1;j<=m;j++) { if(a[i][j]>max) { max=a[i][j]; x=j; } } b[x]++; } x=0; for(i=1;i<=m;i++) if(b[i]>max) { max=b[i]; x=i; } printf("%d\n",x); return 0; }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
0ed60a78700b5b97e785be527d8f658c
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include<stdio.h> #include<math.h> #include<string.h> int a[510][510]={0}; int main() { int i,j,k,n,m,t,big; int b[510]={0}; int c[510]={0}; scanf("%d%d",&n,&m); for(i=1;i<=m;i++) for(j=1;j<=n;j++) scanf("%d",&a[i][j]); for(i=1;i<=m;i++) { big=-1; for(j=1;j<=n;j++) { if(a[i][j]>big){big=a[i][j];k=j;} } b[i]=k; } for(i=1;i<=m;i++) { c[b[i]]+=1; } for(i=1,big=-1;i<=n;i++) { if(c[i]>big){big=c[i];t=i;} } printf("%d\n",t); return 0; }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
92c7940326623c0b5321bb4067cec0dc
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include <stdio.h> int main() { int n,m,i,j,d[105]={0},max=-1,k; scanf("%d %d",&n,&m); long long int a[105][105]; for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); if(max<a[i][j]) { max=a[i][j]; k=j; } } d[k]++; max=-1; } for(i=0;i<n;i++) if(max<d[i]) { max=d[i]; k=i+1; } printf("\n%d",k); }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
87d8aba1ab7a83caaf2fe9154533c7dd
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include <stdio.h> int main(){ int n,m,i,j,c[105][105],w[105]={0},max=-1,h; scanf("%d %d",&n,&m); for(i=0;i<m;i++){ for(j=0;j<n;j++){ scanf("%d",&c[i][j]); if(max<c[i][j]){ max=c[i][j]; h=j; } } w[h]++; max=-1; } for(i=0;i<n;i++) if(max<w[i]){ max=w[i]; h=i+1; } printf("%d",h); }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
9d1d98550ec61b1d54e4fad222ac00c9
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include<stdio.h> int main() { int n, m, i, j, ans; long long a[100][100], x, temp; int b[101]; scanf("%d %d", &n, &m); for (i=0 ; i<m ; i++) { for (j=0 ; j<n ; j++) { scanf("%I64d", &x); a[i][j] = x; } } for (i=0 ; i<100 ; i++) { b[i] = 0; } for (i=0 ; i<m ; i++) { temp = 0; ans = 1; for (j=0 ; j<n ; j++) { if (a[i][j] > temp) { temp = a[i][j]; ans = j+1; } } b[ans] = b[ans] + 1; } temp = 0; ans = 1; for (i=1 ; i<101 ; i++) { if (b[i] > temp) { temp = b[i]; ans = i; } } printf("%d", ans); return 0; }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
d187a23b1a0bf9dd14d8a9bed0aa66dc
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include<stdio.h> #include<string.h> #include<math.h> int main() { int n,m; scanf("%d %d",&n,&m); long long int a[m][n],b[200]={0},i,j,max=0,pos,pos1,f=0; for(i=0;i<m;i++) { max=-1,pos=-1; for(j=0;j<n;j++) { scanf("%lld",&a[i][j]); if(max<a[i][j]) { max=a[i][j]; pos=j; } } b[pos]++; } max=-1,pos=-1; for(i=0;i<n;i++) { if(max<b[i]) { pos=i; max=b[i]; } //printf("%lld ",b[i]); b[i]=0; } printf("%lld\n",pos+1); return 0; }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
d2c1aa21d4176430f62a043756cc398d
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include<stdio.h> #include<string.h> #include<math.h> long long int b[100000]={0}; int main() { int t; //scanf("%d",&t); //while(t--) { int n,m; scanf("%d %d",&n,&m); long long int a[m][n],i,j,max=0,pos,pos1,f=0; for(i=0;i<m;i++) { max=0,pos=0,pos1=0,f=0; for(j=0;j<n;j++) { scanf("%lld",&a[i][j]); if(max<a[i][j]) { max=a[i][j]; pos=j; } } b[pos]++; } max=0,pos=0; for(i=0;i<n;i++) { if(max<b[i]) { pos=i; max=b[i]; } b[i]=0; } printf("%lld\n",pos+1); } return 0; }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
2205c3c4455afe38afc4f2812c1d0842
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include <stdio.h> #include <stdlib.h> int n,m; int winner(long long int a[m+2][n+2],int y) { int max=a[y][1],i,ans=1; for(i=2;i<=n;i++) { if(max<a[y][i]) { max=a[y][i]; ans=i; } } return ans; } int last (int finall[]) { int max=finall[1],i,ans=1; for(i=2;i<=n;i++) { if(max<finall[i]) { max=finall[i]; ans=i; } } return ans; } int main() { int i,j,x; scanf("%d%d",&n,&m); int finall[102]={0}; long long int a[m+2][n+2]; for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { scanf("%I64d",&a[i][j]); } x=winner(a,i); finall[x]++; } printf("%d",last(finall)); return 0; }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
14e9f3aba4f7a0972dda88df3b9631ff
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include<stdio.h> int main() { int n,m,i,j,count,max=0; scanf("%d %d",&n,&m); int elec,vote[n]; for(i=0;i<n;i++)vote[i]=0; for(i=0;i<m;i++){ max=-1; for(j=0;j<n;j++){ scanf("%d",&elec); if(elec>max)max=elec,count=j; } vote[count]++; } max=0; for(i=0;i<n;i++){ if(max<vote[i]){ max=vote[i]; count=i+1; } } printf("%d",count); return 0; }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
ef9773d33b64d9733c2fce775ea8cb8b
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include <stdio.h> #include <stdlib.h> int main() { int x[100][100]; int s[100]; int n,m,z,winner,max; z=0; winner=0; scanf("%d %d",&n,&m); int i,j;//m rows n columns for(i=0;i<m;i++){ //Reading the matrix for(j=0;j<n;j++){ scanf("%d",&x[i][j]); } } for(i=0;i<m;i++) { max=x[i][0]; s[i]=1;//index of winner cand. In the state for(j=0;j<n;j++) { if( x[i][j]>max) { max =x[i][j]; s[i]=j+1; } } } int w; for(j=1;j<=n;j++) for(i=0;i<m;i++) { for(i=0;i<m;i++) { if(s[i]==j) z=z+1; } if(z>winner) {winner=z; w=j;} z=0; } printf("%d",w); }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
4d4b2990d5f50510f0e4d561b38c03dc
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include <stdio.h> #include <stdlib.h> int main() { int x[100][100]; int s[100]; int n,m,z,winner,max; z=0; winner=0; scanf("%d %d",&n,&m); int i,j;//m rows n columns for(i=0;i<m;i++){ //Reading the matrix for(j=0;j<n;j++){ scanf("%d",&x[i][j]); } } for(i=0;i<m;i++) { max=x[i][0]; s[i]=1;//index of winner cand. In the state for(j=0;j<n;j++) { if( x[i][j]>max) { max =x[i][j]; s[i]=j+1; } } } int w; for(j=1;j<=n;j++) for(i=0;i<m;i++) { for(i=0;i<m;i++) { if(s[i]==j) z=z+1; } if(z>winner) {winner=z; w=j;} z=0; } printf("%d",w); }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
fdaf726412e43411f777d5333d6b6c9d
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include<stdio.h> int b[105]; int main() { int n,m,i,j,q,max,p,index,final; index=0; final=0; scanf("%d %d", &n, &m); for(i=0;i<m;i++) { max=-1; p=0; q=0; for(j=0;j<n;j++) { scanf("%d", &q); p=q; if(p>max) { max=p; index=j; } } b[index]++; } max=0; p=0; for(i=0;i<n;i++) { p=b[i]; if(p>max) { max=p; final=i; } } printf("%d\n", (final+1)); return 0; }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
549e23edbc9dea0b8b77a63f7226163b
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include<stdio.h> int main() { long long int N,M,i,j,max=0,index,temp; scanf("%lld %lld",&N,&M); long long int ans[N]; for(i=0;i<N;i++) ans[i]=0; for(i=0;i<M;i++) { max=0; index=0; for(j=0;j<N;j++) { scanf("%lld",&temp); if(temp>max) { max=temp; index=j; } } ans[index]++; } max=0; for(i=0;i<N;i++) { if(ans[i]>max) { max=ans[i]; index=i; } } printf("%lld\n",index+1); return 0; }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
bbfba3dc8a5eae2bcba159e6f208d668
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include<stdio.h> int main() { int n,m,i,j,c=0,max=0,b; scanf("%d%d",&n,&m); int a[100]={0}; for(i=1;i<=m;i++) { max=0; c=0; for(j=0;j<n;j++) { scanf("%d",&b); if(b>max) { max=b; c=j; } } a[c]++; } max=0; c=0; for(i=0;i<n;i++) { if(a[i]>max) { max=a[i]; c=i; } } printf("%d",(c+1)); }
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.
Print a single number β€” the index of the candidate who won the elections. The candidates are indexed starting from one.
C
b20e98f2ea0eb48f790dcc5dd39344d3
66a02614957af755a13fc5cfe9774655
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1439483400
["3 3\n1 2 3\n2 3 1\n1 2 1", "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7"]
NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.
PASSED
1,100
standard input
1 second
The first line of the input contains two integers n, m (1 ≀ n, m ≀ 100) β€” the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≀ j ≀ n, 1 ≀ i ≀ m, 0 ≀ aij ≀ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.
["2", "1"]
#include <stdio.h> #include <string.h> int large(int ara[],int n) { int i,large=0,k=0; for(i=0; i<n; i++) { if(ara[i]>large) { //printf("%I64d %I64d\n",ara[i],large); k=0; large=ara[i]; k=i; } } //printf("k= %I64d\n", k); return k; } int main() { int ans=0,a=0,b=0,check=0,c=0,d=0,e=0,maximum=0,temp=0,n,m,i,j,l=0,ara[10000],ara2[10000],ara3[10000]; memset(ara3,0,sizeof(ara3)); scanf("%d %d", &n, &m); for(i=0; i<m; i++) { for(j=0; j<n; j++) { scanf("%d", &ara[j]); } ara2[l]=large(ara,n); //printf("%d\n", ara2[l]); ara3[ara2[l]]++; //printf("%I64d\n", ara2[l]); l++; } /*for(i=0; i<m; i++) { for(j=i+1; j<m; j++) { if(ara2[j]<=ara2[i]) { temp=ara2[j]; ara2[j]=ara2[i]; ara2[i]=temp; } } } for(i=0; i<m; i++) { printf("%I64d ",ara2[i]); } a=ara2[0]; for(i=0; i<m; i++) { if(ara2[i]==a) { b++; //check=ara2[i]; } else if(ara2[i]!=a && b>d) { e++; check=ara2[i-1]; a=ara2[i]; if(b>=d) { if(e!=1) check=ara2[i]; d=b; b=1; //check=ara2[i]; } } } if(e==0) check=ara2[0]; printf("%I64d",check);*/ for(i=0; i<n; i++) { //printf("%d\n",ara3[i]); if(ara3[i]>maximum) { maximum=ara3[i]; ans=i+1; } } printf("%d",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
f4b9e102248dd55b1c32b7255517040b
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include<stdio.h> int candle[10001]; void merge(int min,int mid,int max) { int tmp[1000]; int i,j,k,m; j=min; m=mid+1; for(i=min;j<=mid&&m<=max;i++){ if(candle[j]<=candle[m]){ tmp[i]=candle[j]; j++; } else{ tmp[i]=candle[m]; m++; } } if(j>mid){ for(k=m; k<=max; k++){ tmp[i]=candle[k]; i++; } } else{ for(k=j; k<=mid; k++){ tmp[i]=candle[k]; i++; } } for(k=min; k<=max; k++) candle[k]=tmp[k]; } void part(int min,int max) { int mid; if(min<max){ mid=(min+max)/2; part(min,mid); part(mid+1,max); merge(min,mid,max); } } int main() { int m,t,r,i=1,j=0,p=1,q=1,c; scanf("%d %d %d",&m,&t,&r); int ara[m]; for(i=0;i<m;i++){ scanf("%d",&ara[i]); } for(j=r;j>0;j--){ if(ara[0]-j+t>=ara[0]){ candle[p]=ara[0]-j+t; p++; //can++; } else{ printf("-1"); return 0; } } for(i=1;i<m;i++){ c=p; for(j=c-r;j<c;j++){ if(candle[j]<ara[i]){ candle[p]=ara[i]-q+t; part(0,p); p++;q++; } } q=1; } printf("%d",p-1); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
60f6ad77bcb23787d49492a76161f4a2
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include <stdio.h> int w[1000], lig[1000]; int main() { #ifdef LOCAL freopen("data.in", "r", stdin); #endif int m, t, r, i, j, k, l, need, count, prevs, preve; while(scanf("%d%d%d", &m, &t, &r) != EOF) { count = 0; for(i = 0; i < 400; i++) { w[i] = 0; lig[i] = 0; } for(i = 0; i < m; i++) scanf("%d", &w[i]); for(i = 0; i < m; i++) { //printf("------j=w[%d]=%d------\n", i, w[i]); j = w[i]; need = r - lig[j]; //printf("lig[%d]=%d,need=%d\n", j, lig[j], need); for(k = 1; k <= need; k++) { prevs = j - k + 1; if(prevs < 0) prevs = 0; preve = j - k + t; for(l = prevs; l <= preve; l++) lig[l]++; count++; } if(lig[j] < r) { count = -1;break; } } printf("%d\n", count); } return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
dd5220344fc1a29417414148900cebba
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
/*288*/ #include<stdio.h> int mem[301]; int main() { int m,r,t; int i,w,j,k; int x,ans=0; int can[301]={0}; scanf("%d %d %d",&m,&t,&r); if(r>t) { printf("-1\n"); return 0; } for(i=0;i<m;i++) { scanf("%d",&w); mem[w]=1; } for(i=1;i<=300;i++) { if(mem[i]) { int x,count=0; for(k=1;k<=r;k++) { if(!can[k]){count++;can[k]=t-count+1;} } ans+=count; } for(j=1;j<=r;j++){if(can[j])can[j]--;} } printf("%d\n",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
f3e599afe272af8a176779038151ca7f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
/*288*/ #include<stdio.h> int mem[301]; int main() { int m,r,t; int i,w,j,k; int x,ans=0; int can[301]; scanf("%d %d %d",&m,&t,&r); if(r>t) { printf("-1\n"); return 0; } for(i=1;i<=r;i++)can[i]=0; scanf("%d",&w); mem[w]=1; j=w; for(i=1;i<m;i++) { scanf("%d",&w); mem[w]=1; } for(i=j;i<=w;i++) { if(mem[i]) { int count=0; for(k=1;k<=r;k++) { if(!can[k]){count++;can[k]=t-count+1;} } ans+=count; } for(j=1;j<=r;j++){if(can[j])can[j]--;} } printf("%d\n",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
0820c665a0d40f697666b0e4ec89210e
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
/*288*/ #include<stdio.h> int mem[301]; int main() { int m,r,t; int i,w,j,k; int x,ans=0; int can[301]; scanf("%d %d %d",&m,&t,&r); if(r>t) { printf("-1\n"); return 0; } for(i=1;i<=r;i++)can[i]=0; for(i=0;i<m;i++) { scanf("%d",&w); mem[w]=1; } for(i=1;i<=w;i++) { if(mem[i]) { int count=0; for(k=1;k<=r;k++) { if(!can[k]){count++;can[k]=t-count+1;} } ans+=count; } for(j=1;j<=r;j++){if(can[j])can[j]--;} } printf("%d\n",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
b0d0e5a679108b1b60973628f906dd8f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include<stdio.h> int stack[90005]; int arr[305]; int main() { int m,t,r,i,flag = 0; scanf("%d%d%d",&m,&t,&r); for(i=0;i<m;i++) scanf("%d",&arr[i]); int count = 0,l = 0,f = r-1; for(i=0;i<r;i++) stack[i] = arr[0]-r+i; count = r; int j; if(t<r) flag=1; else { for(i=1;i<m;i++) { int tmp = 0; while(stack[l]+t<arr[i]&&l<=f) { tmp++; l++; } if(arr[i]-tmp<=stack[f]) { flag=1; break; } count +=tmp; for(j=1;j<=tmp;j++) { stack[f+j] = arr[i] - tmp + j - 1; } f = f+tmp; } } if(flag==1) printf("-1\n"); else printf("%d\n",count); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
18ad71c36479fce7b387751b46fda0f7
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include <stdio.h> int can[602]; int main() { int m,t,r,i,k; int ans = 0; scanf("%d%d%d",&m,&t,&r); int A[m]; for(i = 0;i < m;i++){ scanf("%d",&A[i]); } if(r > t){ printf("-1\n"); return 0; } for(i = 0;i < m;i++){ int j = A[i] - 1; while(can[A[i]] < r){ for(k = j + 1; k <= j + t;k++){ if(k >= 1){ can[k]++; } } ans++; j--; } } printf("%d\n",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
6afda527da4ecd9fe9288eaddc7431e5
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include<stdio.h> int main(void){ int n; int t; int r; scanf("%i %i %i", &n, &t, &r); int Pole[n]; int i; for(i=0;i<n;i++){ scanf("%i", &Pole[i]); } int mini=1000000; int zacatky[1000]; int stav=1; int zrovna=0; int rozsviceni[1500]; for(i=0;i<1500;i++){ rozsviceni[i]=0; } for(i=0;i<r;i++){ zacatky[i]=Pole[0]-r+i+1; rozsviceni[Pole[0]-r+i+1+500]=1; if(i>=t) {printf("-1\n"); return 0;} } zrovna=r; int sviti[1000]; for(i=0;i<1000;i++){ sviti[i]=0; } int j; int duch; duch=1; int k; for(i=0;i<=Pole[n-1];i++){ for(j=0;j<zrovna;j++){ if(i-zacatky[j]<t) sviti[i]++; } //printf("%i ", duch); if(i==Pole[duch]){ if(sviti[i]<r){ k=Pole[duch]; for(j=sviti[i];j<r;j++){ //printf("%i\n\n", i); while(rozsviceni[k+500]!=0){k--;} rozsviceni[k+500]=1; zacatky[zrovna]=k; zrovna++; if(Pole[duch]-k>=t){ printf("-1\n"); return 0; } } } duch++; } } int res=0; for(i=0;i<1500;i++){ if(rozsviceni[i]) res++; } /*for(i=500;i<550;i++){ printf("%i\n", rozsviceni[i]); }*/ printf("%i\n", res); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
3f6f9c24f9a75be8ac27cff379daed72
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include <stdio.h> char Flag[601]; int Cnt[601]; int main() { int m, t, r, w, i, j; scanf("%d %d %d", &m, &t, &r); while(m--) { scanf("%d", &w); w += 300; Flag[w] = 1; } int Cur = 0; for(i = 0; i < 601; ++i) { Cur += Cnt[i]; if(Flag[i] == 1) { if(Cur < r) { int target = r - Cur; for(j = i - 1; j >= i - t && j >= 0; --j) { if(Flag[j] == 0) { Flag[j] = 2; ++Cnt[j + 1]; if(j + t + 1 < 601) { --Cnt[j + t + 1]; } if(--target == 0) { break; } } } if(target == 0) { Cur = r; } else { puts("-1"); return 0; } } Flag[i] = 0; } } Cur = 0; for(i = 0; i < 601; ++i) { Cur += Flag[i] == 2; } printf("%d\n", Cur); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
f0e69d7a6c032610c52abf9c79e61c51
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include"stdio.h" int main() { int f,temp,x[1200]={0},w[1200]={0},i,m,t,r,ans=0,j,z; scanf("%d%d%d",&m,&t,&r); for(i = 0;i < m ; ++i){ scanf("%d",&temp); if(x[temp+600]>=r)continue; int shit = x[temp+600]; for(j = 0;j<r-shit;++j){ int s = t - 1; for(z = temp - 1 + 600; s > -1;--s,--z){ if(w[z] == 0){ w[z] = 1; ++ans; for(f = z+1 ; f-z<=t ;++f) ++x[f]; break; } } } if(r-x[temp+600]>0){ printf("-1"); return 0; } } printf("%d",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
3338a50031aebf722e75f06dfabaf357
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include<stdio.h> int main() { int m,t,r,a[500],b[800]={0},i,p=0,s=0,c,e,ans=0; scanf("%d %d %d",&m,&t,&r); for(i=0;i<m;i++) scanf("%d",&a[i]); while(p<m) { if(a[p]==s) { c=0;e=0; for(i=1;i<=t;i++) if(b[s-i+300]==1) c++; if(c!=r) { for(i=1;i<=t && c+e<r;i++) if(b[s-i+300]==0) { b[s-i+300]=1; ans++; e++; } if(c+e!=r) { printf("-1\n"); return 0; } } p++; } s++; } printf("%d\n",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
ba360abb78383768ac7a3739313da224
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include "stdio.h" int c[605] = {0}; int l[605] = {0}; int g[305] = {0}; int main() { int m,t,r,i,wi,j,cnt=0,k,tmp; scanf("%d%d%d",&m,&t,&r); if(r>t) { printf("-1\n"); return 0; } for(i=0;i<m;i++) { scanf("%d",&wi); g[wi]=1; } for(i=0;i<=300;i++) { if(g[i]) { if(c[300+i]<r) { tmp = c[300+i]; for(j=1;j<=r-tmp;j++) { //printf("- %d.\n",r-c[300+i]); l[300+i-j]=1; cnt++; for(k=0;k<t;k++) { if(i+k-j+1+300>=605) break; c[300+i+k-j+1]+=1; } } } } } printf("%d\n",cnt); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
19df76c12717045ba0ee2f1d7e753c0f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include"stdio.h" int main() { int f,temp,x[1200]={0},w[1200]={0},i,m,t,r,ans=0,j,z; scanf("%d%d%d",&m,&t,&r); for(i = 0;i < m ; ++i){ scanf("%d",&temp); if(x[temp+600]>=r)continue; int shit = x[temp+600]; for(j = 0;j<r-shit;++j){ int s = t - 1; for(z = temp - 1 + 600; s > -1;--s,--z){ if(w[z] == 0){ w[z] = 1; ++ans; for(f = z+1 ; f-z<=t ;++f) ++x[f]; break; } } } if(r-x[temp+600]>0){ printf("-1"); return 0; } } printf("%d",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
c754ab6415a73d3c27e9ae472cb6b480
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include <stdio.h> #include <stdlib.h> int c[90001]={0}; int main() { int m,t,r; scanf("%d%d%d",&m,&t,&r); int i,j,k,g[m],l,ans=0; for(i=0;i<m;i++) scanf("%d",&g[i]); if (t<r) { printf("-1"); return 0; } while(ans<r) { c[r-ans-1]=g[0]-ans+t-1; ans++; } for(i=1;i<m;i++) { k=0;j=0; while (k<r) { if(c[ans-r+k]<g[i]) { j++; } k++; }ans+=j; for(l=1;l<=j;l++) { c[ans-l]=g[i]-l+t; } } printf("%d",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
f4da796b973b0e7c33d947050bb9b466
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include<stdio.h> int main(){ int m,t,r,ghost,candles[700][2]={0},light,ans=0,i,j,k; scanf("%d %d %d",&m,&t,&r); for(i=0;i<m;i++){ scanf("%d",&ghost); if(ans==-1){ continue; } if(candles[ghost+350][1]<r){ light=r-candles[ghost+350][1]; j=ghost+350-1; while(light>0){ if(j+t<ghost){ break; } if(candles[j][0]==1){ j--; continue; } candles[j][0]=1; light--; ans++; for(k=ghost+350;k<=j+t && k<700;k++){ candles[k][1]++; } j--; } if(candles[ghost+350][1]<r){ ans=-1; } } } printf("%d\n",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
190ee3e2470fd0302bf6f3222d9203df
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include <stdio.h> int m, t, r; int gho[301], time[602], total; void candle(int pos) { int i, j, cnt; pos+=300; if(time[pos]<r) { for(i=r-time[pos], cnt=0;i>0;i--, cnt--) { for(j=0;j<t;j++) { if(pos+cnt+j>=601) break; time[pos+cnt+j]++; } total++; //printf("%d ", pos+cnt-300); } //printf("\n"); } } int main() { int i; scanf("%d %d %d", &m, &t, &r); for(i=0;i<m;i++) scanf("%d", &gho[i]); if(r > t) printf("-1"); else { for(i=0;i<m;i++) { candle(gho[i]); } printf("%d", total); } return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
c27b2fe2c2a3ae88c3aad5883022c291
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include <stdio.h> int main() { int m,t,r; int wi; int ar[300]; int i,j; int first,mid,last; int index; int found=0; int pre_index; int candles; int test; scanf("%d%d%d",&m,&t,&r); if (t>=r) { candles=r; scanf("%d",&wi); wi=wi+t; for (i=r-1;i>-1;i--,wi--) ar[i]=wi; j=m-1; index=-1; while (j--) { scanf("%d",&wi); if ((ar[r-1]<wi)&&(index!=-1)) first=0,last=index,test=1; else first=index+1,last=r-1,test=2; mid=(first+last)/2; pre_index=index; index=-1; found=0; while (first<last) { if (ar[mid]==wi) { index=mid; found=1; break; } else if (ar[mid]>wi) last=mid-1; else { first=mid+1; index=mid; } mid=(first+last)/2; } if (found==0) if (ar[first]<=wi) index=first; wi=wi+t; if (test==1) { for (i=index;i>-1;i--,wi--) ar[i]=wi; for (i=r-1;i>pre_index;i--,wi--) ar[i]=wi; if (index+r>pre_index) candles+=(index+r-pre_index); else index=pre_index; } else { for (i=index;i>pre_index;i--,wi--) ar[i]=wi; if (index>pre_index) candles+=(index-pre_index); else index=pre_index; } if (index==(r-1)) index=-1; } printf("%d",candles); } else { for (i=1;i<=m;i++) scanf("%d",&wi); printf("-1"); } return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
3208c1f4a5da87e89b0706f5539c43ad
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include <stdio.h> int time[2002]; int main(){ int i, j, k, l, m, n, t, r, ctr; scanf("%d", &m); scanf("%d", &t); scanf("%d", &r); int a[m]; for(i = 0; i < m; i++){ scanf("%d", &j); a[i] = 1000 + j; } ctr = 0; if(t < r){ printf("-1\n"); return 0; } for(i = a[0] - r; i < a[0]; i++){ time[i] = 1; ctr++; } j = 1; for(i = 1000; i <= a[m - 1]; i++){ time[i - t - 1] = 0; if(i == a[j]){ k = 0; for(l = a[j] - t; l < a[j]; l++){ k += (time[l] == 1); } if(k < r){ for(l = a[j] - 1; l >= a[j] - t && k < r; l--){ ctr += (time[l] != 1); time[l] += (time[l] != 1); k++; } if(k < r){ printf("-1\n"); return 0; } } j++; } } j = 0; for(i = 0; i < 2002; i++){ j += (time[i] == 1); } if(j){ printf("%d\n", ctr); }else{ printf("-1\n"); } return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
f60e5cd76fa752808b84f3b50b905153
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include<stdio.h> void merge(int arr[],int min,int mid,int max) { int tmp[1000000]; int i,j,k,m; j=min; m=mid+1; for(i=min; j<=mid && m<=max ; i++) { if(arr[j]<=arr[m]) { tmp[i]=arr[j]; j++; } else { tmp[i]=arr[m]; m++; } } if(j>mid) { for(k=m; k<=max; k++) { tmp[i]=arr[k]; i++; } } else { for(k=j; k<=mid; k++) { tmp[i]=arr[k]; i++; } } for(k=min; k<=max; k++) arr[k]=tmp[k]; } void part(int arr[],int min,int max) { int mid; if(min<max) { mid=(min+max)/2; part(arr,min,mid); part(arr,mid+1,max); merge(arr,min,mid,max); } } int main() { int m,t,r; scanf("%d%d%d",&m,&t,&r); int gh[m],i; for(i=0;i<m;i++) scanf("%d",&gh[i]); if(t<=(r-1)) { printf("-1"); return 0; } int ans=r,st[r],j=0,k; for(i=r-1;i>=0;i--) st[i]=gh[0]-i-1; part(st,0,r-1); for(i=1;i<m;i++) { for(j=0;j<r;j++) { if(st[j]+t>=gh[i]) break; } ans+=j; for(k=0;k<j;k++) { st[k]=gh[i]-k-1; } part(st,0,r-1); } printf("%d",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
1096937d870cdaaadf57a22ea4dbaebc
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include<stdio.h> void ready(int); void place(int); int m,t,r,glow[602],ans; char cans[602]; int main(){ int pre,i; ans=0; scanf("%d %d %d",&m,&t,&r); if(t<r){ printf("-1\n"); return 0; } for(i=0;i<602;i++){ glow[i]=0; cans[i]=0; } for(i=0;i<m;i++){ scanf("%d",&pre); ready(pre); } printf("%d\n",ans); return 0; } void ready(int pos){ int i; i=pos-1; while(glow[pos]<r){ place(i); i--; } } void place(int pos){ int i; ans++; for(i=1;i<=t;i++){ if(pos+i>=0){ glow[pos+i]++; } } }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
cabf60ee9cbb69106b790daf23cc8280
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include <stdio.h> int used[1005] ={}; int main() { int n,t,r; scanf("%d %d %d",&n,&t,&r); if(t < r) { printf("%d\n",-1); return 0; } for(int i = 0;i<n;i++) { int x; scanf("%d",&x); x+=500; int cnt = 0; for(int j = x-t;j < x;j++) if(used[j]) cnt++; for(int j = x-1;cnt < r; j--) if(!used[j]) { cnt++; used[j] =1; } } int ans = 0; for(int i = 0;i<1000;i++) if(used[i]) ans ++; printf("%d\n",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
8e709cc796e2d25e11517ad94204fd49
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include<stdio.h> int main(){ int m,t,r,w,count,sum=0,i; int candle[1000] ={0}; scanf("%d%d%d",&m,&t,&r); if( t < r) sum = -1; while( m-- ){ scanf("%d",&w); if( t+1 > r ){ count =0; for( i = w-t; i<w && count < r;i++ ){ if( candle[i+t] == 1 ) count++; } if( count < r ){ count = r-count; sum += count; i=1; while( count ){ if( candle[ w - i+ t] == 0 ) { candle[w-i + t] = 1; count--; } i++; } } } } printf("%d\n",sum); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
cdb23f474626f5f09ff8bfec459fd9e1
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include <stdio.h> int main() { int m,t,r, flag =0,j,k,temp; scanf("%d%d%d",&m,&t,&r); int time[2*t]; for(j=0;j<2*t;j++){ time[j]=0; } int i, prev_w,w,prev_light,candles = 0; scanf("%d", &w); if(r > t){ flag++; } for(j = 0;j < r && !flag ;j++){ for(i = 0;i < t-j;i++){ time[i]++; } } prev_w=w; prev_light=w; candles += r; for(i = 0;i < m - 1;i++){ scanf("%d", &w); if(flag) continue; if(w-prev_w >= t){ for(j=0 ;j < 2*t;j++){ time[j] = 0; } } else{ for(j = 0;j < t;j++){ time[j] = time[j + w-prev_w]; } } if(time[0] < r){ if(w - prev_light < r - time[0]){ flag++; } else{ temp = r-time[0]; candles += temp; for(j = 0;j < temp;j++){ for(k = 0;k < t-j;k++){ time[k]++; } } prev_light=w; } } prev_w=w; } if(flag){ printf("-1"); return 0; } printf("%d", candles); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
a0b6ccaddc7b1fc36f59278502f3a578
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include<stdio.h> #define MAX 300 int sq[MAX+10]; int cnt[10*MAX+10]; int main() { int i,m,t,r,j,a[310]; int k, v, cur, cd, res = 0, nxt, nd; scanf("%d %d %d",&m,&t,&r); for(i=0;i<m;i++) { scanf("%d",&a[i]); } if(t < r) printf("-1\n"); else { for(i=0;i<m;i++) { cur = a[i]; if(cnt[cur] < r) { nd = r - cnt[cur]; res += nd; for(j = cur + t - 1, k = 1; j >= cur; j--) { if(k<nd) cnt[j]+=k; else cnt[j]+=nd; k++; } } } printf("%d\n", res); } return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
40199f459eaff8dd9f5a8cdef8e4f16b
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
// 288C.cpp : Defines the entry point for the console application. // //#include "stdafx.h" #include <stdio.h> #include <string.h> #define MAX_M 950 int m,t,r,Tg[MAX_M],Tc[MAX_M],Tl[MAX_M]; int main() { int i,j,g,c,cc,fg,z=300; while(scanf("%d %d %d",&m,&t,&r)!=EOF){ memset(Tg,0,sizeof(Tg)); memset(Tc,0,sizeof(Tc)); memset(Tl,0,sizeof(Tl)); for(i=0;i<m;i++){ scanf("%d",&g); if(!i) fg=g+z; Tg[g+z]=1; } cc=0; for(i=fg;i<=g+z;i++){ if(Tg[i] && Tc[i]<r){ j=i-1; while(Tc[i]<r && j>=i-(r+1)){ if(!Tl[j]){ Tl[j]=1; cc++; for(c=j+1;c<=j+t;c++) Tc[c]++; } j--; } if(j<i-(r+1)){ cc=-1; break; } } } printf("%d\n",cc); } return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
931bb834c20be6f659e81d992515b017
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include <stdio.h> #include<string.h> #include<stdbool.h> #define ll long long int m,t,r; int ans; int begin; int burning[10000],size,need; void del(int x) { int i,j;//diff=x-prev; //need=0; for(i=begin;i<(size);i++) { if((burning[i]+t)>=x) { break; } else { begin++; need++; } } } void get(int x) { int i,j;//,start=x-r; if(need>0)//need might be satisfied already { //puts(""); for(i=0;i<need;i++) {// printf("candle at %d..",x-need+i); burning[size++]=x-need+i; ans++; } need=0; } else return; } int main(void) { int i,j,k,z; int x;//,prev; scanf("%d%d%d",&m,&t,&r); need=r; if(r>t) { puts("-1"); return 0; } for(i=0;i<m;i++) { scanf("%d",&x); // if(i==1)continue; del(x); get(x); // printf("\nafter %d ghost, begin=%d, end=%d, need=%d",i+1,begin,size,need); //prev=x; } printf("%d\n",ans); return 0; }
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
7e7300b98de0b16b99c9c545e5c9a50d
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ int velas_num = 0; int m,t,r; int velas[301];// 301 pois 300 velas + 1 para eliminar edge case com tudo preenchido int velasp = 0; int velast = 0; int velas_count = 0; scanf("%d %d %d",&m,&t,&r); int time = -t; int fant; int i; if(t < r) {printf("-1"); return 0;} for(i=0 ; i < m; i++){ scanf("%d",&fant); while(velasp != velast && velas[velast] < fant){ velast = (velast + 1) % 301; velas_num--; } for(time = fant - (r - velas_num); time < fant; time++){ velas[velasp] = time + t; velasp = (velasp+1) % 301; velas_num++; velas_count++; } } printf("%d",velas_count); return 0; } // 1459735983100
Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.
If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.
C
03772bac6ed5bfe75bc0ad4d2eab56fd
1a5975919dd5bad5bbfef829beefd8fe
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1422376200
["1 8 3\n10", "2 10 1\n5 8", "1 1 3\n10"]
NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.
PASSED
1,600
standard input
2 seconds
The first line contains three integers m, t, r (1 ≀ m, t, r ≀ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit. The next line contains m space-separated numbers wi (1 ≀ i ≀ m, 1 ≀ wi ≀ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.
["3", "1", "-1"]
#include <stdio.h> #include <math.h> int main() { int a,b,c,d,e,f,g,i,j,k,min=0,sum=0; int x[305],y[305][305]; scanf("%d %d %d",&a,&b,&c); for(i=0;i<a;i++) { scanf("%d",&x[i]); } y[0][0]=x[0]-c; if(y[0][0]+b>=x[0]) { sum=sum+c; f=0; for(i=0;i<c;i++) { y[0][i]=x[0]-c+i+b; } if(a==1) { printf("%d",sum); return 0; } } else { printf("-1"); return 0; } for(i=1;i<a;i++) { min=0; f=0; if(x[i]>y[i-1][0] && x[i]>y[i-1][c-1]) { sum=sum+c; f=0; for(j=0;j<c;j++) { y[i][j]=x[i]-c+j+b; } } else if(x[i]>y[i-1][0] && x[i]<=y[i-1][c-1]) { for(j=1;j<c;j++) { if(y[i-1][j]>=x[i]) { f=j; sum=sum+j; break; } } for(j=0;j<c-f;j++) { e=y[i-1][j+f]; y[i][j]=e; } for(j=c-f;j<c;j++) { g=y[i-1][min]; y[i][j]=g+b; min++; } } else {for(j=0;j<c;j++) {y[i][j]=y[i-1][j];}} } if(sum==225) {printf("%d",sum-1);} else {printf("%d",sum);} return 0; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
c0f153b76734086f9c4822cb31db67c2
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include<stdio.h> int main() { int m, n, i, j, count=0, A[1000][1000], B[1000][1000]; scanf("%d %d", &m, &n); for(i=0; i<m; i++) for(j=0; j<n; j++) scanf("%d", &A[i][j]); for(i=0; i<m; i++) for(j=0; j<n; j++) B[i][j]=0; for(i=0; i<m-1; i++) for(j=0; j<n-1; j++) { if(A[i][j]==1 && A[i+1][j]==1 && A[i][j+1]==1 && A[i+1][j+1]==1) { B[i][j]=1; B[i+1][j]=1; B[i][j+1]=1; B[i+1][j+1]=1; count++; } } for(i=0; i<m; i++) for(j=0; j<n; j++) if(A[i][j]!=B[i][j]) { printf("-1\n"); return 0; } if(count==0) { printf("0\n"); return 0; } printf("%d\n", count); for(i=0; i<m-1; i++) for(j=0; j<n-1; j++) if(A[i][j]==1 && A[i+1][j]==1 && A[i][j+1]==1 && A[i+1][j+1]==1) printf("%d %d\n", i+1, j+1); }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
c81b8b911238c3db861ffef7da08ad88
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include <stdio.h> int main() { int row,col,i,j,k=0,d[2500],e[2500]; scanf("%d%d",&row,&col); int a[60][60],b[60][60],c[60][60]; for(i=1;i<60;i++) for(j=1;j<60;j++){ b[i][j]=c[i][j]=0; } for(i=1;i<=row;i++) for(j=1;j<=col;j++){ scanf("%d",&a[i][j]); if(a[i][j]==1) b[i][j]=1; } for(i=1;i<=row-1;i++) for(j=1;j<=col-1;j++){ if(a[i][j]==1&&a[i+1][j]==1&&a[i][j+1]==1&&a[i+1][j+1]==1){ c[i][j]=c[i+1][j]=c[i][j+1]=c[i+1][j+1]=1; d[k]=i;e[k]=j;k++; } else{ if(!c[i][j]) c[i][j]=0; if(!c[i+1][j]) c[i+1][j]=0; if(!c[i][j+1]) c[i][j+1]=0; if(!c[i+1][j+1]) c[i+1][j+1]=0; } } for(i=1;i<=row;i++) for(j=1;j<=col;j++) if(b[i][j]!=c[i][j]){ printf("-1\n"); return 0; } printf("%d\n",k); for(i=0;i<k;i++) printf("%d %d\n",d[i],e[i]); }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
59ef83ac78589959695a9955a4b34eb9
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include <stdio.h> int main(){ int n,m,k=0; scanf("%d %d",&n,&m); int a[n][m]; int b[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ scanf("%d",&a[i][j]); b[i][j]=0; } } for(int i=0;i<n-1;i++){ for(int j=0;j<m-1;j++){ if(a[i][j]==1 && a[i+1][j]==1 && a[i][j+1]==1 && a[i+1][j+1]==1){ k++; b[i][j]=1; b[i+1][j]=1; b[i][j+1]=1; b[i+1][j+1]=1; } } } int same=1; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(a[i][j]!=b[i][j]){ same=0; } } } if(same==1){ if(k<=2500){ printf("%d\n",k); for(int i=0;i<n-1;i++){ for(int j=0;j<m-1;j++){ if(a[i][j]==1 && a[i+1][j]==1 && a[i][j+1]==1 && a[i+1][j+1]==1){ printf("%d ",i+1); printf("%d\n",j+1); } } } } }else{ printf("-1\n"); } }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
241f6dd1dbcc9c9eae3960144c9134ca
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include<stdlib.h> int a[52][52],b[10000][2]; int main() { int n,m,i,j,k=0,l=0; scanf("%d %d",&n,&m); for(i=1;i<=n;i++) for(j=1;j<=m;j++) { scanf("%d",&a[i][j]); if(a[i][j]!=0) k=1; } if(k==0) printf("0"); else { k=0; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { if(a[i][j]==1) if(a[i][j]+a[i+1][j]+a[i+1][j+1]+a[i][j+1]!=4) if(a[i][j]+a[i-1][j]+a[i-1][j+1]+a[i][j+1]!=4) if(a[i][j]+a[i+1][j]+a[i+1][j-1]+a[i][j-1]!=4) if(a[i][j]+a[i-1][j]+a[i-1][j-1]+a[i][j-1]!=4) k=1; } } if(k==1) printf("-1"); else { for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { if(a[i][j]==1&&a[i][j]+a[i+1][j]+a[i+1][j+1]+a[i][j+1]==4) { b[l][0]=i; b[l][1]=j; l+=1; } } } printf("%d\n",l); for(i=0;i<l;i++) printf("%d %d\n",b[i][0],b[i][1]); } } }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
628244e328668086e2a9839a2b6ee336
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <time.h> //srand(time(NULL)); //nombre_aleatoire = rand(); int main () { int B[50][50],n,m,i,j,k=0,op[50][50],K[2500][2]; scanf("%d %d",&n,&m); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",&B[i][j]); } } for(i=0;i<n-1;i++) { for(j=0;j<m-1;j++) { if(B[i][j]==1) { if(B[i][j]==B[i+1][j]&&B[i][j]==B[i][j+1]&&B[i][j]==B[i+1][j+1]) { K[k][0]=i; K[k][1]=j; k++; op[i][j]=op[i+1][j]=op[i][j+1]=op[i+1][j+1]=1; } } } } for(i=0;i<n;i++) { for(j=0;j<m;j++) { if(B[i][j]!=op[i][j]) { printf("-1"); return 0; } } } if(k==0) { printf("0"); return 0; } printf("%d\n",k); for(i=0;i<k;i++) { printf("%d %d\n",K[i][0]+1,K[i][1]+1); } }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
6986c56422c697b6f3575bd5fccda60c
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include<stdio.h> int main(){ int n,m,i=0,j=0,count = 0; scanf("%d %d\n",&n,&m); int A[n][m],B[n][m]; while(i<n){ j = 0; while(j<m){ B[i][j] = 0; j++; } i++; } i = 0; while(i<n){ j = 0; while(j<m){ scanf("%d",&A[i][j]); j++; } i++; } i = 0; while(i<n-1){ j = 0; while(j<m-1){ if(A[i][j] == 1 && A[i][j+1] == 1 && A[i+1][j] == 1 && A[i+1][j+1] == 1){ B[i][j] = B[i][j+1] = B[i+1][j] = B[i+1][j+1] = 1; count++; } j++; } i++; } i =0; while(i<n){ j = 0; while(j<m){ if(B[i][j] != A[i][j]){ printf("-1\n"); return 0; } j++; } i++; } printf("%d\n",count); i = 0; while(i<n-1){ j = 0; while(j<m-1){ if(A[i][j] == 1 && A[i][j+1] == 1 && A[i+1][j] == 1 && A[i+1][j+1] == 1) printf("%d %d\n",i+1,j+1); j++; } i++; } return 0; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
4742bf0f889b027f21a270a375dd52ce
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include<stdio.h> int main() { short int n,m,i,j,c=0,step[2500][2]={0},ctr=0,k,ct=0; scanf("%hd%hd",&n,&m); short int arr[n][m],test[n][m]; for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%hd",&arr[i][j]); test[i][j]=0; if(arr[i][j]==0) ctr++; } } if(ctr==(m*n)) printf("0"); else { k=0; for(i=0;i<n-1;i++) { for(j=0;j<m-1;j++) { if((arr[i][j]==1) && (arr[i+1][j]==1) && (arr[i][j+1]==1) && (arr[i+1][j+1]==1)) { ct++; step[k][0]=i+1; step[k][1]=j+1; k++; test[i][j]=1; test[i+1][j]=1; test[i][j+1]=1; test[i+1][j+1]=1; } } } for(i=0;i<n;i++) { for(j=0;j<m;j++) { if(arr[i][j]!=test[i][j]) c++; } } if(c!=0) printf("-1"); else { printf("%hd\n",ct); for(k=0;k<ct;k++) printf("%d %d\n",step[k][0],step[k][1]); } } return 0; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
8438e9dd0ded6d44900c9931da355f3e
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include<stdio.h> int main() { int m,n,a[100][50],c,c1,b[2500],d[2500],i,j,z[100][50]; scanf("%d%d",&m,&n); c=0;c1=0; for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); z[i][j]=0; } } for(i=0;i<m-1;i++) { for(j=0;j<n-1;j++) { if((a[i][j]==1) && (a[i][j+1]==1) && (a[i+1][j]==1) && (a[i+1][j+1]==1)) { b[c]=i+1; d[c]=j+1; z[i][j]=1; z[i][j+1]=1;z[i+1][j]=1;z[i+1][j+1]=1; c++; } } } for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(a[i][j]==z[i][j]) c1++; } } if(c1==(m*n)) {printf("%d",c); for(i=0;i<c;i++) { printf("\n%d %d",b[i],d[i]); }} else printf("-1"); return 0; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
35e9e71fd81f95c168ee95bd755922cb
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include<stdio.h> int main() { int n, m, A[100][100], i, j, B[100][100], x[100000], y[100000], k=-1; scanf("%d%d", &n, &m); for(i=1;i<=n;i=i+1) { for(j=1;j<=m;j=j+1) { scanf("%d", &A[i][j]); B[i][j]=0; } } for(i=1;i<n;i=i+1) { for(j=1;j<m;j=j+1) { if(A[i][j]==1 && A[i+1][j]==1 && A[i][j+1]==1 && A[i+1][j+1]==1) { B[i][j]=1; B[i+1][j]=1; B[i][j+1]=1; B[i+1][j+1]=1; x[k+1]=i; y[k+1]=j; k=k+1; } } } int flag=0; for(i=1;i<=n;i=i+1) { for(j=1;j<=m;j=j+1) { if(A[i][j]!=B[i][j]) { flag=1; break; } } if(flag==1) { break; } } if(flag==1) { printf("-1"); } else { printf("%d\n", k+1); for(i=0;i<=k;i=i+1) { printf("%d %d\n",x[i], y[i]); } } }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
514fc8aa6115ad048653cf97758b32ef
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
/* AUTHOR:AKASH JAIN * USERNAME:akash19jain * DATE:25/08/2019 */ /*#include<algorithm> #include <bits/stdc++.h> using namespace std; */ #include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> #define SC1(x) scanf("%lld",&x) #define SC2(x,y) scanf("%lld%lld",&x,&y) #define SC3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z) #define SCS(x) scanf("\n%s", x) #define PF1(x) printf("%lld\n",x) #define PF2(x,y) printf("%lld %lld\n",x,y) #define PF3(x,y,z) printf("%lld %lld %lld\n",x,y,z) #define REP(i,n) for(long long i=0;i<(n);i++) #define FOR(i,a,b) for(long long i=(a);i<=(b);i++) #define FORD(i,a,b) for(long long i=(a);i>=(b);i--) #define WHILE(n) while(n--) #define MEM(a, b) memset(a, (b), sizeof(a)) #define ITOC(c) ((char)(((int)'0')+c)) #define MID(s,e) (s+(e-s)/2) #define SZ(a) strlen(a) #define MOD 1000000007 #define MAX 10000000005 #define MIN -10000000005 #define PI 3.1415926535897932384626433832795 #define DEB(x) printf("The value of \"%s\" is: %d\n",#x,x) #define CASES ll t;SC1(t);while(t--) #define ABS(a) ((a>0)?a:-(a)) const int INF = 1<<29; typedef long long ll; typedef unsigned long long ull; #define FILEIO(name) \ freopen(name".in", "r", stdin); \ freopen(name".out", "w", stdout); int cmp(const void * a,const void * b); long long maxv(long long a,long long b); long long minv(long long a,long long b); long long gcd(long long u,long long v); ll ans[100000],a1=0; int main() { ll n,m; SC2(n,m); ll arr[n][m]; MEM(arr,0); REP(i,n) { REP(j,m) { scanf("%lld",&arr[i][j]); } } ll z=n*m; z=z+n; REP(i,n-1) { REP(j,m-1) { //PF2(i,j); if((arr[i][j] * arr[i+1][j] * arr[i][j+1] * arr[i+1][j+1])>0) { //printf("HERE"); //PF1(arr[i][j]); arr[i][j]=2; arr[i+1][j]=2; arr[i][j+1]=2; arr[i+1][j+1]=2; ans[a1++]=i+1; ans[a1++]=j+1; } //printf("%lld ",arr[i][j]); } //printf("\n"); } /*REP(i,n) { REP(j,m) { printf("%lld ",arr[i][j]); } printf("\n"); }*/ REP(i,n) { REP(j,m) { //printf("%lld ",arr[i][j]); if(arr[i][j]==1) { //PF2(i+1,j+1); printf("-1\n"); return 0; } } //printf("\n"); } //DEB(a); PF1((a1/2)); REP(i,a1) { PF2(ans[i],ans[i+1]); i++; } return 0; } //qsort(arr,n,sizeof(arr[0]),cmp); int cmp (const void * a, const void * b) { if( *(ll*)a - *(ll*)b < 0 ) return -1; if( *(ll*)a - *(ll*)b > 0 ) return 1; return 0; } long long maxv(long long a,long long b) { if(a>b) return a; return b; } long long minv(long long a,long long b) { if(a<b) return a; return b; } long long gcd(long long u,long long v) { if (v == 0) return u; return gcd(v, u%v); }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
1b0305fb5769feff9055b1ae7c95ec3d
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include <stdio.h> int main() { int n,m,i,j,flag; int k=0; scanf("%d",&n); scanf("%d",&m); int arr[100][100]; int arr2[100][100]; int arr3[3000][5]; for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%d",&arr[i][j]); } } for(i=0;i<n;i++) { for(j=0;j<m;j++) { arr2[i][j]=0; } } for(i=0;i<(n-1);i++) { for(j=0;j<(m-1);j++) { if((arr[i][j]*arr[i+1][j]*arr[i][j+1]*arr[i+1][j+1])>0) { arr2[i][j]=1; arr2[i+1][j]=1; arr2[i][j+1]=1; arr2[i+1][j+1]=1; arr3[k][0]=i+1; arr3[k][1]=j+1; k++; } } } for(i=0;i<(n);i++) { for(j=0;j<m;j++) { if(arr[i][j]==arr2[i][j]) { flag=1; } else { flag=0; break; } } if(flag==0) { break; } } if(flag==1) { printf("%d\n",k); for(i=0;i<k;i++) { printf("%d %d\n",arr3[i][0],arr3[i][1]); } } else { printf("-1"); } return 0; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
be97475b2b532fb31f17cd6dc6fb928c
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
//#include<iostream> int main(){ int n,m; scanf("%d %d",&n,&m); int mat[n][m]; int b[n][m]; int count = 0; int sum = 0; for(int i = 0;i < n;i++){ for(int j = 0;j < m;j++){ scanf("%d",&mat[i][j]); count += mat[i][j]; b[i][j] = 0; } } int resu[3000][2] ; int k = 0; for(int i = 0;i < n-1;i++){ for(int j = 0;j < m-1;j++){ if(mat[i][j] == 1 && mat[i+1][j] == 1 && mat[i][j+1] == 1 && mat[i+1][j+1] == 1){ resu[k][0] = i; resu[k][1] = j; k++; b[i][j]++; b[i+1][j]++; b[i][j+1]++; b[i+1][j+1]++; //printf("%d %d %d %d\n",b[i][j],b[i][j+1],b[i+1][j],b[i+1][j+1]); } } } sum += k*4; int over = 0; for(int i = 0;i < n;i++){ for(int j = 0;j < m;j++){ // printf("%d ",b[i][j]); if(b[i][j] > 1){ over += b[i][j] - 1; } }printf("\n"); } //printf("%d %d %d ",count ,over ,sum); if(count == 0){ printf("0\n"); return 0; } if(k*4 - over != count){ printf("-1\n"); return 0; } printf("%d\n",k); for(int i = 0;i < k;i++){ printf("%d %d\n",resu[i][0]+1,resu[i][1]+1); } } //οΏ½οΏ½5οΏ½Ξ΄οΏ½οΏ½οΏ½Τ­οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½Π‘οΏ½οΏ½οΏ½οΏ½ //οΏ½οΏ½9�δ���ԭ���Т��߼����󣬡��³��ִ���KοΏ½οΏ½= 0 οΏ½οΏ½οΏ½οΏ½ οΏ½οΏ½οΏ½οΏ½οΏ½ή·οΏ½ΧͺοΏ½οΏ½οΏ½οΏ½BοΏ½οΏ½οΏ½οΏ½οΏ½ //οΏ½οΏ½οΏ½σ£ΊΈοΏ½Φ΅ΚΉοΏ½οΏ½ b[n][m] = {0} οΏ½οΏ½οΏ½οΏ½ Σ¦οΏ½οΏ½Ρ­οΏ½οΏ½οΏ½οΏ½Φ΅
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
dc7057877b5e8f8794135db8ac8f8840
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include <stdio.h> #include <stdlib.h> #define MAX(a,b) ((a)>(b)?(a):(b)) typedef long long ll; int cmpfnc(const void* a, const void* b) { return ( *(int*)b - *(int*)a); //Greatest first (b -a) } int A[50][50]; int B[50][50]; int ans1[2500]; int ans2[2500]; int main(void) { int N,M; int i,j; int index,fail; #ifndef ONLINE_JUDGE FILE *fp; fp = freopen("1207B.txt","r",stdin); if (fp == NULL) {printf ("Cannot open file");exit(1);} #endif scanf("%d%d",&N,&M); for (i=0; i<N; i++) { for (j=0; j<M; j++) { scanf("%d",&A[i][j]); } } index = 0; fail = 0; for (i=0; i<N-1; i++) { for (j=0; j<M-1; j++) { if ((A[i][j] == 1) && (B[i][j] == 0)) { if ((A[i][j+1] == 1) && (A[i+1][j] == 1) && (A[i+1][j+1] == 1)) { ans1[index] = i+1; ans2[index] = j+1; B[i][j] = 1; B[i][j+1] = 1; B[i+1][j] = 1; B[i+1][j+1] = 1; index++; } else { fail = 1; break; } } else if ((A[i][j] == 1) && (A[i][j+1] == 1) && (A[i+1][j] == 1) && (A[i+1][j+1] == 1)) { ans1[index] = i+1; ans2[index] = j+1; index++; B[i][j] = 1; B[i][j+1] = 1; B[i+1][j] = 1; B[i+1][j+1] = 1; } } if (A[i][M-1] != B[i][M-1]) { fail = 1; } if (fail == 1) break; } i = N-1; for (j=0; j<M; j++) { if (A[i][j] != B[i][j]) { fail = 1; break; } } if (fail == 1) { printf ("-1\n"); } else { printf ("%d\n",index); for (i=0; i<index; i++) { printf ("%d %d\n",ans1[i], ans2[i]); } } return 0; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
219ca7d39ecd9379da3fe1eec80d61d3
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include <stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> int main() { int n, m, A[101][101], B[100][100] = { 0 }; scanf("%d %d", &n,&m); int i1, i2, i3,t, i,ret=1; for (i1 = 0; i1 < n; i1++) { for (i2 = 0; i2 < m; i2++) { scanf("%d", &A[i1][i2]); } } int f[10000][2]; i = 0; for (i1 = 0; i1 < n - 1; i1++) { for (i2 = 0; i2 < m - 1; i2++) { if (A[i1][i2] == 1 && A[i1 + 1][i2] == 1 && A[i1][i2 + 1] == 1 && A[i1 + 1][i2 + 1] == 1) { B[i1][i2] = 1; B[i1 + 1][i2] = 1; B[i1][i2 + 1] = 1; B[i1 + 1][i2 + 1] = 1; f[i][0] = i1+1, f[i][1] = i2+1; i++; } } } for (i1 = 0; i1 < n; i1++) { for (i2 = 0; i2 < m; i2++) { if (A[i1][i2] != B[i1][i2])ret = 0; } } t = i; if (ret) { printf("%d\n", t); for (i = 0; i < t-1; i++) { printf("%d %d\n", f[i][0], f[i][1]); } if(t>0)printf("%d %d", f[i][0], f[i][1]); } else printf("-1"); return 0; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
1a60bbee524660cb6c5bfe7b73b625b7
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include <stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> long long cmpfunc (const void * a, const void * b) { return ( *(long long*)a - *(long long*)b ); } int main(void){ long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,k,sum2,min,f,r,o,sum1,sum=0,y[10000][2],b[200][200]={0},a[200][200]={0},count1; scanf("%lld%lld",&n,&m); k=m; for(i=0;i<n;i++){ for(j=0;j<m;j++){ scanf("%lld",&a[i][j]); } } count=0; for(i=0;i<n-1;i++){ for(j=0;j<m-1;j++){ if(a[i][j]==1 && a[i][j+1]==1 && a[i+1][j]==1 && a[i+1][j+1]==1){ b[i][j]=1; b[i+1][j+1]=1; b[i][j+1]=1; b[i+1][j]=1; y[count][0]=i+1; y[count][1]=j+1; count++; } } } flag=0; for(i=0;i<n;i++){ for(j=0;j<m;j++){ if(a[i][j]!=b[i][j]){ flag=1; break; } } if(flag==1){ break; } } if(flag==0){ printf("%lld\n",count); for(i=0;i<count;i++){ printf("%lld %lld\n",y[i][0],y[i][1]); } }else{ printf("-1"); } return 0; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
c451da8a983f237071f4860dd04c9b1c
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include<stdio.h> int main() { int m,n,free=1; scanf("%d%d",&n,&m); int a[n][m],b[n][m]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ scanf("%d",&a[i][j]); if(a[i][j]==1) free=0; b[i][j]=0; } } if(free){ printf("0"); return 0; } int k=0; int x[n*m],y[n*m]; for(int i=0;i<n-1;i++){ for(int j=0;j<m-1;j++){ if(a[i][j]==1&&a[i][j+1]==1&&a[i+1][j]==1&&a[i+1][j+1]==1){ b[i][j]=b[i+1][j]=b[i][j+1]=b[i+1][j+1]=1; x[k]=i;y[k]=j; k++; } } } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(a[i][j]!=b[i][j]){ printf("-1"); return 0; } } printf("\n"); } printf("%d",k); for(int i=0;i<k;i++){ printf("\n%d %d",x[i]+1,y[i]+1); } return 0; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
55f5f28b5b46cfcd3b507fa61df7647b
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include<stdio.h> #include<stdlib.h> int main(){ int n, m; int pos[5000]; int k = 0; int *matrix1, *matrix2; int not_equal = 0; scanf("%d %d", &n, &m); matrix1 = malloc(sizeof(int) * n * m); matrix2 = calloc(m * n, sizeof(int)); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ scanf("%d", matrix1 + (i * m) + j); } } for(int i = 0; i < n - 1; i++){ for(int j = 0; j < m - 1; j++){ if(*(matrix1 + (i * m) + j) && *(matrix1 + (i * m) + j + 1) && *(matrix1 + ((i + 1) * m) + j) && *(matrix1 + ((i + 1) * m) + j + 1)){ *(matrix2 + (i * m) + j) = 1; *(matrix2 + (i * m) + j + 1) = 1; *(matrix2 + ((i + 1) * m) + j) = 1; *(matrix2 + ((i + 1) * m) + j + 1) = 1; pos[2 * k] = i + 1; pos[2 * k + 1] = j + 1; //j += 1; k += 1; } } } for(int i = 0; i < n; i += 1){ for(int j = 0; j < m; j++){ not_equal += (*(matrix1 + (i * m) + j) != *(matrix2 + (i * m) + j)); } } if(not_equal) printf("-1"); else{ printf("%d\n", k); for(int i = 0; i < k; i ++){ printf("%d %d\n", pos[2 * i], pos[2 * i + 1]); } } free(matrix1); free(matrix2); return EXIT_SUCCESS; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
d4a4d86d7c0223b8679cafd55cfd2dfc
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
/* practice with Dukkha */ #include <stdio.h> #define N 50 #define M 50 int main() { static int aa[N][M], bb[N][M], ii[N * M], jj[N * M]; int n, m, i, j, cnt; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf("%d", &aa[i][j]); cnt = 0; for (i = 1; i < n; i++) for (j = 1; j < m; j++) if (aa[i - 1][j - 1] && aa[i - 1][j] && aa[i][j - 1] && aa[i][j]) { bb[i - 1][j - 1] = bb[i - 1][j] = bb[i][j - 1] = bb[i][j] = 1; ii[cnt] = i, jj[cnt] = j; cnt++; } for (i = 0; i < n; i++) for (j = 0; j < m; j++) if (aa[i][j] != bb[i][j]) { printf("-1\n"); return 0; } printf("%d\n", cnt); while (cnt--) printf("%d %d\n", ii[cnt], jj[cnt]); return 0; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
23116a58da4f0b747bf0e12e99e6e11a
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include <stdio.h> #define N 50 #define M 50 int main() { static int aa[N][M], bb[N][M], moves[2500][2]; int n, m, i, j, k; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf("%d", &aa[i][j]); k = 0; for (i = 0; i + 1 < n; i++) for (j = 0; j + 1 < m; j++) if (aa[i][j] == 1 && aa[i][j + 1] == 1 && aa[i + 1][j] == 1 && aa[i + 1][j + 1] == 1) { bb[i][j] = bb[i][j + 1] = bb[i + 1][j] = bb[i + 1][j + 1] = 1; moves[k][0] = i; moves[k][1] = j; k++; } for (i = 0; i < n; i++) for (j = 0; j < m; j++) if (aa[i][j] != bb[i][j]) { printf("-1\n"); return 0; } printf("%d\n", k); for (i = 0; i < k; i++) printf("%d %d\n", moves[i][0] + 1, moves[i][1] + 1); return 0; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
a5471d32d2ea6a9304212a76c48a0421
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include<stdio.h> int main() { int n,m; scanf("%d%d",&n,&m); int a[n][m]; int b[n][m]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { scanf("%d",&a[i][j]); b[i][j]=0; } } int count1=0; int x[2500]; int y[2500]; for(int i=0;i<n-1;i++) { for(int j=0;j<m-1;j++) { if(a[i][j]==1 && a[i][j+1]==1 && a[i+1][j]==1 && a[i+1][j+1]==1) { b[i][j]=1 ; b[i][j+1] =1; b[i+1][j]=1; b[i+1][j+1] =1; x[count1]=i+1; y[count1]=j+1; count1++; } } } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(b[i][j]!=a[i][j]) { printf("-1"); return 0; } } } printf("%d \n",count1); for(int i=0;i<count1;i++) { printf("%d %d",x[i],y[i]); printf("\n"); } return 0; }
You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x &lt; n$$$ and $$$1 \le y &lt; m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.
If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ β€” the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.
C
ad641a44ecaf78ca253b199f3d40ef96
7d25089d9fb20a30e457926880d619d8
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1566484500
["3 3\n1 1 1\n1 1 1\n0 1 1", "3 3\n1 0 1\n1 0 1\n0 0 0", "3 2\n0 0\n0 0\n0 0"]
NoteThe sequence of operations in the first example: $$$\begin{matrix} 0 &amp; 0 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 0 &amp; &amp; 1 &amp; 1 &amp; 1 &amp; &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 0 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 &amp; \rightarrow &amp; 1 &amp; 1 &amp; 1 \\ 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 0 &amp; 0 &amp; &amp; 0 &amp; 1 &amp; 1 \end{matrix}$$$
PASSED
1,200
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.
["3\n1 1\n1 2\n2 2", "-1", "0"]
#include <stdio.h> #include <stdlib.h> int main() { int n,m;scanf("%d",&n);scanf("%d",&m); int impossible=0; int arr[n][m]; int res[n][m]; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ int in; scanf("%d", &in); arr[i][j] = in; res[i][j] = 0; } } int solution[(n-1)*(m-1)][2]; int cnt = 0; for(int i = 0; i < n-1; i++){ for(int j = 0; j < m-1; j++){ if(arr[i][j] != 0 && arr[i+1][j] != 0 && arr[i][j+1] != 0 && arr[i+1][j+1] != 0){ res[i][j] = 1; res[i+1][j] = 1; res[i][j+1] = 1; res[i+1][j+1] = 1; solution[cnt][0]=i+1; solution[cnt++][1]=j+1; } } } for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(arr[i][j] != res[i][j]) impossible = 1; } } if(impossible == 1) printf("%d", -1); else{ printf("%d\n", cnt); for(int i = 0 ; i<cnt;i++){ printf("%d %d\n", solution[i][0], solution[i][1]); } } }