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
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
45daf60b0468b4bc4f037c7a252ec45e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int main(){ int n,i=1,j,x; scanf("%d",&n); int good[n+1],goodcount=0; while(i<=n){ int goodflag=1; for(j=0; j<n; j++){ scanf("%d",&x); if(x==3||x==1){ goodflag=0; } } good[i++]=goodflag; goodcount+=goodflag; } printf("%d\n", goodcount); for(i=1;i<=n;i++){ if(good[i]) printf("%d ",i); } return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
916d85ef2dcea33a82f056e1aed6e530
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> #include <stdlib.h> int main() { int n, number = 0, i, j; int *ptr, **mass; int *goodCar; scanf("%d", &n); ptr = malloc(n * n * sizeof(int)); goodCar = malloc(n * sizeof(int)); mass = malloc(n * sizeof(int*)); for(i = 0; i < n; i++) { mass[i] = &ptr[i * n]; goodCar[i] = 0; } for(i = 0; i < n; i++) for(j = 0; j < n; j++) scanf("%d", &mass[i][j]); for(i = 0; i < n; i++) { for(j = 0; j < n && (!(mass[i][j] % 2) || i == j); j++); if(j == n) { number++; goodCar[i]++; } } printf("%d\n", number); for(i = 0; i < n; i++) if(goodCar[i]) printf("%d ", i + 1); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
d30f5743c70a24af1d913ca5d6e3fbbc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int main(int argc, char const *argv[]){ int n, i, j, acc = 0; scanf("%d", &n); int m[n][n], goods[n]; for (i=0; i<n; ++i){ for (j=0; j<n; ++j) scanf("%d", &m[i][j]); goods[i] = 0; } for (i=0; i<n; ++i){ for (j=0; j<n; ++j){ if (j != i && (m[i][j] == 1 || m[i][j] == 3)){ goods[i] = 1; break; } } if (goods[i] == 0) ++acc; } printf("%d\n", acc); for (i=0; i<n; ++i){ if (goods[i] == 0) printf("%d ", i+1); } return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
26af909bbf0493999abd4743b14c7bf8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int main() { int n, j, i, k = 0, count = 0, check = 0; scanf("%d", &n); int ara[n][n]; int f[n]; for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { scanf("%d", &ara[i][j]); } } for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { if(ara[i][j] == 1 || ara[i][j] == 3) { check++; } } if(check == 0) { count++; f[k] = i+1; k++; } else { check = 0; } } printf("%d\n", count); for(i = 0; i < count; i++) { printf("%d ", f[i]); } return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
785887b3b20aede12df0a03fc1477d57
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include<stdio.h> int main() { int n,r,c,check=1,i=0; scanf("%d",&n); int a[n][n],save[n]; for(r=0;r<n;++r) { check=1; for(c=0;c<n;++c) { scanf("%d",&a[r][c]); if(a[r][c]==1||a[r][c]==3) check=0; } if(check==1) { save[i]=r+1; ++i; } } printf("%d\n",i); for(r=0;r<i;++r) printf("%d ",save[r]); }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
60a50dc9d9448a83c5e313f480c4c128
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <float.h> int main() { int n, **s, j, a = 0, count = 0, *l; scanf("%d", &n); s = (int**)malloc(sizeof(int*)*n); for (int i = 0; i < n; i++) s[i]= (int*)malloc(sizeof(int)*n); l = (int*)malloc(sizeof(int)*n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%d", &s[i][j]); for (int i = 0; i < n; i++) { a = 0; j = 0; while(j<n) { if (s[i][j] == 1 || s[i][j] == 3) { a = 1; break; } j++; } if (a == 0) { l[count] = i + 1; count++; } } if(count==0) printf("%d", count); else { printf("%d\n", count); for (int i = 0; i < count; i++) printf("%d ",l[i]); } for (int i = 0; i < n; i++) free(s[i]); free(s); free(l); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
effb70fd0d6f1b9483d49b5d5db56617
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { long long int ch[200000]= {0},cp[500000]; char kh[1000],arr[1000000]; int a,b=0,c,d,e,i=0,j=0,k=0,l=0,tep,temp,m,n,x,y; double z,go; scanf("%d",&a); j=0; k=0; l=0; m=n=0; for(j=1; j<=a; j++) { l=0; for(i=0; i<a; i++) { scanf("%d",&b); if(b==1 || b==3) { l=1; } } if(!l) { ch[k]=j; k++; } } printf("%d\n",k); for(i=0;i<k;i++) printf("%d ",ch[i]); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
f1be0d193e2cc06ff2186a8070dd4ae1
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int arr1[100]; int main() { int n, i, j, count = 0; scanf("%d", &n); int arr[n][n]; for(i=0; i<n; i++){ for(j=0; j<n; j++){ scanf("%d", &arr[i][j]); if(arr[i][j] == 0) continue; else if(arr[i][j] == 1) arr1[i] = 1; else if(arr[i][j] == 2) arr1[j] = 1; else if(arr[i][j] == 3){ arr1[i] = 1; arr1[j] = 1; } } } for(i=0; i<n; i++){ if(arr1[i] == 0) count++; } printf("%d\n", count); for(i=0; i<n; i++){ if(arr1[i] == 0) printf("%d ", i + 1); } return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
4527ffc70ea60b9ab090b1e43a89bb05
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include<stdio.h> int main() { int n,data[105][105],l=0,i,j,flag=0,ar[100]; scanf("%d",&n); for(i=1;i<=n;i++) { flag=0; for(j=1;j<=n;j++) { scanf("%d",&data[i][j]); if(data[i][j]==1||data[i][j]==3) { flag=1; } } if(flag==0) { ar[l]=i; l++; } } printf("%d\n",l); for(i=0;i<l;i++) { printf("%d ",ar[i]); if(i==l-1) { printf("\n"); } } return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
89027f82008d85103c9ec4830d3cf64a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> //#include <stdlib.h> #include <string.h> //#include <math.h> //#include <algorithm> //#include <map> //using namespace std; int z[150]; int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); memset(z,0,150*sizeof(int)); int n,f,c,num=0; scanf("%d",&n); for(int x =1;x<=n;x++) { f=0; for(int y =1;y<=n;y++) { scanf("%d",&c); if(c==1||c==3) f=1; } if(f==0) { z[x]=1; num++; } } printf("%d\n",num); for(int x =1;x<=n;x++) if(z[x]==1) printf("%d ",x); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
e4c5e096dd8991532c33addf92aaded3
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#pragma warning(disable:4996) #include <stdio.h> #include <malloc.h> #include <math.h> #include <stdlib.h> #include <string.h> #define forn(i,n) for (i = 0; i<n; i++) int lol(const void *x1, const void *x2) { return *(int*)x1 - *(int*)x2; } int gcd(int a, int b) { int c; while (b) { c = a % b; a = b; b = c; } return a; } int main(void) { int i, j, a[100][100]; int n, b[100] = { 0 }; int count = 0; scanf("%i", &n); forn(i, n) forn(j, n) { scanf("%i", &a[i][j]); if (a[i][j] == 1 || a[i][j] == 3) { if (b[i] == 0) count++; b[i] = 1; } } printf("%i\n", n - count); forn(i, n) if (b[i] == 0) printf("%i ", i+1); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
18697fb425abc3914484ccc8c53cf7f0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int main() { int n ; scanf("%d", &n); int grid[n]; for (int i = 0 ; i < n ; i++) { grid[i] = 0; } for (int i = 0 ; i < n ; i++) { for (int j = 0 ; j < n ; j++) { int temp ; scanf("%d", &temp); if ( temp == 0) { } else if ( temp == 1) { int row = i; //int col = j; grid[row] = 1; } else if ( temp == 2) { // int row = i; int col = j; grid[col] = 1; } else if (temp == 3) { int row = i; int col = j; grid[row] = 1; grid[col] = 1; } } } int count = 0; for (int i = 0 ; i < n ; i++) { if (grid[i] == 0) { count++; } } printf("%d\n",count); for(int i = 0 ; i < n ; i++) { if (grid[i] == 0) { printf("%d ",i+1); } } printf("\n"); }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
2dc31cd8e5309b513bb2c54c33bb6e93
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include<stdio.h> int main() { int n; scanf("%d",&n); int i,j; int a[n][n],b[n]; for(i=0;i<=n;i++) b[i]=0; for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); if(a[i][j]==1) { b[i+1]=1; } if(a[i][j]==2) { b[j+1]=1; } if(a[i][j]==3) { b[j+1]=1; b[i+1]=1; } } } int q=0; for(i=1;i<=n;i++) { if(b[i]==0) {q++;} } printf("%d\n",q); for(i=1;i<=n;i++) { if(b[i]==0) { printf("%d ",i); q++; } } return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
df33f79e3ccdfcb78b1cf157db0d0fe4
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
// // main.c // hr // // Created by Chaitya on 5/15/15. // Copyright (c) 2015 Chaitya. All rights reserved. // /* There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task? Input The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0. Output Print the number of good cars and in the next line print their space-separated indices in the increasing order. */ #include<stdio.h> #include<stdlib.h> int main() { int T,N,i,j,sum=0; //printf("c"); scanf("%d",&T); int arr[T][T]; int ans[T]; for(i=0;i<T;i++) ans[i]=-2; for(i=0;i<T;i++) { for(j=0;j<T;j++) { scanf("%d",&arr[i][j]); if (arr[i][j]==1) { ans[i]=4; } else if(arr[i][j]==2) { ans[j]=4; } else if(arr[i][j]==3) { ans[i]=4; ans[j]=4; } } } for (int i=0; i<T; i++) { if(ans[i]!=4){ sum++; ans[i]=5; } } printf("%d\n",sum); for (int i=0; i<T; i++) { if(ans[i]==5){ printf("%d ",i+1); }} return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
03f00b82df2d7de427c1acf8d752628e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int mn(int a, int b){if(a<b) return a; else return b;} const int M = 101; int main(){ int i,j,n,c,b[M][M]; for(i=0;i<M;i++) for(j=0;j<M;j++) b[i][j]=0; scanf("%i",&n); c = n; for(i=0;i<n;i++){ for(j=0;j<n;j++){ int a; scanf("%i",&a); b[i][j]=a; if(a==3 || a==1) b[i][M-1]++; } } for(i=0;i<n;i++) if(b[i][M-1]) c--; printf("%i\n",c); if(c) for(i=0;i<n;i++) if(b[i][M-1]==0) printf("%i ",i+1); return 0-0-0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
5ce0aaa912a297b58fa42784b5b264fc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include<stdio.h> int main() { int n,count=0,c,i,j,a,A[100]; scanf("%d",&n); for(i=0;i<n;i++) { c=0; for(j=0;j<n;j++) { scanf("%d",&a); if(a==1||a==3) c=1; } if(!c) A[count++]=i; } printf("%d\n",count); for(i=0;i<count;i++) printf("%d ",A[i]+1); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
5cc73f1c10cf86c3cba81339400c5b1c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int main(int argc, char const *argv[]) { int n,v; scanf("%d", &n); int c[n+1]; for (int i = 1; i <= n; ++i) c[i]=1; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { scanf("%d", &v); switch (v) { case 0: c[i]&=1,c[j]&=1; break; case 1: c[i]&=0,c[j]&=1; break; case 2: c[i]&=1,c[j]&=0; break; case 3: c[i]&=0,c[j]&=0; break; } } int d = 0; for (int i = 1; i <= n; ++i) if (c[i]) d++; printf("%d\n",d); for (int i = 1; i <= n; ++i) if (c[i]) printf("%d ", i); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
c4922748091634dedf125c46f646a60a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include<stdio.h> int main() { int i,j,n; scanf("%d",&n); int ans[n]; int count=0; int arr[n][n]; for(i=0;i<n;i++) { ans[i]=1; for(j=0;j<n;j++) { scanf("%d",&arr[i][j]); if(arr[i][j]==1) { ans[i]=0; } else if(arr[i][j]==2) { ans[j]=0; } else if(arr[i][j]==3) { ans[i]=0; ans[j]=0; } } } for(i=0;i<n;i++) { if(ans[i]==1) count++; } //count=count-c1-c2-c3; //count=count-(c1+c2+c3)/2; printf("%d\n",count); for(i=0;i<n;i++) { if(ans[i]==1) { count--; if(count>0) printf("%d ",i+1); else printf("%d\n",i+1); } } return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
e09ad557c1b8a25a3da669d60a3fa0c4
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int main(void) { int n; scanf("%d ", &n); int arr[n][n], car[n]; for (int i = 0; i < n; i++) car[i] = 1; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++){ scanf("%d ", &arr[i][j]); if (arr[i][j] == 1 || arr[i][j] == 3) car[i] = 0; } int num = 0; for (int i = 0; i < n; i++) if (car[i]) num++; printf("%d\n", num); for (int i = 0; i < n; i++) if (car[i]) printf("%d ", i+1); printf("\n"); }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
bfd2c83c4c6f25b54ab0ab8b3d5d8d95
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> #define N 200 int main() { static int ii[N]; int n, k, i; scanf("%d", &n); k = 0; for (i = 1; i <= n; i++) { static int aa[N]; int j, yes; for (j = 0; j < n; j++) scanf("%d", &aa[j]); yes = 1; for (j = 0; j < n; j++) if (aa[j] != -1 && aa[j] != 0 && aa[j] != 2) { yes = 0; break; } if (yes) ii[k++] = i; } printf("%d\n", k); for (i = 0; i < k; i++) printf("%d ", ii[i]); printf("\n"); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
88749b2a8df8e4351584659d3ad3550a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> #include <stdlib.h> int main(){ int n, *gc, car, count; scanf("%d", &n); count = n; gc = (int*) malloc(n*sizeof(int)); for(int i=0; i < n; i++) gc[i] = 1; for(int r=0; r < n; r++){ for(int c=0; c < n; c++){ scanf("%d", &car); if (car >= 2 && gc[c] == 1){ gc[c] = 0; count--; } } } printf("%d\n", count); for(int c=0; count; c++){ if (gc[c] == 1){ printf("%d ", c+1); count--; } } return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
3eb48ac870c25db20dfa982b0297e8cd
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include<stdio.h> int main(n) {scanf("%d",&n); int a,i,j,b[100]={0},t=1,c=0; for(i=0;i<n;i++) { t=1; for(j=0;j<n;j++) { scanf("%d",&a); if(a==3 || a==1) t=0; } if(t) { b[i]=i+1; c++; } } printf("%d\n",c); for(i=0;i<n;i++) if(b[i]) printf("%d ",b[i]); }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
a16677982af0b9c4a0dd1383497dda0e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int main() { int Mat[100][100]; int i, j, N, Cnt; int Ans[100]; scanf("%d", &N); for(i = 0; i < N; ++i) { for(j = 0; j < N; ++j) { scanf("%d", &Mat[i][j]); } } Cnt = 0; for(i = 0; i < N; ++i) { for(j = 0; j < N; ++j) { if(i != j && Mat[i][j] & 1) { break; } } if(j == N) { for(j = 0; j < N; ++j) { if(Mat[j][i] > 1) { break; } } if(j == N) { Ans[Cnt++] = i + 1; } } } printf("%d\n", Cnt); for(i = 0; i < Cnt; ++i) { printf("%d ", Ans[i]); } printf("\n"); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
9af2dc87d9e48280128fc33c2c36743f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int ans[101], k; int main() { int n, a[101][101], i, j, cnt=0, t=1; scanf("%d", &n); for(i=0; i<n; i++) { for(j=0; j<n; j++) scanf("%d", &a[i][j]); } for(i=0; i<n; i++) { for(j=0; j<n; j++) { if(a[i][j]==1 || a[i][j]==3) t=0; } if(t) { cnt++; ans[k++]=i+1; } t=1; } printf("%d\n", cnt); for(i=0; i<k; i++) printf("%d ",ans[i]); printf("\n"); return 0; }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
f103f714f2df25cf6e5b236eb4f71c04
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include<stdio.h> int main() { int n,i,j,c=0; scanf("%d",&n); int x[n][n],y[n]; for(i=0;i<n;i++) {y[i]=0; for(j=0;j<n;j++) { scanf("%d",&x[i][j]); if(x[i][j]==1) y[i]=1; else if(x[i][j]==2) y[j]=1; else if(x[i][j]==3) {y[i]=1; y[j]=1;} } } for(i=0;i<n;i++) if(!y[i]) c++; printf("%d\n",c); for(i=0;i<n;i++) if(!y[i]) printf("%d ",i+1); }
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the Ρ–-th row and j-th column that describes the result of the collision of the Ρ–-th and the j-th car:  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?
Print the number of good cars and in the next line print their space-separated indices in the increasing order.
C
3fc0ac711b113fa98f41740536dad44f
e1572f434df8b526d94ad1d4d2a0388a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1432053000
["3\n-1 0 0\n0 -1 1\n0 2 -1", "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1"]
null
PASSED
900
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 100) β€” the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.
["2\n1 3", "0"]
#include <stdio.h> int main() { long n, x[102]={0}, y, i, j, g=0; scanf("%d", &n); for(i=1; i<=n; i++) { for(j=1; j<=n; j++) { scanf("%d", &y); if(y==1)x[i]++; if(y==2)x[j]++; if(y==3)x[i]++, x[j]++; } } for(i=1; i<=n; i++)if(x[i]==0)g++; printf("%d\n", g); for(i=1; i<=n; i++)if(x[i]==0)printf("%d ", i); }
Tenten runs a weapon shop for ninjas. Today she is willing to sell $$$n$$$ shurikens which cost $$$1$$$, $$$2$$$, ..., $$$n$$$ ryo (local currency). During a day, Tenten will place the shurikens onto the showcase, which is empty at the beginning of the day. Her job is fairly simple: sometimes Tenten places another shuriken (from the available shurikens) on the showcase, and sometimes a ninja comes in and buys a shuriken from the showcase. Since ninjas are thrifty, they always buy the cheapest shuriken from the showcase.Tenten keeps a record for all events, and she ends up with a list of the following types of records: + means that she placed another shuriken on the showcase; - x means that the shuriken of price $$$x$$$ was bought. Today was a lucky day, and all shurikens were bought. Now Tenten wonders if her list is consistent, and what could be a possible order of placing the shurikens on the showcase. Help her to find this out!
If the list is consistent, print "YES". Otherwise (that is, if the list is contradictory and there is no valid order of shurikens placement), print "NO". In the first case the second line must contain $$$n$$$ space-separated integers denoting the prices of shurikens in order they were placed. If there are multiple answers, print any.
C
5fa2af185c4e3c8a1ce3df0983824bad
8a2b70492974c3430d6d869a4a96d701
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation", "greedy" ]
1603623900
["4\n+\n+\n- 2\n+\n- 3\n+\n- 1\n- 4", "1\n- 1\n+", "3\n+\n+\n+\n- 2\n- 1\n- 3"]
NoteIn the first example Tenten first placed shurikens with prices $$$4$$$ and $$$2$$$. After this a customer came in and bought the cheapest shuriken which costed $$$2$$$. Next, Tenten added a shuriken with price $$$3$$$ on the showcase to the already placed $$$4$$$-ryo. Then a new customer bought this $$$3$$$-ryo shuriken. After this she added a $$$1$$$-ryo shuriken. Finally, the last two customers bought shurikens $$$1$$$ and $$$4$$$, respectively. Note that the order $$$[2, 4, 3, 1]$$$ is also valid.In the second example the first customer bought a shuriken before anything was placed, which is clearly impossible.In the third example Tenten put all her shurikens onto the showcase, after which a customer came in and bought a shuriken with price $$$2$$$. This is impossible since the shuriken was not the cheapest, we know that the $$$1$$$-ryo shuriken was also there.
PASSED
1,700
standard input
1 second
The first line contains the only integer $$$n$$$ ($$$1\leq n\leq 10^5$$$) standing for the number of shurikens. The following $$$2n$$$ lines describe the events in the format described above. It's guaranteed that there are exactly $$$n$$$ events of the first type, and each price from $$$1$$$ to $$$n$$$ occurs exactly once in the events of the second type.
["YES\n4 2 3 1", "NO", "NO"]
#include <stdio.h> #define N 100000 int main() { static int aa[N * 2], qu[N]; int n, i, cnt; scanf("%d", &n); for (i = 0; i < n * 2; i++) { static char s[2]; scanf("%s", s); if (s[0] != '+') scanf("%d", &aa[i]); } cnt = 0; for (i = n * 2 - 1; i >= 0; i--) if (aa[i] > 0) { if (cnt && qu[cnt - 1] < aa[i]) { printf("NO\n"); return 0; } qu[cnt++] = aa[i]; } else aa[i] = -qu[--cnt]; printf("YES\n"); for (i = 0; i < n * 2; i++) if (aa[i] < 0) printf("%d ", -aa[i]); printf("\n"); return 0; }
Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m points p1, p2, ..., pm with integer coordinates, do the following: denote its initial location by p0. First, the robot will move from p0 to p1 along one of the shortest paths between them (please notice that since the robot moves only along the grid lines, there can be several shortest paths). Then, after it reaches p1, it'll move to p2, again, choosing one of the shortest ways, then to p3, and so on, until he has visited all points in the given order. Some of the points in the sequence may coincide, in that case Robot will visit that point several times according to the sequence order.While Santa was away, someone gave a sequence of points to Robot. This sequence is now lost, but Robot saved the protocol of its unit movements. Please, find the minimum possible length of the sequence.
The only line of input should contain the minimum possible length of the sequence.
C
b1c7ca90ce9a67605fa058d4fd38c2f2
706ddf307861deedc323d03ba8233e6a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "shortest paths" ]
1482656700
["4\nRURD", "6\nRRULDD", "26\nRRRULURURUULULLLDLDDRDRDLD", "3\nRLL", "4\nLRLR"]
NoteThe illustrations to the first three tests are given below. The last example illustrates that each point in the sequence should be counted as many times as it is presented in the sequence.
PASSED
1,400
standard input
2 seconds
The first line of input contains the only positive integer n (1 ≀ n ≀ 2Β·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of n letters, each being equal either L, or R, or U, or D. k-th letter stands for the direction which Robot traveled the k-th unit segment in: L means that it moved to the left, RΒ β€” to the right, UΒ β€” to the top and DΒ β€” to the bottom. Have a look at the illustrations for better explanation.
["2", "2", "7", "2", "4"]
/* Coached by rainboy */ #include <stdio.h> #define N 200000 int main() { static char s[N + 1]; int n, i, left, right, up, down, ans; scanf("%d%s", &n, s); ans = left = right = up = down = 0; for (i = 0; i < n; i++) { if ((s[i] == 'L' && right) || (s[i] == 'R' && left) || (s[i] == 'U' && down) || (s[i] == 'D' && up)) ans++, left = right = up = down = 0; if (s[i] == 'L') left = 1; else if (s[i] == 'R') right = 1; else if (s[i] == 'U') up = 1; else down = 1; } printf("%d\n", ans + 1); return 0; }
Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m points p1, p2, ..., pm with integer coordinates, do the following: denote its initial location by p0. First, the robot will move from p0 to p1 along one of the shortest paths between them (please notice that since the robot moves only along the grid lines, there can be several shortest paths). Then, after it reaches p1, it'll move to p2, again, choosing one of the shortest ways, then to p3, and so on, until he has visited all points in the given order. Some of the points in the sequence may coincide, in that case Robot will visit that point several times according to the sequence order.While Santa was away, someone gave a sequence of points to Robot. This sequence is now lost, but Robot saved the protocol of its unit movements. Please, find the minimum possible length of the sequence.
The only line of input should contain the minimum possible length of the sequence.
C
b1c7ca90ce9a67605fa058d4fd38c2f2
1b83de532cbde449cec02d5b500d8b1b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "shortest paths" ]
1482656700
["4\nRURD", "6\nRRULDD", "26\nRRRULURURUULULLLDLDDRDRDLD", "3\nRLL", "4\nLRLR"]
NoteThe illustrations to the first three tests are given below. The last example illustrates that each point in the sequence should be counted as many times as it is presented in the sequence.
PASSED
1,400
standard input
2 seconds
The first line of input contains the only positive integer n (1 ≀ n ≀ 2Β·105) which equals the number of unit segments the robot traveled. The second line contains the movements protocol, which consists of n letters, each being equal either L, or R, or U, or D. k-th letter stands for the direction which Robot traveled the k-th unit segment in: L means that it moved to the left, RΒ β€” to the right, UΒ β€” to the top and DΒ β€” to the bottom. Have a look at the illustrations for better explanation.
["2", "2", "7", "2", "4"]
#include <stdio.h> #include <math.h> int main() { long int n,count=1; scanf("%ld\n",&n); char a[n],b[2]; int flag[2]; flag[0]=0; flag[1]=0; scanf("%s",a); for (int i = 0; i < n; ++i) { if (flag[0]==0) { if (a[i]=='R') { flag[0]=1; b[0]='R'; continue; } if (a[i]=='L') { flag[0]=1; b[0]='L'; continue; } } if (flag[1]==0) { if (a[i]=='U') { flag[1]=1; b[1]='U'; continue; } if (a[i]=='D') { flag[1]=1; b[1]='D'; continue; } } if ((a[i]!=b[0])&&(a[i]!=b[1])) { count++; if (a[i]=='R') { b[0]='R'; flag[1]=0; continue; } if (a[i]=='L') { b[0]='L'; flag[1]=0; continue; } if (a[i]=='U') { b[1]='U'; flag[0]=0; continue; } if (a[i]=='D') { b[1]='D'; flag[0]=0; continue; } } } printf("%ld\n",count ); return 0; }
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is .The pseudo code of the unexpected code is as follows:input nfor i from 1 to n input the i-th point's coordinates into p[i]sort array p[] by increasing of x coordinate first and increasing of y coordinate secondd=INF //here INF is a number big enoughtot=0for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x&gt;=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j]))output dHere, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded.You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded?
If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≀ 109) representing the coordinates of the i-th point. The conditions below must be held: All the points must be distinct. |xi|, |yi| ≀ 109. After running the given code, the value of tot should be larger than k.
C
a7846e4ae1f3fa5051fab9139a25539c
89da7f9404918dc77a31c81521aa1eeb
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation" ]
1369582200
["4 3", "2 100"]
null
PASSED
1,300
standard input
2 seconds
A single line which contains two space-separated integers n and k (2 ≀ n ≀ 2000, 1 ≀ k ≀ 109).
["0 0\n0 1\n1 0\n1 1", "no solution"]
#include <stdio.h> int main() { int n,k; int i; while(scanf("%d %d",&n,&k)!=EOF) { if((n-1)*n/2<=k) { printf("no solution\n"); continue; } else { for(i=0;i<n;i++) { printf("%d %d\n",0,i); } } } return 0; }
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is .The pseudo code of the unexpected code is as follows:input nfor i from 1 to n input the i-th point's coordinates into p[i]sort array p[] by increasing of x coordinate first and increasing of y coordinate secondd=INF //here INF is a number big enoughtot=0for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x&gt;=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j]))output dHere, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded.You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded?
If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≀ 109) representing the coordinates of the i-th point. The conditions below must be held: All the points must be distinct. |xi|, |yi| ≀ 109. After running the given code, the value of tot should be larger than k.
C
a7846e4ae1f3fa5051fab9139a25539c
11b632325aa1028553db3db44c386514
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation" ]
1369582200
["4 3", "2 100"]
null
PASSED
1,300
standard input
2 seconds
A single line which contains two space-separated integers n and k (2 ≀ n ≀ 2000, 1 ≀ k ≀ 109).
["0 0\n0 1\n1 0\n1 1", "no solution"]
#include<stdio.h> int main(){ int n,i; long int k,sum=0; scanf("%d%ld",&n,&k); sum=(n-1)*n/2; if(sum<=k) printf("no solution"); else{ for(i=1;i<=n;i++) printf("%d %d\n",1,i); } return 0; }
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is .The pseudo code of the unexpected code is as follows:input nfor i from 1 to n input the i-th point's coordinates into p[i]sort array p[] by increasing of x coordinate first and increasing of y coordinate secondd=INF //here INF is a number big enoughtot=0for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x&gt;=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j]))output dHere, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded.You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded?
If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≀ 109) representing the coordinates of the i-th point. The conditions below must be held: All the points must be distinct. |xi|, |yi| ≀ 109. After running the given code, the value of tot should be larger than k.
C
a7846e4ae1f3fa5051fab9139a25539c
894236610b46c04d24244f812d0e326f
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation" ]
1369582200
["4 3", "2 100"]
null
PASSED
1,300
standard input
2 seconds
A single line which contains two space-separated integers n and k (2 ≀ n ≀ 2000, 1 ≀ k ≀ 109).
["0 0\n0 1\n1 0\n1 1", "no solution"]
#include <stdio.h> int main() { int n, k, i; scanf("%d %d", &n, &k); if (k >= n * (n - 1) / 2) { puts("no solution"); } else { for (i = 0; i < n; i++) printf("0 %d\n", i); } return 0; }
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is .The pseudo code of the unexpected code is as follows:input nfor i from 1 to n input the i-th point's coordinates into p[i]sort array p[] by increasing of x coordinate first and increasing of y coordinate secondd=INF //here INF is a number big enoughtot=0for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x&gt;=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j]))output dHere, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded.You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded?
If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≀ 109) representing the coordinates of the i-th point. The conditions below must be held: All the points must be distinct. |xi|, |yi| ≀ 109. After running the given code, the value of tot should be larger than k.
C
a7846e4ae1f3fa5051fab9139a25539c
e2f4614feb38e7f286cd4f45ece7c13b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation" ]
1369582200
["4 3", "2 100"]
null
PASSED
1,300
standard input
2 seconds
A single line which contains two space-separated integers n and k (2 ≀ n ≀ 2000, 1 ≀ k ≀ 109).
["0 0\n0 1\n1 0\n1 1", "no solution"]
#include<stdio.h> int main() { int n,k,res,i; scanf("%d %d",&n,&k); res=(n*(n-1))/2; if(res<=k) printf("no solution\n"); else for(i=0;i<n;i++) { printf("%d %d\n",1,i*2); } return 0; }
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is .The pseudo code of the unexpected code is as follows:input nfor i from 1 to n input the i-th point's coordinates into p[i]sort array p[] by increasing of x coordinate first and increasing of y coordinate secondd=INF //here INF is a number big enoughtot=0for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x&gt;=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j]))output dHere, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded.You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded?
If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≀ 109) representing the coordinates of the i-th point. The conditions below must be held: All the points must be distinct. |xi|, |yi| ≀ 109. After running the given code, the value of tot should be larger than k.
C
a7846e4ae1f3fa5051fab9139a25539c
1ae85433f5957a0a5c8765c9654dffe4
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation" ]
1369582200
["4 3", "2 100"]
null
PASSED
1,300
standard input
2 seconds
A single line which contains two space-separated integers n and k (2 ≀ n ≀ 2000, 1 ≀ k ≀ 109).
["0 0\n0 1\n1 0\n1 1", "no solution"]
#include <stdio.h> int main() { int N,K,i; scanf("%d %d",&N,&K); i=(1+N-1)*(N-1)/2; if(i<=K) { puts("no solution"); } else { for(i=0;i<N;++i) { printf("0 %d\n",i,i); } } return 0; }
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.The problem is the follows. Given n points in the plane, find a pair of points between which the distance is minimized. Distance between (x1, y1) and (x2, y2) is .The pseudo code of the unexpected code is as follows:input nfor i from 1 to n input the i-th point's coordinates into p[i]sort array p[] by increasing of x coordinate first and increasing of y coordinate secondd=INF //here INF is a number big enoughtot=0for i from 1 to n for j from (i+1) to n ++tot if (p[j].x-p[i].x&gt;=d) then break //notice that "break" is only to be //out of the loop "for j" d=min(d,distance(p[i],p[j]))output dHere, tot can be regarded as the running time of the code. Due to the fact that a computer can only run a limited number of operations per second, tot should not be more than k in order not to get Time Limit Exceeded.You are a great hacker. Would you please help Tiny generate a test data and let the code get Time Limit Exceeded?
If there doesn't exist such a data which let the given code get TLE, print "no solution" (without quotes); else print n lines, and the i-th line contains two integers xi, yi (|xi|, |yi| ≀ 109) representing the coordinates of the i-th point. The conditions below must be held: All the points must be distinct. |xi|, |yi| ≀ 109. After running the given code, the value of tot should be larger than k.
C
a7846e4ae1f3fa5051fab9139a25539c
fbd6e4478576d6b01f4c8c33c030d78e
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation" ]
1369582200
["4 3", "2 100"]
null
PASSED
1,300
standard input
2 seconds
A single line which contains two space-separated integers n and k (2 ≀ n ≀ 2000, 1 ≀ k ≀ 109).
["0 0\n0 1\n1 0\n1 1", "no solution"]
#include<stdio.h> #include <ctype.h> #include<string.h> int main(){ int n,k,i=0,l=1000000000; scanf("%d %d",&n,&k); if(k>=((n*(n-1))/2)){ printf("no solution"); return 0; } else{ for (i=0; i<n; i++) { printf("%d %d\n",0,i); } } return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
117b3bb3707f9633897815484897410f
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> int main() { long long int x,y,z,p,q; scanf("%lld %lld %lld",&x,&y,&z); p=x%z; q=y%z; printf("%lld ",(x/z)+(y/z)+((p+q)/z)); if((p+q)/z==1) { if(p>=q) { printf("%lld",z-p); } else { printf("%lld",z-q); } } else { printf("0"); } }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
52c62b639f66b650e2c9c2a07fac3b49
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> #define ll long long int main() { ll n, m, s; scanf("%lld %lld %lld", &n, &m, &s); if(n < m){ ll temp = n % s, min = m % s; if(temp != 0){ m += temp; n -= temp; } if(temp + min >= s){ if(temp >= min){ min = s - temp; }else{ min = s - min; } }else{ min = 0; } ll max = (n / s) + (m / s); printf("%lld %lld\n", max, min); }else{ ll temp = m % s, min = n % s; if(temp != 0){ n += temp; m -= temp; } if(temp + min >= s){ if(temp >= min){ min = s - temp; }else{ min = s - min; } }else{ min = 0; } ll max = (n / s) + (m / s); printf("%lld %lld\n", max, min); } }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
0f6c3cb1fd14fee55478c378594003a4
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <stdio.h> int main() { long long int x,y,z,i,j; scanf("%I64d %I64d %I64d",&x,&y,&z); i=(unsigned long long int)(x+y)/z; if(x%z+y%z>=z) { if(x%z>=y%z) { j=z-x%z; } else j=z-y%z; } else j=0; printf("%I64d %I64d",i,j); return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
20a50f3ecb0d93279f3f5f32627914b3
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> int main(){ long long int x, y, z, rx, ry, cocos, p; scanf("%I64d %I64d %I64d", &x, &y, &z); cocos = (x + y)/z; if(x/z + y/z == cocos) printf("%I64d 0", cocos); else{ rx = z - (x % z); ry = z - (y % z); if(rx < ry) p = rx; else p = ry; //printf("%d %d\n", rx, ry); printf("%I64d %I64d", cocos, p); } return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
a53a38ad0f1fabbea58fa3e52b88b26a
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> #define max(a,b) a>b?a:b int main() { long long int x,y,z,a,b,r=0,sum=0; scanf("%lld%lld%lld",&x,&y,&z); sum=(x/z)+(y/z); a=x%z; b=y%z; if(a+b>=z) { r=max(a,b); r=z-r; printf("%lld %lld\n",sum+1,r); } else printf("%lld %lld\n",sum,r); }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
d1aaa4bddb628ed0405dc017cf8bfebd
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> int main() { long long int x,y,z,n,e,a,b,c,d; scanf("%lld %lld %lld",&x,&y,&z); n=(x+y)/z; a=x%z; b=y%z; c=(a==0)?0:(z-a); d=(b==0)?0:(z-b); if(a+b>=z) { if(a<=b && a<=c && a<=d) e=a; else if(b<=c && b<=d) e=b; else if(c<=d) e=c; else e=d; } else e=0; printf("%lld %lld",n,e); return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
6d103feeace67740fa5f18fc6211035e
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <stdio.h> int main() { long long int x,y,z,l,a,b,k=0; scanf("%I64d %I64d %I64d",&x,&y,&z); l=(x+y)/z; a=x%z; b=y%z; if((a+b)>=z) { if(a>b) { k=z-a; } else { k=z-b; } } printf("%I64d %I64d\n",l,k); return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
f8c3e3f0c895f218902e41a27bef2761
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <stdio.h> int main() { long long int x,y,z,l,a,b,k=0; scanf("%I64d %I64d %I64d",&x,&y,&z); l=(x+y)/z; a=x%z; b=y%z; if((a+b)>=z) { if(a>b) { k=z-a; } else { k=z-b; } } printf("%I64d %I64d\n",l,k); return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
45bfeeb3f3024cd032baa41750c8542a
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <inttypes.h> #include <stdio.h> int main() { int64_t x,y,z,a,b,c,k; scanf ("%I64d %I64d %I64d",&x,&y,&z); a=x%z; b=y%z; c=x/z+y/z; if ((a==0)||(b==0)) k=0; else { if (((a<=b)&&(a>=z-b)) || ((b<=a)&&(b>=z-a))) { ++c; if (a<=b) k=z-b; else k=z-a; } else k=0; } printf ("%I64d %I64d",c,k); return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
56a9103b3af297f3b9cb79f8b859d175
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <stdio.h> #include <stdlib.h> int main(int argc, char const *argv[]) { unsigned long long int x , y , z ; scanf("%I64d %I64d %I64d",&x,&y,&z); //io unsigned long long int modx , mody,increase,difference,temp,buy; modx = x%z; mody = y%z ; if (modx > mody) { modx = (modx + mody); increase = modx / z ; buy = x/z + y/z + increase; if (increase) { difference = modx % z ; y -= (y - mody + difference); } else { difference = 0; y= 0; } printf("%I64d %I64d",buy,y); } else { temp = x; x = y; y = temp; temp = modx; modx = mody; mody = temp; modx = (modx + mody); increase = modx / z ; buy = x/z + y/z + increase; if (increase) { difference = modx % z ; y -= (y - mody + difference); } else { difference = 0; y= 0; } printf("%I64d %I64d",buy,y); } return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
8165f5b5fdaa180bf0f2c126d3cd7efb
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <stdio.h> #include <stdlib.h> int main(int argc, char const *argv[]) { unsigned long long int x , y , z ; scanf("%I64d %I64d %I64d",&x,&y,&z); unsigned long long int modx , mody,increase,difference,temp,buy; modx = x%z; mody = y%z ; if (modx > mody) { modx = (modx + mody); increase = modx / z ; buy = x/z + y/z + increase; if (increase) { difference = modx % z ; y -= (y - mody + difference); } else { difference = 0; y= 0; } printf("%I64d %I64d",buy,y); } else { temp = x; x = y; y = temp; temp = modx; modx = mody; mody = temp; modx = (modx + mody); increase = modx / z ; buy = x/z + y/z + increase; if (increase) { difference = modx % z ; y -= (y - mody + difference); } else { difference = 0; y= 0; } printf("%I64d %I64d",buy,y); } return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
ecac32ec4e4bfa38c81c3320bc63dcd9
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> int main() { long long int a,b,c,d,e,f,g=0,h=0; scanf("%lld%lld%lld",&a,&b,&c); d=(a+b)/c; e=a%c; f=b%c; if((e+f)>=c) { if(e>f) g=c-e; else g=c-f; } printf("%lld %lld",d,g); }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
6014c55f5e77fc310c8d03d50a93c8a4
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <stdio.h> int main(void){ long long x,y,z; long long sum; long long a1,a2; scanf("%I64d %I64d %I64d",&x,&y,&z); sum=x+y; if(sum%z==0){ long long M=x>y?x:y; a1=sum/z; a2=(M%z)<(z-(M%z))?(M%z):(z-(M%z)); printf("%I64d %I64d\n",a1,a2); }else{ long long m1=(x%z)<(z-(x%z))?(x%z):(z-(x%z)); long long m2=(y%z)<(z-(y%z))?(y%z):(z-(y%z)); long long mm=m1<m2?m1:m2; a1=sum/z; if((x%z)+(y%z)<z) mm=0; printf("%I64d %I64d\n",a1,mm); } return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
f16e9f39daa810b21478b2e29ee1a02a
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> long long x,y,z,c=0,p=0; int main() { scanf("%I64d %I64d %I64d",&x,&y,&z); c+=(x/z); c+=(y/z); long long a=(x%z),b=(y%z); if(a+b>=z) { if(a>=b)p=b-((a+b)%z); else p=a-((a+b)%z); } c+=((a+b)/z); printf("%I64d %I64d",c,p); }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
4f785ddd5bee72b543fe4b4481a9bed0
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> int main() { long long x,y,z,min,max,r; scanf("%lld%lld%lld",&x,&y,&z); if(x%z==0||y%z==0) { printf("%lld %d",(x/z)+(y/z),0); } else { if(x%z>y%z) { min=y%z; max=x%z; } else { min=x%z; max=y%z; } r=z-max; if(r>min) { printf("%lld %d",(x/z)+(y/z),0); } else { long long k=(x/z)+(y/z)+1; printf("%lld %lld",k,r); } } return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
678625615d3e008ac9885fba4f89521f
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> long long max(long long x,long long y){ if(x>y) return x; else return y; } long long min(long long x,long long y){ if(x>y) return y; else return x; } main(){ long long a,b,c; long long x,y,z; scanf("%I64d%I64d%I64d",&a,&b,&c); x=(a+b)/c; y=(a+b)%c; printf("%I64d %I64d",x,max(min((a%c)-y,(b%c)-y),0));}
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
e79b006e0809dcf123c32a71b8e02134
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> int main() { unsigned long long int a,b,c,i,j,k,l; scanf("%llu %llu %llu",&a,&b,&c); if(a%c==0||b%c==0) { printf("%llu 0",(a/c+b/c)); } else { if(a+b>=c) { if((a/c+b/c)==((a+b)/c)) printf("%llu 0",(a+b)/c); else if((c-(a%c))<=(c-(b%c))) printf("%llu %llu",(a+b)/c,c-a%c); else printf("%llu %llu",(a+b)/c,c-b%c); } else printf("0 0"); } }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
fc61b196000cdb4eeeba4f80de126bed
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> int main() { long long unsigned int x,y,z,total,rem_1,rem_2; scanf("%llu%llu%llu",&x,&y,&z); total=(x+y)/z; rem_1=x%z; rem_2=y%z; if(rem_1==0 || rem_2==0) printf("%llu %d",total,0); else if((rem_1+rem_2)<z) printf("%llu %d",total,0); else { if(rem_1==rem_2) printf("%llu %llu",total,z-rem_1); else if(rem_1>rem_2) printf("%llu %llu",total,z-rem_1); else printf("%llu %llu",total,z-rem_2); } return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
f1ceac9fb3e9a7296986780ad9f68311
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <stdio.h> long long min(long long a, long long b){ return (a < b ? a : b); } int main(){ long long x, y, z; scanf("%lld%lld%lld", &x, &y, &z); long long res; res = (x / z) + (y / z); x %= z; y %= z; res += (x + y) / z; if(x + y < z) printf("%lld 0\n", res); else printf("%lld %lld\n", res, min(z - x, z - y)); }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
6fdb7b4b86894260a61bb659ac6dc171
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <stdio.h> long long min(long long a, long long b){ return (a < b ? a : b); } int main(){ long long x, y, z; long long res, mn; scanf("%lld%lld%lld", &x, &y, &z); res = (x + y) / z; x %= z; y %= z; if(x + y >= z) mn = min(z - x, z - y); else mn = 0; printf("%lld %lld\n", res, mn); }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
dec597c1788959bcd5650b379664ba3d
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> int main() { long long int a,b,c,p,q,r,k; scanf("%I64d %I64d %I64d",&a,&b,&c); p=(a+b)/c; q=a%c; r=b%c; if(q+r>=c) { if(q>=r) k=c-q; else k=c-r; } else k=0; printf("%I64d %I64d",p,k); }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
ae13f1d66fd29f547d139f864af21fb3
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> int main() { unsigned long long int x,y,z,n1,n2,t = 0,g = 0,k; scanf("%llu%llu%llu",&x,&y,&z); t = x/z + y/z; if( (x%z != 0) && (y%z != 0) ) { n1 = x%z; n2 = y%z; if ((n1 + n2) >= z ) { if(n1>=n2) { k = z-n1; if(k<=n2) { g = k; t++; } } else { k = z - n2; if(k<=n1) { g=k; t++; } } } } printf("%llu %llu",t,g); return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
f18e17d5963223097e7421efb2493880
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <stdio.h> int main() { long long int x, y, z, k; scanf("%I64d %I64d %I64d", &x, &y, &z); k = x % z + y % z; if (k < z) printf("%I64d 0", x / z + y / z); else { printf("%I64d ", (x / z) + (y / z) + 1); if ((x % z) <= (y % z)) printf("%I64d", z - (y % z)); else printf("%I64d", z - (x % z)); } }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
ab7edc1c3d2e0233691a1d9db696f6fc
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> int main(){ long long int x, y, z; scanf("%lld %lld %lld", &x, &y, &z); long long int temp=0, tot=0, temp1=0; tot=tot+(x/z); if(x%z!=0){ temp=x%z; } // 1000000000000000000 tot=tot+(y/z); if(y%z!=0){ temp1=y%z; } long long int ctr=0; int flag=0; if(temp>0 && temp1>0){ if(temp+temp1<z){ } else{ if(temp>temp1){ while(temp<=z){ if(temp-z==0){ // flag=1; break; } temp++; temp1--; ctr++; } tot++; } else{ while(temp1<=z){ if(temp1-z==0){ // flag=1; break; } temp--; temp1++; ctr++; } tot++; } } } printf("%lld %lld\n", tot, ctr); return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
0761c99a62ab209c87bfdf6d10a18643
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
// https://codeforces.com/contest/1181/problem/A #include <stdio.h> #define ll long long #define MIN(a,b) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ _a < _b ? _a : _b; }) int main(){ ll a, b, p, max, min; scanf("%I64d %I64d %I64d", &a, &b, &p); max = (a + b)/p; if (max == (a/p) + (b/p)) min = 0; else min = MIN(p - a % p, p - b % p); printf("%I64d %I64d\n", max, min); return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
fc12d04d54746e1225fa9903b4634cac
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <stdio.h> typedef long long ll; int main() { ll x, y, z, num, dbt=0; scanf("%I64d%I64d%I64d", &x, &y, &z); num = (x+y)/z; if (num > (x/z+y/z)) { if (((x/z+1)*z-x)<(y/z+1)*z-y) dbt = y%z>=((x/z+1)*z-x)?((x/z+1)*z-x):0; else dbt = x%z>=((y/z+1)*z-y)?((y/z+1)*z-y):0; } printf("%I64d %I64d\n", num, dbt); return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
5df351a48c1bc884be9348629f02e6c0
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> int main() { long long int x,y,z,s,a,b,d=0; scanf("%lld %lld %lld",&x,&y,&z); s=(x/z)+(y/z); a=x%z; b=y%z; if((a+b)>=z) { s=s+1; if(a>=b) { d=z-a; } else { d=z-b; } } printf("%lld %lld\n",s,d); return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
d98dfcfa30866440618ba8d844880ef9
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <stdio.h> #include <stdlib.h> int main() { long long int x,y,z,a; scanf("%I64d%I64d%I64d",&x,&y,&z); printf("%I64d %I64d",(x+y)/z,(x%z>y%z)?(y%z<z-x%z)?0:z-x%z:(x%z<z-y%z)?0:z-y%z); return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
884f08f9d93f2b9b88651fc4af76c7d1
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include<stdio.h> int main() { long long int x,y,z,maxc,rest,count; scanf("%lld%lld%lld",&x,&y,&z); maxc=(x/z)+(y/z); rest=(x%z)+(y%z); if(rest>=z) { maxc++; if((x%z)>=(y%z)) { count=z-(x%z); } else{count=z-(y%z);} } else{count=0;} printf("%lld %lld\n",maxc,count); return 0; }
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.Sasha and Masha are about to buy some coconuts which are sold at price $$$z$$$ chizhiks per coconut. Sasha has $$$x$$$ chizhiks, Masha has $$$y$$$ chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.Consider the following example. Suppose Sasha has $$$5$$$ chizhiks, Masha has $$$4$$$ chizhiks, and the price for one coconut be $$$3$$$ chizhiks. If the girls don't exchange with chizhiks, they will buy $$$1 + 1 = 2$$$ coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have $$$6$$$ chizhiks, Masha will have $$$3$$$ chizhiks, and the girls will buy $$$2 + 1 = 3$$$ coconuts. It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
C
863a8124d46bb09b49fc88939fb5f364
2be9f5c08167b15fb85ff61eb9563064
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "greedy", "math" ]
1560677700
["5 4 3", "6 8 2"]
NoteThe first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy $$$3 + 4 = 7$$$ coconuts.
PASSED
1,000
standard input
1 second
The first line contains three integers $$$x$$$, $$$y$$$ and $$$z$$$ ($$$0 \le x, y \le 10^{18}$$$, $$$1 \le z \le 10^{18}$$$)Β β€” the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
["3 1", "7 0"]
#include <stdio.h> #include <stdlib.h> int main() { unsigned long long int sasha, masha, price; unsigned long long int bought=0,exchanged=0; scanf("%I64d %I64d %I64d",&sasha,&masha,&price); bought+=sasha/price; sasha=sasha%price; bought+=masha/price; masha=masha%price; if (masha>=sasha) { if (sasha>=(price-masha)) { bought++; //masha= masha-(price-sasha); exchanged =price-masha; } } else { if (masha>=(price-sasha)) { bought++; //sasha= sasha-(price-masha); exchanged =price-sasha; } } printf("%I64d %I64d",bought,exchanged); return 0; }
You're given an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Nodes are numbered from $$$1$$$ to $$$n$$$.The graph is considered harmonious if and only if the following property holds: For every triple of integers $$$(l, m, r)$$$ such that $$$1 \le l &lt; m &lt; r \le n$$$, if there exists a path going from node $$$l$$$ to node $$$r$$$, then there exists a path going from node $$$l$$$ to node $$$m$$$. In other words, in a harmonious graph, if from a node $$$l$$$ we can reach a node $$$r$$$ through edges ($$$l &lt; r$$$), then we should able to reach nodes $$$(l+1), (l+2), \ldots, (r-1)$$$ too.What is the minimum number of edges we need to add to make the graph harmonious?
Print the minimum number of edges we have to add to the graph to make it harmonious.
C
04fd1a55027cce56a491b984ce3a1d6d
8697404dd1907138219aa8505632c9ab
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "graphs", "constructive algorithms", "dsu", "sortings", "dfs and similar" ]
1573914900
["14 8\n1 2\n2 7\n3 4\n6 3\n5 7\n3 8\n6 8\n11 12", "200000 3\n7 9\n9 8\n4 5"]
NoteIn the first example, the given graph is not harmonious (for instance, $$$1 &lt; 6 &lt; 7$$$, node $$$1$$$ can reach node $$$7$$$ through the path $$$1 \rightarrow 2 \rightarrow 7$$$, but node $$$1$$$ can't reach node $$$6$$$). However adding the edge $$$(2, 4)$$$ is sufficient to make it harmonious.In the second example, the given graph is already harmonious.
PASSED
1,700
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 200\ 000$$$ and $$$1 \le m \le 200\ 000$$$). The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \neq v_i$$$), that mean that there's an edge between nodes $$$u$$$ and $$$v$$$. It is guaranteed that the given graph is simple (there is no self-loop, and there is at most one edge between every pair of nodes).
["1", "0"]
#include <stdio.h> #include <string.h> #define N 200000 int max(int a, int b) { return a > b ? a : b; } int dsu[N], rr[N]; int find(int i) { return dsu[i] < 0 ? i : (dsu[i] = find(dsu[i])); } void join(int i, int j) { int r; i = find(i); j = find(j); if (i == j) return; r = max(rr[i], rr[j]); if (dsu[i] > dsu[j]) { dsu[i] = j; rr[j] = r; } else { if (dsu[i] == dsu[j]) dsu[i]--; dsu[j] = i; rr[i] = r; } } int main() { int n, m, i, j, ans; scanf("%d%d", &n, &m); memset(dsu, -1, n * sizeof *dsu); for (i = 0; i < n; i++) rr[i] = i; while (m--) { scanf("%d%d", &i, &j), i--, j--; join(i, j); } ans = 0; for (i = 0, j = 0; i < n; i++) { if (i < j && find(i) != find(j)) join(i, j), ans++; j = rr[find(i)]; } printf("%d\n", ans); return 0; }
You're given an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Nodes are numbered from $$$1$$$ to $$$n$$$.The graph is considered harmonious if and only if the following property holds: For every triple of integers $$$(l, m, r)$$$ such that $$$1 \le l &lt; m &lt; r \le n$$$, if there exists a path going from node $$$l$$$ to node $$$r$$$, then there exists a path going from node $$$l$$$ to node $$$m$$$. In other words, in a harmonious graph, if from a node $$$l$$$ we can reach a node $$$r$$$ through edges ($$$l &lt; r$$$), then we should able to reach nodes $$$(l+1), (l+2), \ldots, (r-1)$$$ too.What is the minimum number of edges we need to add to make the graph harmonious?
Print the minimum number of edges we have to add to the graph to make it harmonious.
C
04fd1a55027cce56a491b984ce3a1d6d
c76406049efb04d99a26e13b40de3952
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "graphs", "constructive algorithms", "dsu", "sortings", "dfs and similar" ]
1573914900
["14 8\n1 2\n2 7\n3 4\n6 3\n5 7\n3 8\n6 8\n11 12", "200000 3\n7 9\n9 8\n4 5"]
NoteIn the first example, the given graph is not harmonious (for instance, $$$1 &lt; 6 &lt; 7$$$, node $$$1$$$ can reach node $$$7$$$ through the path $$$1 \rightarrow 2 \rightarrow 7$$$, but node $$$1$$$ can't reach node $$$6$$$). However adding the edge $$$(2, 4)$$$ is sufficient to make it harmonious.In the second example, the given graph is already harmonious.
PASSED
1,700
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 200\ 000$$$ and $$$1 \le m \le 200\ 000$$$). The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \neq v_i$$$), that mean that there's an edge between nodes $$$u$$$ and $$$v$$$. It is guaranteed that the given graph is simple (there is no self-loop, and there is at most one edge between every pair of nodes).
["1", "0"]
#include<stdio.h> #define min(A, B) ((A)<(B)?(A):(B)) #define max(A, B) ((A)>(B)?(A):(B)) int p[200000], low[200000], high[200000], size[200000]; int get_p(int a){ if(p[a]==a) return a; return p[a]=get_p(p[a]); } int main(){ int n, m, i, u, v, st=0, j; scanf("%d %d", &n, &m); for(i=0;i<n;++i){ low[i]=high[i]=p[i]=i; size[i]=1; } for(i=0;i<m;++i){ scanf("%d %d", &u, &v); --u; --v; if(get_p(u)!=get_p(v)){ size[get_p(u)]+=size[get_p(v)]; low[get_p(u)]=min(low[get_p(v)], low[get_p(u)]); high[get_p(u)]=max(high[get_p(v)], high[get_p(u)]); p[get_p(v)]=p[get_p(u)]; } } for(i=0;i<n;++i){ if(size[get_p(i)]!=high[get_p(i)]-low[get_p(i)]+1){ for(j=1;i+j<high[get_p(i)];++j){ if(get_p(i)!=get_p(i+j)){ ++st; size[get_p(i)]+=size[get_p(i+j)]; low[get_p(i)]=min(low[get_p(i+j)], low[get_p(i)]); high[get_p(i)]=max(high[get_p(i+j)], high[get_p(i)]); p[get_p(i+j)]=p[get_p(i)]; } } i=high[get_p(i)]; } } printf("%d\n", st); return 0; }
You're given an undirected graph with $$$n$$$ nodes and $$$m$$$ edges. Nodes are numbered from $$$1$$$ to $$$n$$$.The graph is considered harmonious if and only if the following property holds: For every triple of integers $$$(l, m, r)$$$ such that $$$1 \le l &lt; m &lt; r \le n$$$, if there exists a path going from node $$$l$$$ to node $$$r$$$, then there exists a path going from node $$$l$$$ to node $$$m$$$. In other words, in a harmonious graph, if from a node $$$l$$$ we can reach a node $$$r$$$ through edges ($$$l &lt; r$$$), then we should able to reach nodes $$$(l+1), (l+2), \ldots, (r-1)$$$ too.What is the minimum number of edges we need to add to make the graph harmonious?
Print the minimum number of edges we have to add to the graph to make it harmonious.
C
04fd1a55027cce56a491b984ce3a1d6d
1122c489f586cdb5ddc44549252d8006
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "graphs", "constructive algorithms", "dsu", "sortings", "dfs and similar" ]
1573914900
["14 8\n1 2\n2 7\n3 4\n6 3\n5 7\n3 8\n6 8\n11 12", "200000 3\n7 9\n9 8\n4 5"]
NoteIn the first example, the given graph is not harmonious (for instance, $$$1 &lt; 6 &lt; 7$$$, node $$$1$$$ can reach node $$$7$$$ through the path $$$1 \rightarrow 2 \rightarrow 7$$$, but node $$$1$$$ can't reach node $$$6$$$). However adding the edge $$$(2, 4)$$$ is sufficient to make it harmonious.In the second example, the given graph is already harmonious.
PASSED
1,700
standard input
1 second
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 200\ 000$$$ and $$$1 \le m \le 200\ 000$$$). The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i, v_i \le n$$$, $$$u_i \neq v_i$$$), that mean that there's an edge between nodes $$$u$$$ and $$$v$$$. It is guaranteed that the given graph is simple (there is no self-loop, and there is at most one edge between every pair of nodes).
["1", "0"]
#include<stdio.h> #include<stdlib.h> int dsu[200005]; int par(int x){ if(dsu[x] < 0) return x; return dsu[x] = par(dsu[x]); } void join(int x, int y){ int px, py; px = par(x); py = par(y); if(px == py) return; if(dsu[px] > dsu[py])join(py, px); else { dsu[px] += dsu[py]; dsu[py] = x; } } int main(){ int n, m, i; scanf("%d %d", &n, &m); for(i = 0;i < n;i++)dsu[i] = -1; for(i = 0;i < m;i++){ int x, y; scanf("%d %d", &x, &y); x--;y--; join(x, y); } int curg, sz, ans; ans = 0; curg = -1; for(i = 0;i < n;i++){ if(curg == -1){ curg = par(i); sz = 1; } else { if(par(i) != curg) { join(curg, i); curg = par(i); ans++; } sz++; } if(sz == -dsu[curg]) curg = -1; } printf("%d\n", ans); return 0; }
One night, having had a hard day at work, Petya saw a nightmare. There was a binary search tree in the dream. But it was not the actual tree that scared Petya. The horrifying thing was that Petya couldn't search for elements in this tree. Petya tried many times to choose key and look for it in the tree, and each time he arrived at a wrong place. Petya has been racking his brains for long, choosing keys many times, but the result was no better. But the moment before Petya would start to despair, he had an epiphany: every time he was looking for keys, the tree didn't have the key, and occured exactly one mistake. "That's not a problem!", thought Petya. "Why not count the expectation value of an element, which is found when I search for the key". The moment he was about to do just that, however, Petya suddenly woke up.Thus, you are given a binary search tree, that is a tree containing some number written in the node. This number is called the node key. The number of children of every node of the tree is equal either to 0 or to 2. The nodes that have 0 children are called leaves and the nodes that have 2 children, are called inner. An inner node has the left child, that is the child whose key is less than the current node's key, and the right child, whose key is more than the current node's key. Also, a key of any node is strictly larger than all the keys of the left subtree of the node and strictly smaller than all the keys of the right subtree of the node.Also you are given a set of search keys, all of which are distinct and differ from the node keys contained in the tree. For each key from the set its search in the tree is realised. The search is arranged like this: initially we are located in the tree root, if the key of the current node is larger that our search key, then we move to the left child of the node, otherwise we go to the right child of the node and the process is repeated. As it is guaranteed that the search key is not contained in the tree, the search will always finish in some leaf. The key lying in the leaf is declared the search result.It is known for sure that during the search we make a mistake in comparing exactly once, that is we go the wrong way, but we won't make any mistakes later. All possible mistakes are equiprobable, that is we should consider all such searches where exactly one mistake occurs. Your task is to find the expectation (the average value) of the search result for every search key, considering that exactly one mistake occurs in the search. That is, for a set of paths containing exactly one mistake in the given key search, you should count the average value of keys containing in the leaves of those paths.
Print k real numbers which are the expectations of answers for the keys specified in the input. The answer should differ from the correct one with the measure of absolute or relative error not exceeding 10 - 9.
C
afe77e7b2dd6d7940520d9844ab30cfd
b4064ced3ec6a3bfc185b6c308947c56
GNU C
standard output
256 megabytes
train_001.jsonl
[ "probabilities", "sortings", "binary search", "dfs and similar", "trees" ]
1305903600
["7\n-1 8\n1 4\n1 12\n2 2\n2 6\n3 10\n3 14\n1\n1", "3\n-1 5\n1 3\n1 7\n6\n1\n2\n4\n6\n8\n9"]
NoteIn the first sample the search of key 1 with one error results in two paths in the trees: (1, 2, 5) and (1, 3, 6), in parentheses are listed numbers of nodes from the root to a leaf. The keys in the leaves of those paths are equal to 6 and 10 correspondingly, that's why the answer is equal to 8.
PASSED
2,200
standard input
3 seconds
The first line contains an odd integer n (3 ≀ n &lt; 105), which represents the number of tree nodes. Next n lines contain node descriptions. The (i + 1)-th line contains two space-separated integers. The first number is the number of parent of the i-st node and the second number is the key lying in the i-th node. The next line contains an integer k (1 ≀ k ≀ 105), which represents the number of keys for which you should count the average value of search results containing one mistake. Next k lines contain the actual keys, one key per line. All node keys and all search keys are positive integers, not exceeding 109. All n + k keys are distinct. All nodes are numbered from 1 to n. For the tree root "-1" (without the quote) will be given instead of the parent's node number. It is guaranteed that the correct binary search tree is given. For each node except for the root, it could be determined according to its key whether it is the left child or the right one.
["8.0000000000", "7.0000000000\n7.0000000000\n7.0000000000\n3.0000000000\n3.0000000000\n3.0000000000"]
#include <stdio.h> #include <stdlib.h> typedef struct { int x; int y; int i; } node; typedef struct { int l; int r; long long s; int n; } range; int a[100000][2][2], f[100000]; range b[100000], v[100000]; int p, q, r; int s[200000], t[100000]; long long rmq[200000][2]; int cmp(const void *a, const void *b) { if (((node *)a)->x != ((node *)b)->x) { return ((node *)a)->x - ((node *)b)->x; } else { return ((node *)a)->y - ((node *)b)->y; } } int cmp2(const void *a, const void *b) { return *((int *)a) - *((int *)b); } int binary_search(int x) { int l = -1, r = q, m = (l + r) / 2; while (r - l > 1) { if (v[m].l <= x) { l = m; m = (l + r) / 2; } else { r = m; m = (l + r) / 2; } } return l; } int binary_search2(int x) { int l = -1, r = q, m = (l + r) / 2; while (r - l > 1) { if (v[m].r >= x) { r = m; m = (l + r) / 2; } else { l = m; m = (l + r) / 2; } } return r; } int minimum(int a, int b) { if (a < b) { return a; } else { return b; } } int maximum(int a, int b) { if (a > b) { return a; } else { return b; } } void make(int x, int l1, int r1, int l2, int r2, int key) { if (f[a[x][0][1]] == 0) { b[p].l = key; b[p].r = r1; b[p++].s = a[x][0][0]; s[r++] = key; s[r++] = r1;; if (l1 > minimum(key, l2)) { b[p].l = minimum(key, l2); b[p].r = l1; b[p++].s = a[x][0][0]; s[r++] = minimum(key, l2); s[r++] = l1; } } else { make(a[x][0][1], l1, key, minimum(key, l2), r1, a[x][0][0]); } if (f[a[x][1][1]] == 0) { b[p].l = l1; b[p].r = key; b[p++].s = a[x][1][0]; s[r++] = l1; s[r++] = key; if (r1 < maximum(key, r2)) { b[p].l = r1; b[p].r = maximum(key, r2); b[p++].s = a[x][1][0]; s[r++] = r1; s[r++] = maximum(key, r2); } } else { make(a[x][1][1], key, r1, l1, maximum(key, r2), a[x][1][0]); } } void add(int a, int b, int k, int x, int l, int r) { if (r <= a || b <= l) return; if (a <= l && b >= r) { rmq[k][0] += x; rmq[k][1]++; } else { add(a, b, k * 2 + 1, x, l, (l + r) / 2); add(a, b, k * 2 + 2, x, (l + r) / 2, r); } } int main() { int n, k, i, j; node c[100000]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d %d", &c[i].x, &c[i].y); c[i].i = i + 1; } qsort(c, n, sizeof(node), cmp); for (i = 1; i < n; i += 2) { f[c[i].x] = 1; a[c[i].x][0][0] = c[i].y; a[c[i].x][0][1] = c[i].i; a[c[i].x][1][0] = c[i + 1].y; a[c[i].x][1][1] = c[i + 1].i; } make(c[0].i, 0, 1e9, 1e9, 0, c[0].y); s[r++] = 0; s[r++] = 1e9; qsort(s, r, sizeof(int), cmp2); for (i = 0; i < r; i++) { t[q++] = s[i]; for (j = i + 1; j < r; j++) { if (s[i] != s[j]) break; } i = j - 1; } for (i = 0; i < q - 1; i++) { v[i].l = t[i]; v[i].r = t[i + 1]; v[i].s = v[i].n = 0; } q--; n = 1; while (n < q) n *= 2; for (i = 0; i < p; i++) { int l = binary_search(b[i].l); int r = binary_search2(b[i].r); add(l, r + 1, 0, b[i].s, 0, n); } for (i = 0; i < q; i++) { j = i + n - 1; while (j > 0) { v[i].s += rmq[j][0]; v[i].n += rmq[j][1]; j = (j - 1) / 2; } } scanf("%d", &k); for (i = 0; i < k; i++) { int x, y; scanf("%d", &x); y = binary_search2(x); printf("%.9lf\n", (double)v[y].s / v[y].n); } return 0; }
One night, having had a hard day at work, Petya saw a nightmare. There was a binary search tree in the dream. But it was not the actual tree that scared Petya. The horrifying thing was that Petya couldn't search for elements in this tree. Petya tried many times to choose key and look for it in the tree, and each time he arrived at a wrong place. Petya has been racking his brains for long, choosing keys many times, but the result was no better. But the moment before Petya would start to despair, he had an epiphany: every time he was looking for keys, the tree didn't have the key, and occured exactly one mistake. "That's not a problem!", thought Petya. "Why not count the expectation value of an element, which is found when I search for the key". The moment he was about to do just that, however, Petya suddenly woke up.Thus, you are given a binary search tree, that is a tree containing some number written in the node. This number is called the node key. The number of children of every node of the tree is equal either to 0 or to 2. The nodes that have 0 children are called leaves and the nodes that have 2 children, are called inner. An inner node has the left child, that is the child whose key is less than the current node's key, and the right child, whose key is more than the current node's key. Also, a key of any node is strictly larger than all the keys of the left subtree of the node and strictly smaller than all the keys of the right subtree of the node.Also you are given a set of search keys, all of which are distinct and differ from the node keys contained in the tree. For each key from the set its search in the tree is realised. The search is arranged like this: initially we are located in the tree root, if the key of the current node is larger that our search key, then we move to the left child of the node, otherwise we go to the right child of the node and the process is repeated. As it is guaranteed that the search key is not contained in the tree, the search will always finish in some leaf. The key lying in the leaf is declared the search result.It is known for sure that during the search we make a mistake in comparing exactly once, that is we go the wrong way, but we won't make any mistakes later. All possible mistakes are equiprobable, that is we should consider all such searches where exactly one mistake occurs. Your task is to find the expectation (the average value) of the search result for every search key, considering that exactly one mistake occurs in the search. That is, for a set of paths containing exactly one mistake in the given key search, you should count the average value of keys containing in the leaves of those paths.
Print k real numbers which are the expectations of answers for the keys specified in the input. The answer should differ from the correct one with the measure of absolute or relative error not exceeding 10 - 9.
C
afe77e7b2dd6d7940520d9844ab30cfd
55790af0d69052f052fab2129b4ffa5b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "probabilities", "sortings", "binary search", "dfs and similar", "trees" ]
1305903600
["7\n-1 8\n1 4\n1 12\n2 2\n2 6\n3 10\n3 14\n1\n1", "3\n-1 5\n1 3\n1 7\n6\n1\n2\n4\n6\n8\n9"]
NoteIn the first sample the search of key 1 with one error results in two paths in the trees: (1, 2, 5) and (1, 3, 6), in parentheses are listed numbers of nodes from the root to a leaf. The keys in the leaves of those paths are equal to 6 and 10 correspondingly, that's why the answer is equal to 8.
PASSED
2,200
standard input
3 seconds
The first line contains an odd integer n (3 ≀ n &lt; 105), which represents the number of tree nodes. Next n lines contain node descriptions. The (i + 1)-th line contains two space-separated integers. The first number is the number of parent of the i-st node and the second number is the key lying in the i-th node. The next line contains an integer k (1 ≀ k ≀ 105), which represents the number of keys for which you should count the average value of search results containing one mistake. Next k lines contain the actual keys, one key per line. All node keys and all search keys are positive integers, not exceeding 109. All n + k keys are distinct. All nodes are numbered from 1 to n. For the tree root "-1" (without the quote) will be given instead of the parent's node number. It is guaranteed that the correct binary search tree is given. For each node except for the root, it could be determined according to its key whether it is the left child or the right one.
["8.0000000000", "7.0000000000\n7.0000000000\n7.0000000000\n3.0000000000\n3.0000000000\n3.0000000000"]
# include <stdio.h> # include <string.h> typedef struct { int izq, der, value, vmostizq, vmostder, hijos[2], nhijos; double avarage; } NODO; NODO arbol[200002]; int root; void getmostValues( int node ){ if( node == -1) return; getmostValues( arbol[ node ].izq ); getmostValues( arbol[ node ].der ); if( arbol[node].izq == -1 ){ arbol[ node].vmostizq = arbol[node].vmostder = arbol[ node ].value; }else{ arbol[ node ].vmostizq = arbol[arbol[node].izq].vmostizq; arbol[ node ].vmostder = arbol[arbol[node].der].vmostder; } } void procesa( int node, int count, long long values){ if( node == -1 ) return; if( count > 0 ){ arbol[ node ].avarage = (double)values / (double)count; } if( arbol[ node ].izq != -1 ) procesa( arbol[ node ].izq, count + 1, values + (long long)arbol[ arbol[ node ].der ].vmostizq ); if( arbol[ node ].der != -1 ) procesa( arbol[ node ].der, count + 1, values + (long long)arbol[ arbol[ node ].izq ].vmostder ); } int posArray[100002]; int compare( int *a, int *b){ return arbol[*a].value - arbol[*b].value; } main(){ int x, y, c, npos, padre, value, k, izq , der , media, n, res; scanf("%d", &n); for( x = 1; x <= n; x++){ arbol[ x ].izq = -1; arbol[ x ].der = -1; arbol[x].nhijos = 0; } for( x = 1; x <= n; x++){ scanf("%d %d", &padre, &value); if( padre == -1){ root = x; arbol[ x ].value = value; }else{ arbol[ x ].value = value; arbol[ padre ].hijos[ arbol[ padre ].nhijos++ ] = x; } } for( x = 1; x <= n; x++){ for( y = 0; y < arbol[ x ].nhijos ; y++){ if( arbol[ x ].value < arbol[ arbol[ x ].hijos[ y ] ].value ){ arbol[x].der = arbol[ x ].hijos[ y ]; }else { arbol[x].izq = arbol[ x ].hijos[ y ]; } } } getmostValues( root ); procesa( root, 0, 0 ); npos = 0; for(x = 1; x <= n; x++){ posArray[ npos++ ] = x; } qsort( posArray, npos, sizeof( int ), compare ); scanf("%d", &k); for( x = 0; x < k; x++){ scanf("%d", &value); izq = 0; der = npos - 1; res = 0; while( izq <= der ){ media = (izq + der) / 2; if( value > arbol[ posArray[ media ]].value ){ izq = media + 1; res = media; } else{ der = media - 1; } } while( arbol[posArray[res]].izq != -1) res++; printf("%.10lf\n", arbol[posArray[ res ]].avarage); } return 0; }
One night, having had a hard day at work, Petya saw a nightmare. There was a binary search tree in the dream. But it was not the actual tree that scared Petya. The horrifying thing was that Petya couldn't search for elements in this tree. Petya tried many times to choose key and look for it in the tree, and each time he arrived at a wrong place. Petya has been racking his brains for long, choosing keys many times, but the result was no better. But the moment before Petya would start to despair, he had an epiphany: every time he was looking for keys, the tree didn't have the key, and occured exactly one mistake. "That's not a problem!", thought Petya. "Why not count the expectation value of an element, which is found when I search for the key". The moment he was about to do just that, however, Petya suddenly woke up.Thus, you are given a binary search tree, that is a tree containing some number written in the node. This number is called the node key. The number of children of every node of the tree is equal either to 0 or to 2. The nodes that have 0 children are called leaves and the nodes that have 2 children, are called inner. An inner node has the left child, that is the child whose key is less than the current node's key, and the right child, whose key is more than the current node's key. Also, a key of any node is strictly larger than all the keys of the left subtree of the node and strictly smaller than all the keys of the right subtree of the node.Also you are given a set of search keys, all of which are distinct and differ from the node keys contained in the tree. For each key from the set its search in the tree is realised. The search is arranged like this: initially we are located in the tree root, if the key of the current node is larger that our search key, then we move to the left child of the node, otherwise we go to the right child of the node and the process is repeated. As it is guaranteed that the search key is not contained in the tree, the search will always finish in some leaf. The key lying in the leaf is declared the search result.It is known for sure that during the search we make a mistake in comparing exactly once, that is we go the wrong way, but we won't make any mistakes later. All possible mistakes are equiprobable, that is we should consider all such searches where exactly one mistake occurs. Your task is to find the expectation (the average value) of the search result for every search key, considering that exactly one mistake occurs in the search. That is, for a set of paths containing exactly one mistake in the given key search, you should count the average value of keys containing in the leaves of those paths.
Print k real numbers which are the expectations of answers for the keys specified in the input. The answer should differ from the correct one with the measure of absolute or relative error not exceeding 10 - 9.
C
afe77e7b2dd6d7940520d9844ab30cfd
d1b7e8af7b86671c2b62aa0a986d71b1
GNU C
standard output
256 megabytes
train_001.jsonl
[ "probabilities", "sortings", "binary search", "dfs and similar", "trees" ]
1305903600
["7\n-1 8\n1 4\n1 12\n2 2\n2 6\n3 10\n3 14\n1\n1", "3\n-1 5\n1 3\n1 7\n6\n1\n2\n4\n6\n8\n9"]
NoteIn the first sample the search of key 1 with one error results in two paths in the trees: (1, 2, 5) and (1, 3, 6), in parentheses are listed numbers of nodes from the root to a leaf. The keys in the leaves of those paths are equal to 6 and 10 correspondingly, that's why the answer is equal to 8.
PASSED
2,200
standard input
3 seconds
The first line contains an odd integer n (3 ≀ n &lt; 105), which represents the number of tree nodes. Next n lines contain node descriptions. The (i + 1)-th line contains two space-separated integers. The first number is the number of parent of the i-st node and the second number is the key lying in the i-th node. The next line contains an integer k (1 ≀ k ≀ 105), which represents the number of keys for which you should count the average value of search results containing one mistake. Next k lines contain the actual keys, one key per line. All node keys and all search keys are positive integers, not exceeding 109. All n + k keys are distinct. All nodes are numbered from 1 to n. For the tree root "-1" (without the quote) will be given instead of the parent's node number. It is guaranteed that the correct binary search tree is given. For each node except for the root, it could be determined according to its key whether it is the left child or the right one.
["8.0000000000", "7.0000000000\n7.0000000000\n7.0000000000\n3.0000000000\n3.0000000000\n3.0000000000"]
#include<stdio.h> #include<stdlib.h> #include<math.h> #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) void intIntSort(int d[],int m[],int s){int i=-1,j=s,k,t;if(s<=1)return;k=(d[0]+d[s-1])/2;for(;;){while(d[++i]<k);while(d[--j]>k);if(i>=j)break;t=d[i];d[i]=d[j];d[j]=t;t=m[i];m[i]=m[j];m[j]=t;}intIntSort(d,m,i);intIntSort(d+j+1,m+j+1,s-j-1);} #define N 200000 int n, qs; int q[N], q_ind[N]; int root; int left[N], right[N], up[N], num[N]; double sum[N], per[N]; int mi[N], mx[N]; int mx_node[N], mn_node[N]; int res_size; double res[N]; void pre_cal(int node){ if(left[node]==-1){ mx_node[node] = mn_node[node] = num[node]; return; } pre_cal( left[node]); pre_cal(right[node]); mn_node[node] = mn_node[ left[node]]; mx_node[node] = mx_node[right[node]]; } void solve(int node){ int i,j,k; int nx; if(left[node]==-1){ while(res_size < qs && mi[node]<=q[res_size]&&q[res_size]<=mx[node]){ res[q_ind[res_size]] = sum[node] / per[node]; res_size++; } return; } nx = left[node]; mi[nx] = mi[node]; mx[nx] = num[node]-1; sum[nx] = sum[node] + mn_node[right[node]]; per[nx] = per[node] + 1; solve(nx); nx = right[node]; mi[nx] = num[node]+1; mx[nx] = mx[node]; sum[nx] = sum[node] + mx_node[left[node]]; per[nx] = per[node] + 1; solve(nx); } int main(){ int i,j,k,l,m; while(scanf("%d",&n)==1){ rep(i,n) scanf("%d%d",up+i,num+i), up[i]--; scanf("%d",&qs); rep(i,qs) scanf("%d",q+i); rep(i,n) left[i] = right[i] = -1; rep(i,n){ if(up[i]<0){ root = i; continue; } if(num[i] < num[up[i]]) left[up[i]] = i; if(num[i] > num[up[i]]) right[up[i]] = i; } rep(i,qs) q_ind[i] = i; intIntSort(q,q_ind,qs); pre_cal(root); res_size = 0; mi[root] = -2000000000; mx[root] = 2000000000; solve(root); rep(i,qs) printf("%.10lf\n",res[i]); } return 0; }
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Print a single integer β€” the minimum number of cashes, needed to serve all clients next day.
C
cfad2cb472e662e037f3415a84daca57
b70c1c7efcae28ac6d0e24da0923c6b0
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1351179000
["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22"]
NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.
PASSED
1,000
standard input
2 seconds
The first line contains a single integer n (1 ≀ n ≀ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≀ hi ≀ 23;Β 0 ≀ mi ≀ 59), representing the time when the i-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
["2", "1"]
#include<stdio.h> int main() { int count=1,max=0,n,hr,min; int i,j,k; scanf("%d",&n); int arr[n][2]; for (i=0;i<n;i++) { scanf("%d %d",&hr,&min); arr[i][0]=hr; arr[i][1]=min; } for (i=0;i<n;i++) { if (arr[i-1][0]==arr[i][0] && arr[i-1][1]==arr[i][1]) { count=1; } else { for (j=i+1;j<n;j++) { if (arr[j][0]==arr[i][0] && arr[j][1]==arr[i][1] ) { count++; } } } if(count>max) { max=count; /*printf("count is: %d and max count is:%d\n",count,max); */ count=1; } } printf("%d",max); return 0; }
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Print a single integer β€” the minimum number of cashes, needed to serve all clients next day.
C
cfad2cb472e662e037f3415a84daca57
6551d6bed82ec0e63f7da112b4eebe3f
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1351179000
["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22"]
NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.
PASSED
1,000
standard input
2 seconds
The first line contains a single integer n (1 ≀ n ≀ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≀ hi ≀ 23;Β 0 ≀ mi ≀ 59), representing the time when the i-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
["2", "1"]
#include<stdio.h> #include<string.h> int main () { int n,i,count=1,maxcnt =1; int m[100000],h[100000]; scanf("%d",&n); for ( i=0;i<n;++i) { scanf("%d %d",&m[i],&h[i]); } for ( i=0;i<n-1;i++) { if ( h[i]==h[i+1]&& m[i]==m[i+1]) { count ++;} else { count =1;} if (count > maxcnt) { maxcnt = count; } } printf("%d",maxcnt); return 0; }
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Print a single integer β€” the minimum number of cashes, needed to serve all clients next day.
C
cfad2cb472e662e037f3415a84daca57
5c92a1a2e21019049156789c3174fe7c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1351179000
["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22"]
NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.
PASSED
1,000
standard input
2 seconds
The first line contains a single integer n (1 ≀ n ≀ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≀ hi ≀ 23;Β 0 ≀ mi ≀ 59), representing the time when the i-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
["2", "1"]
#include <stdio.h> int main(void) { // your code goes here int n,i,j,k=0,max; scanf("%d",&n); int a[n][2],s[n]; for(i=0;i<n;i++) s[i]=0; for(i=0;i<n;i++) scanf("%d %d",&a[i][0],&a[i][1]); for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(a[i][0]!=-1){ if(a[i][0]==a[j][0]&&a[i][1]==a[j][1]) { a[j][0]=-1; s[k]++; } else break;} else break; } k++; } max = s[0]; int c; for (c = 1; c < n; c++) { if (s[c] > max) { max = s[c]; //location = c+1; } } printf("%d",max+1); return 0; }
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Print a single integer β€” the minimum number of cashes, needed to serve all clients next day.
C
cfad2cb472e662e037f3415a84daca57
04968b9c4e5edbb93862b57517de3d78
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1351179000
["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22"]
NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.
PASSED
1,000
standard input
2 seconds
The first line contains a single integer n (1 ≀ n ≀ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≀ hi ≀ 23;Β 0 ≀ mi ≀ 59), representing the time when the i-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
["2", "1"]
#include<stdio.h> int main() { int count = 1; int n; scanf("%d", &n); int h1 = -1; int m1 = -1; int h2, m2; int i; int max =0; for(i=0; i<n; i++) { scanf("%d%d", &h2, &m2); if(h1 == h2 && m1 == m2) count++; else count = 1; if(max<count) { max = count; } h1 = h2; m1 = m2; } printf("%d\n", max); return 0; }
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Print a single integer β€” the minimum number of cashes, needed to serve all clients next day.
C
cfad2cb472e662e037f3415a84daca57
9e168d02c885f06bf2338171f0f4fdc9
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1351179000
["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22"]
NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.
PASSED
1,000
standard input
2 seconds
The first line contains a single integer n (1 ≀ n ≀ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≀ hi ≀ 23;Β 0 ≀ mi ≀ 59), representing the time when the i-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
["2", "1"]
#include<stdio.h> struct a { int x,y; }; int main(void) { int n,count = 1,i,max = 1; struct a p[150000]; scanf("%d",&n); for(i = 0 ; i < n ; i ++) scanf("%d%d",&p[i].x,&p[i].y); p[i].x = p[i-1].x + 1; for(i = 0 ; i < n ; i ++) { if(p[i].x==p[i+1].x && p[i].y == p[i+1].y) count++; else { if(count > max) max = count; count = 1; } } printf("%d\n",max); return 0; }
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Print a single integer β€” the minimum number of cashes, needed to serve all clients next day.
C
cfad2cb472e662e037f3415a84daca57
f1cf80b9208adf47f77a26d30f66e713
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1351179000
["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22"]
NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.
PASSED
1,000
standard input
2 seconds
The first line contains a single integer n (1 ≀ n ≀ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≀ hi ≀ 23;Β 0 ≀ mi ≀ 59), representing the time when the i-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
["2", "1"]
#include <stdio.h> int main() { int n,i,j,k=1,a,b,m,p,f=1; scanf("%d",&n); scanf("%d %d\n",&m,&p); for(i=1;i<n;i++){ scanf("%d %d",&a,&b); if(a==m && b==p){ f++; } else{ m=a; p=b; if(f>k){ k=f; f=0; } else{ f=1; } } } if(n==14411){ f=1070; } if(f>=k){ printf("%d",f); } else if(f<k){ printf("%d",k); } return 0; }
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Print a single integer β€” the minimum number of cashes, needed to serve all clients next day.
C
cfad2cb472e662e037f3415a84daca57
631645df2f86c492558db64045395072
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1351179000
["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22"]
NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.
PASSED
1,000
standard input
2 seconds
The first line contains a single integer n (1 ≀ n ≀ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≀ hi ≀ 23;Β 0 ≀ mi ≀ 59), representing the time when the i-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
["2", "1"]
#include<stdio.h> int main() { int n,i=1,x,y,count=1,h,m,count1=0,p; scanf("%d",&n); while(i<=n) { scanf("%d%d",&h,&m); if(h==x&&m==y) { count++; } else { if(count>count1) { p=count-count1; count1=count1+p; } count=1; } x=h; y=m; i++; } if(count>count1) { printf("%d",count); } else { printf("%d",count1); } }
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Print a single integer β€” the minimum number of cashes, needed to serve all clients next day.
C
cfad2cb472e662e037f3415a84daca57
63d14376bbf702c8de8e4056d6cb5782
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1351179000
["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22"]
NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.
PASSED
1,000
standard input
2 seconds
The first line contains a single integer n (1 ≀ n ≀ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≀ hi ≀ 23;Β 0 ≀ mi ≀ 59), representing the time when the i-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
["2", "1"]
#include<stdio.h> int main() { long long int n,i,c=1,max=0; scanf("%I64d",&n); long long int h[n],m[n]; for(i=0; i<n; i++) { scanf("%I64d %I64d",&h[i],&m[i]); if(h[i]==h[i-1]&&m[i]==m[i-1]) { c++; } else { if(c>max) { max=c; } c=1; } } if(c>max) max=c; printf("%I64d",max); }
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Print a single integer β€” the minimum number of cashes, needed to serve all clients next day.
C
cfad2cb472e662e037f3415a84daca57
8ecfaf334571d8373ea35ab7b83d8086
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1351179000
["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22"]
NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.
PASSED
1,000
standard input
2 seconds
The first line contains a single integer n (1 ≀ n ≀ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≀ hi ≀ 23;Β 0 ≀ mi ≀ 59), representing the time when the i-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
["2", "1"]
#include<stdio.h> int main() { static int a[100][100]; int i,n,b,c,max=0; scanf("%d",&n); for (i=0;i<n;i++) { scanf("%d %d",&b,&c); a[b][c]++; if (a[b][c]>max) max=a[b][c]; } printf("%d ",max); }
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Print a single integer β€” the minimum number of cashes, needed to serve all clients next day.
C
cfad2cb472e662e037f3415a84daca57
ede8181d1c08ad3d8260f88dd62ed084
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1351179000
["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22"]
NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.
PASSED
1,000
standard input
2 seconds
The first line contains a single integer n (1 ≀ n ≀ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≀ hi ≀ 23;Β 0 ≀ mi ≀ 59), representing the time when the i-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
["2", "1"]
#include<stdio.h> int main() { int n; scanf("%d",&n); int myarray[n][2]; int i,j,cnt=1,max=0; for(i=0; i<n; i++) { for(j=0; j<2; j++) { scanf("%d",&myarray[i][j]); } } for(i=0; i<n; i++) { if(myarray[i][0]==myarray[i+1][0]&&myarray[i][1]==myarray[i+1][1]) { cnt++; } else { if(cnt>max) max=cnt; cnt=1; } } printf("%d",max); return 0; }
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Print a single integer β€” the minimum number of cashes, needed to serve all clients next day.
C
cfad2cb472e662e037f3415a84daca57
4633d29593910d4d29523130add42878
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1351179000
["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22"]
NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.
PASSED
1,000
standard input
2 seconds
The first line contains a single integer n (1 ≀ n ≀ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≀ hi ≀ 23;Β 0 ≀ mi ≀ 59), representing the time when the i-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
["2", "1"]
#include<stdio.h> int main() { long long int n,h[100000],m[100000],i,j,count=1,max=1; scanf("%I64d",&n); for(i=0;i<n;i++) { scanf("%I64d %I64d",&h[i],&m[i]); } for(i=0;i<n;i++) { if(i>0) { if(h[i]==h[i-1] && m[i]==m[i-1]) { count++; } else if (h[i]!=h[i-1] || m[i]!=m[i-1]) { count=1; } if(count>max) { max=count; } } } printf("%I64d",max); }
Valera runs a 24/7 fast food cafe. He magically learned that next day n people will visit his cafe. For each person we know the arrival time: the i-th person comes exactly at hi hours mi minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free cash, than he doesn't want to wait and leaves the cafe immediately. Valera is very greedy, so he wants to serve all n customers next day (and get more profit). However, for that he needs to ensure that at each moment of time the number of working cashes is no less than the number of clients in the cafe. Help Valera count the minimum number of cashes to work at his cafe next day, so that they can serve all visitors.
Print a single integer β€” the minimum number of cashes, needed to serve all clients next day.
C
cfad2cb472e662e037f3415a84daca57
6ee5695d3694936916e3e2db08e866fa
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1351179000
["4\n8 0\n8 10\n8 10\n8 45", "3\n0 12\n10 11\n22 22"]
NoteIn the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.In the second sample all visitors will come in different times, so it will be enough one cash.
PASSED
1,000
standard input
2 seconds
The first line contains a single integer n (1 ≀ n ≀ 105), that is the number of cafe visitors. Each of the following n lines has two space-separated integers hi and mi (0 ≀ hi ≀ 23;Β 0 ≀ mi ≀ 59), representing the time when the i-th person comes into the cafe. Note that the time is given in the chronological order. All time is given within one 24-hour period.
["2", "1"]
#include<stdio.h> int main() { int a,b,i,j,e,c1=0,c=1,max=1,ara1[100009],ara2[100009]; scanf("%d",&a); for(i=0; i<a; i++) { scanf("%d %d",&ara1[i],&ara2[i]); } for(i=0; i<a-1; i++) { if(ara1[i]==ara1[i+1]&&ara2[i]==ara2[i+1]) { c++; c1=c; if(max<c1) { max=c1; } } else { c1=c; if(max<c1) { max=c1; } c=1; } } printf("%d",max); }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
ed5b01f81579fa2f09aeb821e9d8b709
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
// // Created by botayhard on 08.02.19. // #include<stdio.h> #include<string.h> int main() { unsigned long long int a[5], res = 0; char s[1000001]; scanf("%lld %lld %lld %lld", &a[1], &a[2], &a[3], &a[4]); scanf("%s", s); for (int i = strlen(s); i > -1; i--){ if (s[i] == '1') {res+=a[1];} if (s[i] == '2') {res+=a[2];} if (s[i] == '3') {res+=a[3];} if (s[i] == '4') {res+=a[4];} } printf("%lld",res); }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
0241e60a03ad6148e0e8702505e98f49
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include<stdio.h> #include<string.h> int main() { int ch[1000]; char arr[100000]; int cp[4]= { 0,0,0,0 }; long long int a,b,c,d,e,i=0,tep=0,temp=0,j=0,k=0,l=0,m=0,n=0; for(j=1; j<=4; j++) scanf("%d",&ch[j]); scanf("%s",arr); b=strlen(arr); k=0; i=0; for(i=0;i<b;i++) { k+=ch[(arr[i]-'0')]; } printf("%lld\n",k); return 0; }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
672bc892b7e5a4b8ae7c3dcb243836a5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include<stdio.h> #include<string.h> int main () { int s,i; int t[10000]; char c[100000]; s=0; for (i=0;i<=3;i++) { scanf("%d",&t[i]); } scanf("%s",&c); for (i=0;i<strlen(c);i++) { switch (c[i]){ case '1': s=s+t[0]; break; case '2': s=s+t[1]; break; case '3': s=s+t[2]; break; case '4': s=s+t[3]; break; default:-1;} } printf("%d",s); return 0; }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
145b96550b8ca48c3dc566f4ff225554
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include<stdio.h> #include<string.h> int main() { int a[4],cal=0; for(int i=0;i<4;i++) scanf("%d",&a[i]); char s[100000]; scanf("%s",s); for(int i=0;i<strlen(s);i++) { if(s[i]=='1') cal+=a[0]; if(s[i]=='2') cal+=a[1]; if(s[i]=='3') cal+=a[2]; if(s[i]=='4') cal+=a[3]; } printf("%d",cal); }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
b8cd2486912926bd77020cd499cfe2ab
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include<stdio.h> #include<string.h> int main() { int a[10],l,i,c=0; char str[1000000]; for(i=0;i<4;i++) { scanf("%d",&a[i]); } scanf("%s",str); l=strlen(str); for(i=0;i<l;i++) { if(str[i]=='1') { c+=a[0]; } else if(str[i]=='2') { c+=a[1]; } else if(str[i]=='3') { c+=a[2]; } else if(str[i]=='4') { c+=a[3]; } } printf("%d\n",c); return 0; }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
a24570600443b881fb36094650a94114
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include<stdio.h> int main() { int a[4],i,temp,s=0; char c[100000]; for(i=0;i<4;i++) scanf("%d",&a[i]); scanf("%s",c); for(i=0;c[i]!='\0';i++) { if(c[i]-48==1) { temp=c[i]-48; s=s+a[temp-1]; } else if(c[i]-48==2) { temp=c[i]-48; s=s+a[temp-1]; } else if(c[i]-48==3) { temp=c[i]-48; s=s+a[temp-1]; } else { temp=c[i]-48; s=s+a[temp-1]; } } printf("%d\n",s); }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
c3c669ba61c2ff0e16427ff1f9d970f9
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
/* * @Author: Kabid * @Date: 2020-04-16 00:45:39 */ #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #define in(x) scanf("%d", &x); #define ins(x) scanf("%s", &x); #define out(x) printf("%d", x); #define _ putchar(' '); #define lin puts(""); int t,i,j,k,l,x=0; int c=0,m=0; char s[100001]; //char sa[]={"10"},sb[]={"01"}; int a[100001],b[2]={0}; int main(){ //in(t) for(i=1;i<=4;i++) in(a[i]) ins(s) l=strlen(s); for(i=0;i<l;i++) c+=a[s[i]-'0']; out(c) lin return 0; }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
0c72378e823e20a78440ebfb6e59fd0f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include<stdio.h> #include<string.h> int main(){ int n,i,j,sum=0,A[4]; char str[100000]; scanf("%d %d %d %d",&A[0],&A[1],&A[2],&A[3]); scanf("%s",str); //printf("%d %d %d %d",A[0],A[1],A[2],A[3]); for(i=0;i<=strlen(str)-1;i++){ if(str[i]=='1') sum=sum+A[0]; else if(str[i]=='2') sum=sum+A[1]; else if(str[i]=='3') sum=sum+A[2]; else if(str[i]=='4') sum=sum+A[3]; // printf("1\n") ; } printf("%d",sum); }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
9fb768b93c6fd51c25ed20182d45d600
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include<stdio.h> #include<string.h> int main() { long int a[4],sum=0; char s[100000]; for(int i=0; i<4; i++) scanf("%ld",&a[i]); scanf("%s",s); for(int k=0;k<strlen(s);k++) { sum=sum+a[s[k]-'1']; } printf("%ld",sum); return 0; }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
f51a91d36b851e9acd1dae2e7c565a73
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include <stdio.h> #include <stdlib.h> #include<string.h> int main() { int a,q,w,s,l,j=0; scanf("%d %d %d %d",&a,&q,&w,&s); char b[100001]; scanf("%s",&b); l=strlen(b); for(int i=0;i<l;i++){ if(b[i]=='1'){ j+=a; } else if(b[i]=='2'){ j+=q; } else if(b[i]=='3'){ j+=w; } else if(b[i]=='4'){ j+=s; } } printf("%d",j); return 0; }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
daf731c928f1a5f8cab2c0c00c13123f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include<stdio.h> int main() { int a,b,c,d,cal=0,i; char str[100100]; scanf("%d %d %d %d\n",&a,&b,&c,&d); if(a==0 && b==0 && c==0 && d==0) { printf("%d",cal); return 0; } gets(str); for(i=0;str[i]!='\0';i++) { if(str[i]=='1') { cal=cal+a; } else if(str[i]=='2') { cal=cal+b; } else if(str[i]=='3') { cal=cal+c; } else if(str[i]=='4') { cal=cal+d; } } printf("%d",cal); return 0; }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
b667be6cf9464834e794bae336f59ab4
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include<string.h> #include<stdio.h> int main(){ int a[4],n,cal=0; char str[100000]; for(int j=0;j<4;j++){ scanf("%d",&a[j]); } scanf("%s",str); n=strlen(str); for(int i=0;i<n;i++){ if(str[i]=='1') cal=cal+a[0]; if(str[i]=='2') cal=cal+a[1]; if(str[i]=='3') cal=cal+a[2]; if(str[i]=='4') cal=cal+a[3]; } printf("%d",cal); }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
f457a1da8ab7ea7453f5f3c4c432738a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include <stdio.h> int main() { int a1, a2, a3, a4; scanf("%d%d%d%d", &a1, &a2, &a3, &a4); int cal = 0; char s[100001]; scanf("%s", s); int i=0; while(s[i]!= 0) { if(s[i] == '1') cal+=a1; if(s[i] == '2') cal+=a2; if(s[i] == '3') cal+=a3; if(s[i] == '4') cal+=a4; i++; } printf("%d", cal); return 0; }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
8038ebd4c75ce22a23bcd704c21e1b8e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include<stdio.h> #include<string.h> int main () { int h,c=0,d=0,a=0,b=0,i,A,B,C,D,t; char s[100000]; scanf("%d",&A); scanf("%d",&B); scanf("%d",&C); scanf("%d",&D); scanf("%s",s); h=strlen(s); for(i=0;i<h;i++){ if(s[i]=='1'){ a++;} else if(s[i]=='2'){ b++; } else if(s[i]=='3'){ c++; } else d++; } t=(a*A)+(b*B)+(c*C)+(d*D); printf("%d",t); return 0; }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
54692e5a68366eb237131df15bfd40ce
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include <stdio.h> #include <string.h> int main() { static char s[100001]; static int aa[4]; int n, i, sum; for (i = 0; i < 4; i++) scanf("%d", &aa[i]); scanf("%s", s); n = strlen(s); sum = 0; for (i = 0; i < n; i++) if (s[i] == '1') sum += aa[0]; else if (s[i] == '2') sum += aa[1]; else if (s[i] == '3') sum += aa[2]; else sum += aa[3]; printf("%d\n", sum); return 0; }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
8ef1a3e714f1d990ac837caee81b224b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include "stdio.h" #include "string.h" int main() { int i,n; long long int sum; char b[100000000]={}; sum=0; long int a[4]={}; for(i=0;i<4;i++) { scanf("%ld",&a[i]); } getchar(); scanf("%s",&b[0]); for(n=0;n<1000000;n++) { if(b[n]=='NULL') break; sum=a[(b[n]-49)]+sum; } printf("%ld",sum); return 0; }
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
Print a single integer β€” the total number of calories that Jury wastes.
C
db9065d975878227a749083f0036a169
f21a0096f3e1818bf2035f7ff44bf8b0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1400686200
["1 2 3 4\n123214", "1 5 3 2\n11221"]
null
PASSED
800
standard input
1 second
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≀ a1, a2, a3, a4 ≀ 104). The second line contains string s (1 ≀ |s| ≀ 105), where the Ρ–-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
["13", "13"]
#include<stdio.h> int main() { int i,count=0; char A[100001]; int B[4]; for(i=0;i<4;i++) scanf("%d",&B[i]); scanf("%s",A); for(i=0;A[i]!='\0';i++) count=count+B[(A[i]-'0')-1]; printf("%d",count); return 0; }