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
sequencelengths
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
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
C
9037f487a426ead347baa803955b2c00
20f39ec42c4d09a1257b2b609ac28a1f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "geometry", "math" ]
1359732600
["3\n30\n60\n90"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case β€” a square.
PASSED
1,100
standard input
2 seconds
The first line of input contains an integer t (0 < t < 180) β€” the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) β€” the angle the robot can make corners at measured in degrees.
["NO\nYES\nYES"]
#include<stdio.h> int main() { int t,i,a; scanf("%d",&t); for(i=0;i<t;i++) { scanf("%d",&a); if((360%(180-a))==0) printf("YES\n"); else printf("NO\n"); } }
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
C
9037f487a426ead347baa803955b2c00
be0fd919e682aa44b4652a52e7fbc38b
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "geometry", "math" ]
1359732600
["3\n30\n60\n90"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case β€” a square.
PASSED
1,100
standard input
2 seconds
The first line of input contains an integer t (0 &lt; t &lt; 180) β€” the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) β€” the angle the robot can make corners at measured in degrees.
["NO\nYES\nYES"]
#include <stdio.h> int main() { int n,k,a[200],i; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { k=360%(180-a[i]); if(k==0&&a[i]>=60) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
C
9037f487a426ead347baa803955b2c00
1b764051e88fc95e39776ccf65e2f9ce
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "geometry", "math" ]
1359732600
["3\n30\n60\n90"]
NoteIn the first test case, it is impossible to build the fence, since there is no regular polygon with angle .In the second test case, the fence is a regular triangle, and in the last test case β€” a square.
PASSED
1,100
standard input
2 seconds
The first line of input contains an integer t (0 &lt; t &lt; 180) β€” the number of tests. Each of the following t lines contains a single integer a (0 &lt; a &lt; 180) β€” the angle the robot can make corners at measured in degrees.
["NO\nYES\nYES"]
main() { int T; scanf("%d",&T); while(T--) { int ang; scanf("%d",&ang); if(360%(180-ang)==0) printf("YES\n"); else printf("NO\n"); } return 0; }
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers β€” the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
C
6b7d6f5c07b313c57d52db6a48d3eeef
24b91e716ce27e08681332d0d4717313
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1368968400
["4\n100 10 1 0", "3\n2 70 3"]
null
PASSED
1,600
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 100) β€” the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≀ di ≀ 100).
["4\n0 1 10 100", "2\n2 70"]
#include<stdio.h> #define fr(i,n) for(i=0;i<n;i++) #define Fr(i,m,n) for(i=m;i<n;i++) int a[103],ans[103]; int main() { int n=0,x,k,i,flag=0; scanf("%d",&k); fr(i,k) {scanf("%d",&x); a[x]=1; } if(a[100]==1) ans[n++]=100; for(i=10;i<91;i+=10) { if(a[i]==1) { ans[n++] = i; break; } } if(i==100) { Fr(i,11,100) { if(a[i]==1) { ans[n++] = i; flag=1; break; } } } if(flag==0) Fr(i,1,10) { if(a[i]==1) { ans[n++] = i; break; } } if(a[0]==1) ans[n++] = 0; printf("%d\n",n); fr(i,n) printf("%d ",ans[i]); return 0; }
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers β€” the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
C
6b7d6f5c07b313c57d52db6a48d3eeef
3cea4acbfacb4c22114d2394fb480b71
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1368968400
["4\n100 10 1 0", "3\n2 70 3"]
null
PASSED
1,600
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 100) β€” the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≀ di ≀ 100).
["4\n0 1 10 100", "2\n2 70"]
#include<stdio.h> #include<string.h> char a[105][5]; int hun=0,zero=0; void pf(void) { if(hun) { printf("100 "); } if(zero) { printf("0"); } } int main() { int n,i,eve=130,ten=130,one=130; int cont=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%s",a[i]); if(a[i][0]=='1'&&a[i][2]=='0') { hun=1; cont++; continue; } if(a[i][0]=='0') { zero=1; cont++; continue; } if(strlen(a[i])==2&&a[i][1]=='0') { ten=i; } if(strlen(a[i])==2&&a[i][1]!=0) { eve=i; } if(strlen(a[i])==1) { one=i; } } if(ten!=130&&one!=130) { printf("%d\n",cont+2); pf(); if(zero) { printf(" "); } printf("%s ",a[ten]); printf("%s\n",a[one]); return 0; } if(ten==130&&one!=130) { printf("%d\n",cont+1); pf(); if(zero) { printf(" "); } printf("%s\n",a[one]); return 0; } if(ten!=130&&one==130) { printf("%d\n",cont+1); pf(); if(zero) { printf(" "); } printf("%s\n",a[ten]); return 0; } if(ten==130&&one==130&&eve!=130) { printf("%d\n",cont+1); pf(); if(zero) { printf(" "); } printf("%s",a[eve]); printf("\n"); return 0; } printf("%d\n",cont); pf(); printf("\n"); return 0; }
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers β€” the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
C
6b7d6f5c07b313c57d52db6a48d3eeef
15f14f3a036ecf887cbbc58470315180
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1368968400
["4\n100 10 1 0", "3\n2 70 3"]
null
PASSED
1,600
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 100) β€” the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≀ di ≀ 100).
["4\n0 1 10 100", "2\n2 70"]
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #define max(a,b) ((a)>(b))?(a):(b) #define min(a,b) ((a)<(b))?(a):(b) #define si(n) scanf("%d",&n) #define ss(s) scanf("%s",s) #define sort(a,n) qsort(a,n,sizeof(int),compare) #define pi(n) printf("%d ",n) #define ps(s) printf("%s",s) #define loop(i,n) for(i=0;i<n;i++) #define Loop(i,n) for(i=1;i<=n;i++) typedef long long int lld; #define MAX 110 int a[MAX],b[MAX]; int compare(const void *a,const void *b) { return *(int *)a-*(int *)b; } int main() { int i,j,n,t,p=-1,l,ans=0,flag=0,flag2=0,ct=0,flag3=0; si(n); loop(i,n) si(a[i]); loop(i,n) { if(a[i]==0) b[ct++]=a[i]; else if(a[i]<10) { if(!flag) { b[ct++]=a[i]; flag=1; } } else if(a[i]==100) { b[ct++]=100; flag3=1; } else if(a[i]%10==0) { if(!flag2) { b[ct++]=a[i]; flag2=1; } } else p=a[i]; } if(!flag2 && !flag) { if(p!=-1) b[ct++]=p; } ans=ct; pi(ct); puts(""); loop(i,ct) { pi(b[i]); } return 0; }
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers β€” the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
C
6b7d6f5c07b313c57d52db6a48d3eeef
e2ba11d15f7a17dd60e7e963d37ed459
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1368968400
["4\n100 10 1 0", "3\n2 70 3"]
null
PASSED
1,600
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 100) β€” the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≀ di ≀ 100).
["4\n0 1 10 100", "2\n2 70"]
#include<stdio.h> #include<string.h> int aray[103], hold1[101], hold2[101]; int res[102]; int main() { int n ,i, j, k,l=0, three=0, two=0, one=0, zero=0, p; scanf("%d", &n); k=0; for(i=0;i<101;i++){ res[i]=-2; } for(i=0;i<n;i++){ scanf("%d", &aray[i]); if(aray[i]==100){ three++; } else if(aray[i]>9 && aray[i]<100){ two++; if((aray[i]%10)==0){ hold1[k]=aray[i]; k++; } else{ hold2[l]=aray[i]; l++; } } else if(aray[i]==0){ zero++; } else{ one++; p=i; } } i=0; if(n==1){ printf("1\n%d ", aray[0]); return 0; } if(three>=1){ res[0]=100; if(one>0){ if(hold1[0]!=0){ res[1]=hold1[0];} res[2]=aray[p]; if(zero>0){ res[3]=0; } } else{ if(hold2[0]!=0){ res[1]=hold2[0];} else if(hold1[0]!=0){ res[1]=hold1[0]; } if(zero>0){ res[2]=0; } } } else{ if(one>0){ if(hold1[0]!=0){ res[0]=hold1[0]; } res[1]=aray[p]; if(zero>0){ res[2]=0; } } else{ if(hold1[0]!=0){ res[0]=hold1[0]; } else if(hold2[0]!=0){ res[0]=hold2[0]; } if(zero>0){ res[1]=0; } } } int count=0; for(i=0;i<101;i++){ if(res[i]!=-2){ count++; } } printf("%d\n", count); for(i=0;i<15;i++){ if(res[i]!=-2){ printf("%d ", res[i]); } } return 0; }
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers β€” the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
C
6b7d6f5c07b313c57d52db6a48d3eeef
be79ad48a413e2eac16cf9e90f3f777e
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1368968400
["4\n100 10 1 0", "3\n2 70 3"]
null
PASSED
1,600
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 100) β€” the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≀ di ≀ 100).
["4\n0 1 10 100", "2\n2 70"]
#include<stdio.h> int main() { int k,ar[100],t=0,i,a[100],m=0,n=0,o=0,p=0,q=0,b,c,d,e; scanf("%d\n",&k); while(k--) { scanf("%d",&ar[t++]); } for(i=0;i<t;i++) { if(ar[i]==0) { a[m++]=ar[i]; } else if(ar[i]==100 && n==0) { b=ar[i]; n++; } else if(ar[i]<10 && o==0) { c=ar[i]; o++; } } if(o>0) { for(i=0;i<t;i++) { if(ar[i]>=10 && ar[i]<100 && ar[i]%10==0) { d=ar[i]; p++; break; } } } else { for(i=0;i<t;i++) { if(ar[i]>=10 && ar[i]<100) { e=ar[i]; q++; break; } } } int tot=m+n+o+p+q; printf("%d\n",tot); for(i=0;i<m;i++) printf("%d\t",a[i]); if(n!=0) printf("%d\t",b); if(o!=0) printf("%d\t",c); if(p!=0) printf("%d\t",d); if(q!=0) printf("%d",e); return 0; }
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers β€” the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
C
6b7d6f5c07b313c57d52db6a48d3eeef
60745c38f2a9657eb96664b9b0d11e44
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1368968400
["4\n100 10 1 0", "3\n2 70 3"]
null
PASSED
1,600
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 100) β€” the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≀ di ≀ 100).
["4\n0 1 10 100", "2\n2 70"]
#include<stdio.h> int main() { int n,i,j=0,k=0,l=0,count=0,m=0,a=0,b=0,c=0; scanf("%d",&n); int arr[n],arr1[n]; for(i=0;i<n;i++) scanf("%d",&arr[i]); for(i=0;i<n;i++) { if(arr[i]==100) { if(a==0) { count++; a=1; arr1[j]=100; j++; } } else if(arr[i]%10==0&&arr[i]!=100&&arr[i]!=0) { if(b==0) { count++; b=1; arr1[j]=arr[i]; j++; } } else if(arr[i]==0) { count++; arr1[j]=0; j++; } else { if(arr[i]<10&&c==0) { count++; arr1[j]=arr[i]; j++; c=1; } else if(arr[i]>10&&c==0) { k=arr[i]; } } } if(b==0&&k!=0&&c==0) { count++; printf("%d\n",count); for(m=0;m<j;m++) printf("%d ",arr1[m]); printf("%d",k); } else { printf("%d\n",count); for(m=0;m<j;m++) printf("%d ",arr1[m]); } }
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers β€” the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
C
6b7d6f5c07b313c57d52db6a48d3eeef
708e4aa10db7fa5c89cd66b8fa416a3c
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1368968400
["4\n100 10 1 0", "3\n2 70 3"]
null
PASSED
1,600
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 100) β€” the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≀ di ≀ 100).
["4\n0 1 10 100", "2\n2 70"]
#include<stdio.h> #include<string.h> int vis[110],b[110]; int main(){ int N,t; while(scanf("%d",&N)!=EOF){ memset(vis,0,sizeof(vis)); int i,j,ans=0,ca; for(i=0;i<N;i++){ scanf("%d",&t);ca=t; vis[t]++;} int ok1=0,ok2=0,ok3=0,t1,t2,t3,k=0; for(i=1;i<10;i++) if(vis[i]) {ok1=1;t1=i;break;} for(i=10;i<100;i+=10) if(vis[i]) {ok2=1;t2=i;break;} for(i=1;i<100;i++) if(vis[i]) {ok3=1;t3=i;break;} if(ok1&&ok2) {ans+=2;b[k++]=t1;b[k++]=t2;} else if(ok3&&(vis[0]||vis[100])) {ans++;b[k++]=t3;} if((ok3||vis[0])&&vis[100]) {ans++;b[k++]=100;} ans+=vis[0]; for(i=0;i<vis[0];i++) b[k++]=0; if(k>0){ printf("%d\n",ans); for(i=0;i<k-1;i++) printf("%d ",b[i]); printf("%d\n",b[i]);} else printf("1\n%d\n",ca);} return 0;}
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers β€” the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
C
6b7d6f5c07b313c57d52db6a48d3eeef
dfb898701f7f67c383cf4195e8400763
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1368968400
["4\n100 10 1 0", "3\n2 70 3"]
null
PASSED
1,600
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 100) β€” the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≀ di ≀ 100).
["4\n0 1 10 100", "2\n2 70"]
#include <stdio.h> int main() { int n; int z=0, lt=0, lh1=0, lh2=0, h=0; int lts[9], lh1s[9], lh2s[80]; int i; int res[5]; scanf("%d\n",&n); for(i = 0; i<n; i++) { int d; scanf("%d",&d); if(d==0) { z++; } else if(d<10) { lts[lt++] = d; } else if(d<100 && d%10==0) { lh1s[lh1++] = d; } else if(d<100) { lh2s[lh2++] = d; } else { h++; } } n = 0; if(z > 0) res[n++] = 0; if(h > 0) res[n++] = 100; if(lt > 0) res[n++] = lts[0]; if(lh1 > 0) res[n++] = lh1s[0]; if(lh1 == 0 && lt == 0 && lh2>0) res[n++] = lh2s[0]; printf("%d\n",n); for(i = 0; i<n-1; i++) printf("%d ",res[i]); printf("%d\n",res[n-1]); return 0; }
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers β€” the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
C
6b7d6f5c07b313c57d52db6a48d3eeef
d1e49613e9a6607948fe75e2498b1fe1
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1368968400
["4\n100 10 1 0", "3\n2 70 3"]
null
PASSED
1,600
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 100) β€” the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≀ di ≀ 100).
["4\n0 1 10 100", "2\n2 70"]
#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { int a; int b; int c; }; int main() { int n,i,flag=0,k=0,j,r,m,l=0,x,i1,min=0; struct node pr[1000]; char s[1000]; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%s",s); r=0; flag=0; x=1; m=1; for(j=strlen(s)-1;j>=0;j--) { if(s[j]-'0'==0) { m=0; } r+=(s[j]-'0')*x; x*=10; } if(r==0) { l=1; } else { for(j=0;j<k;j++) { if(pr[j].a==strlen(s)) { i1=j; flag=1; } } if((flag==0)) { pr[k].a=strlen(s); pr[k].b=r; pr[k].c=m; if(m==1) { min++; } k++; } else if((pr[i1].c==1)&&(m==0)) { pr[i1].b=r; pr[i1].c=0; min--; } } } k-=min; if(min!=0) { k++; } if(l==0) { printf("%d\n",k); } else { printf("%d\n",k+1); printf("0 "); } l=0; for(i=0;i<k;i++) { if((pr[i].c==0)||(l==0)) { printf("%d ",pr[i].b); if(pr[i].c==1) { l=1; } } } return 0; }
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers β€” the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
C
6b7d6f5c07b313c57d52db6a48d3eeef
491784cb8e299934342c9f828f2fc0d2
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1368968400
["4\n100 10 1 0", "3\n2 70 3"]
null
PASSED
1,600
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 100) β€” the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≀ di ≀ 100).
["4\n0 1 10 100", "2\n2 70"]
#include<stdio.h> #include<stdlib.h> int main() { int n; scanf("%d",&n); int x; int y=0; int ar[10]={0}; int i=0; int n2=n; int a=0,b=0,c=0,d=0; int arr[109]={0}; int u=0;; while(n>0) { scanf("%d",&x); arr[u]=x; u++; if(x==100 && a==0) { ar[i]=x; a++; y++; i++; } if(b==0) if(x==90 || x==80 || x==70 || x==60 ||x==50 || x==40 || x==30 || x==20 || x==10) { ar[i]=x; b++; i++; y++; } if(x-9<=0 && c==0 && x-9>-9) { ar[i]=x; i++; c++; y++; } if(x==0 && d==0) { ar[i]=x; i++; d++; y++; } n--; } int g=0; a=0; b=0; c=0; int s=0; for(i=0;i<y;i++) { if(ar[i]!=100 && ar[i]!=0) { g++; } } int o=0; int s2=0; if(g==0) { // printf("haha\n"); for(i=0;i<u;i++) { if(arr[i]==100 && a==0) { ar[o]=arr[i]; // printf("hoho\n"); o++; a++; s2++; } if(arr[i]==0 && b==0) { ar[o]=arr[i]; o++; b++; s2++; } if(c==0 && arr[i]!=100 && arr[i]!=0) { ar[o]=arr[i]; o++; c++; s2++; } } y=o; s=s2; } o=y; s2=s; printf("%d\n",o); for(i=0;i<o;i++) printf("%d ",ar[i]); printf("\n"); return 0; }
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers β€” the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
C
6b7d6f5c07b313c57d52db6a48d3eeef
bc4af20b4cf2270aa5c1083305528961
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1368968400
["4\n100 10 1 0", "3\n2 70 3"]
null
PASSED
1,600
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 100) β€” the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≀ di ≀ 100).
["4\n0 1 10 100", "2\n2 70"]
int n,a,b,c,d,e; main() { int i,j,k; while(~scanf("%d",&n)) { a=b=c=d=e=-1; while(n--) { scanf("%d",&i); if(i==0) a=0; else if(i<10) b=i; else if(i<100&&i%10==0) c=i; else if(i<100) d=i; else e=i; } n=0; if(a!=-1) n++; if(b!=-1) n++; if(c!=-1) n++; if(b==-1&&c==-1&&d!=-1) n++; if(e!=-1) n++; printf("%d\n",n); i=0; if(a!=-1) { if(!i) i=1; else printf(" "); printf("%d",a); } if(b!=-1) { if(!i) i=1; else printf(" "); printf("%d",b); } if(c!=-1) { if(!i) i=1; else printf(" "); printf("%d",c); } if(b==-1&&c==-1&&d!=-1) { if(!i) i=1; else printf(" "); printf("%d",d); } if(e!=-1) { if(!i) i=1; else printf(" "); printf("%d",e); } puts(""); } }
Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers β€” the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
C
6b7d6f5c07b313c57d52db6a48d3eeef
1ff2c83066c6ffa48e433ff960716370
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1368968400
["4\n100 10 1 0", "3\n2 70 3"]
null
PASSED
1,600
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 100) β€” the number of integers. The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≀ di ≀ 100).
["4\n0 1 10 100", "2\n2 70"]
#include<stdio.h> int main(){ int p=-5,k,a[105],i,x=-5,y=-5,z=-5,counter=0,flag=0; scanf("%d",&k); for(i=0;i<k;i++) scanf("%d",&a[i]); if(k==1){ printf("1\n"); printf("%d",a[0]); flag=1;} for(i=0;i<k;i++){ if(a[i]==0){ counter++; p=i; break;}} for(i=0;i<k;i++){ if(a[i]>=1&&a[i]<=9){ counter++; x=i; break;}} for(i=0;i<k;i++){ if(a[i]>=10&&a[i]<=99){ if(a[i]%10==0){ counter++; y=i; break;} if(a[i]%10!=0&&x<0&&p>=0){ counter++; y=i; break;} }} for(i=0;i<k;i++){ if(a[i]==100){ counter++; z=i; break;}} for(i=0;i<k;i++){ if(a[i]>=10&&a[i]<=99){ if(y<0&&x<0){ y=i; counter++; break;}}} if(flag==0){ printf("%d\n",counter); if(x>=0&&x<k) printf("%d ",a[x]); if(y>=0&&y<k) printf("%d ",a[y]); if(z>=0&&z<k) printf("%d ",a[z]); if(p>=0&&p<k) printf("%d ",a[p]);} return 0;}
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example.Now let's create a task this way. We will use the task: you are given a tree, please calculate the distance between any pair of its nodes. Yes, it is very easy, but the inverse version is a bit harder: you are given an n × n distance matrix. Determine if it is the distance matrix of a weighted tree (all weights must be positive integers).
If there exists such a tree, output "YES", otherwise output "NO".
C
a5363163c1c2dfed91947a582ac28bda
6da13f79bdd179e1f15fe91bf62c9f18
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dsu", "dfs and similar", "trees", "shortest paths" ]
1411918500
["3\n0 2 7\n2 0 9\n7 9 0", "3\n1 2 7\n2 0 9\n7 9 0", "3\n0 2 2\n7 0 9\n7 9 0", "3\n0 1 1\n1 0 1\n1 1 0", "2\n0 0\n0 0"]
NoteIn the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7.In the second example, it is impossible because d1, 1 should be 0, but it is 1.In the third example, it is impossible because d1, 2 should equal d2, 1.
PASSED
1,900
standard input
2 seconds
The first line contains an integer n (1 ≀ n ≀ 2000) β€” the number of nodes in that graph. Then next n lines each contains n integers di, j (0 ≀ di, j ≀ 109) β€” the distance between node i and node j.
["YES", "NO", "NO", "NO", "NO"]
/* practice with Dukkha */ #include <stdio.h> #define N 2000 int dd[N][N]; int aa[N]; int partition(int l, int r) { int i, j, p, q, a, b, c, u, v, tmp; if (r == l) return 1; a = aa[l], b = -1, j = -1; for (i = l + 1; i <= r; i++) { c = aa[i]; if (b == -1 || dd[a][b] > dd[a][c]) { j = i; b = c; } } tmp = aa[r], aa[r] = aa[j], aa[j] = tmp; for (i = l + 1; i <= r - 1; i++) { c = aa[i]; if (dd[a][c] == dd[b][c]) return 0; } i = l, j = r; while (1) { while (j - i > 1 && dd[a][aa[i + 1]] < dd[b][aa[i + 1]]) i++; while (j - i > 1 && dd[a][aa[j - 1]] > dd[b][aa[j - 1]]) j--; if (j - i == 1) break; i++, j--; tmp = aa[i], aa[i] = aa[j], aa[j] = tmp; } for (p = l; p <= i; p++) { u = aa[p]; for (q = j; q <= r; q++) { v = aa[q]; if (dd[u][v] - dd[a][b] != dd[u][a] + dd[b][v]) return 0; } } return partition(l, i) && partition(j, r); } int main() { int n, i, j; scanf("%d", &n); for (i = 0; i < n; i++) for (j = 0; j < n; j++) scanf("%d", &dd[i][j]); for (i = 0; i < n; i++) { if (dd[i][i] != 0) { printf("NO\n"); return 0; } for (j = i + 1; j < n; j++) if (dd[i][j] == 0 || dd[j][i] == 0 || dd[i][j] != dd[j][i]) { printf("NO\n"); return 0; } } for (i = 0; i < n; i++) aa[i] = i; printf(partition(0, n - 1) ? "YES\n" : "NO\n"); return 0; }
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height $$$h$$$, and there is a moving platform on each height $$$x$$$ from $$$1$$$ to $$$h$$$.Each platform is either hidden inside the cliff or moved out. At first, there are $$$n$$$ moved out platforms on heights $$$p_1, p_2, \dots, p_n$$$. The platform on height $$$h$$$ is moved out (and the character is initially standing there).If you character is standing on some moved out platform on height $$$x$$$, then he can pull a special lever, which switches the state of two platforms: on height $$$x$$$ and $$$x - 1$$$. In other words, the platform you are currently standing on will hide in the cliff and the platform one unit below will change it state: it will hide if it was moved out or move out if it was hidden. In the second case, you will safely land on it. Note that this is the only way to move from one platform to another.Your character is quite fragile, so it can safely fall from the height no more than $$$2$$$. In other words falling from the platform $$$x$$$ to platform $$$x - 2$$$ is okay, but falling from $$$x$$$ to $$$x - 3$$$ (or lower) is certain death. Sometimes it's not possible to come down from the cliff, but you can always buy (for donate currency) several magic crystals. Each magic crystal can be used to change the state of any single platform (except platform on height $$$h$$$, which is unaffected by the crystals). After being used, the crystal disappears.What is the minimum number of magic crystal you need to buy to safely land on the $$$0$$$ ground level?
For each query print one integer β€” the minimum number of magic crystals you have to spend to safely come down on the ground level (with height $$$0$$$).
C
d0c50562764f2008045fe57e5da5de1c
33ddc916be4d64d917b8edebbf32eb5c
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "math" ]
1570545300
["4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1"]
null
PASSED
1,600
standard input
2 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) β€” the number of queries. Each query contains two lines and is independent of all other queries. The first line of each query contains two integers $$$h$$$ and $$$n$$$ ($$$1 \le h \le 10^9$$$, $$$1 \le n \le \min(h, 2 \cdot 10^5)$$$) β€” the height of the cliff and the number of moved out platforms. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$h = p_1 &gt; p_2 &gt; \dots &gt; p_n \ge 1$$$) β€” the corresponding moved out platforms in the descending order of their heights. The sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.
["0\n1\n2\n0"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { int q; int h, n; int *p; scanf("%d", &q); for(int j = 0; j < q; ++j) { scanf("%d%d", &h, &n);; p = calloc(n + 1, sizeof(*p)); for(int t = 0; t < n; ++t) { int a; scanf("%d", &p[t]); } int count = 0; for(int i = 1; i < n;) { if(i + 1 == n) { if(p[i] + 1 > 2) { count++; break; } } if(p[i] - p[i + 1] == 1) { i += 2; } else { i++; count++; } } printf("%d\n", count); free(p); } return 0; }
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height $$$h$$$, and there is a moving platform on each height $$$x$$$ from $$$1$$$ to $$$h$$$.Each platform is either hidden inside the cliff or moved out. At first, there are $$$n$$$ moved out platforms on heights $$$p_1, p_2, \dots, p_n$$$. The platform on height $$$h$$$ is moved out (and the character is initially standing there).If you character is standing on some moved out platform on height $$$x$$$, then he can pull a special lever, which switches the state of two platforms: on height $$$x$$$ and $$$x - 1$$$. In other words, the platform you are currently standing on will hide in the cliff and the platform one unit below will change it state: it will hide if it was moved out or move out if it was hidden. In the second case, you will safely land on it. Note that this is the only way to move from one platform to another.Your character is quite fragile, so it can safely fall from the height no more than $$$2$$$. In other words falling from the platform $$$x$$$ to platform $$$x - 2$$$ is okay, but falling from $$$x$$$ to $$$x - 3$$$ (or lower) is certain death. Sometimes it's not possible to come down from the cliff, but you can always buy (for donate currency) several magic crystals. Each magic crystal can be used to change the state of any single platform (except platform on height $$$h$$$, which is unaffected by the crystals). After being used, the crystal disappears.What is the minimum number of magic crystal you need to buy to safely land on the $$$0$$$ ground level?
For each query print one integer β€” the minimum number of magic crystals you have to spend to safely come down on the ground level (with height $$$0$$$).
C
d0c50562764f2008045fe57e5da5de1c
813254676e1bd165a0f2109d8db802af
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "math" ]
1570545300
["4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1"]
null
PASSED
1,600
standard input
2 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) β€” the number of queries. Each query contains two lines and is independent of all other queries. The first line of each query contains two integers $$$h$$$ and $$$n$$$ ($$$1 \le h \le 10^9$$$, $$$1 \le n \le \min(h, 2 \cdot 10^5)$$$) β€” the height of the cliff and the number of moved out platforms. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$h = p_1 &gt; p_2 &gt; \dots &gt; p_n \ge 1$$$) β€” the corresponding moved out platforms in the descending order of their heights. The sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.
["0\n1\n2\n0"]
#include <stdio.h> int P[200002]; int main() { int i; int Q; int h, n; char F; int R; scanf("%d", &Q); while (Q--) { scanf("%d %d", &h, &n); for (i = 0; i < n; i++) { scanf("%d", &P[i]); } P[n] = 0; P[n + 1] = 0; F = 0; R = 0; for (i = 0; i < n; i++) { if (F) { if (P[i] > P[i + 1] + 1) { R++; } else { F = 0; } } else if (P[i] == P[i + 1] + 1) { if (P[i] > P[i + 2] + 2) { R++; F = 1; } i++; } else { F = 1; } } printf("%d\n", R); } return 0; }
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height $$$h$$$, and there is a moving platform on each height $$$x$$$ from $$$1$$$ to $$$h$$$.Each platform is either hidden inside the cliff or moved out. At first, there are $$$n$$$ moved out platforms on heights $$$p_1, p_2, \dots, p_n$$$. The platform on height $$$h$$$ is moved out (and the character is initially standing there).If you character is standing on some moved out platform on height $$$x$$$, then he can pull a special lever, which switches the state of two platforms: on height $$$x$$$ and $$$x - 1$$$. In other words, the platform you are currently standing on will hide in the cliff and the platform one unit below will change it state: it will hide if it was moved out or move out if it was hidden. In the second case, you will safely land on it. Note that this is the only way to move from one platform to another.Your character is quite fragile, so it can safely fall from the height no more than $$$2$$$. In other words falling from the platform $$$x$$$ to platform $$$x - 2$$$ is okay, but falling from $$$x$$$ to $$$x - 3$$$ (or lower) is certain death. Sometimes it's not possible to come down from the cliff, but you can always buy (for donate currency) several magic crystals. Each magic crystal can be used to change the state of any single platform (except platform on height $$$h$$$, which is unaffected by the crystals). After being used, the crystal disappears.What is the minimum number of magic crystal you need to buy to safely land on the $$$0$$$ ground level?
For each query print one integer β€” the minimum number of magic crystals you have to spend to safely come down on the ground level (with height $$$0$$$).
C
d0c50562764f2008045fe57e5da5de1c
8d5f1de9387d0eb719228c6e1203b549
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "math" ]
1570545300
["4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1"]
null
PASSED
1,600
standard input
2 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) β€” the number of queries. Each query contains two lines and is independent of all other queries. The first line of each query contains two integers $$$h$$$ and $$$n$$$ ($$$1 \le h \le 10^9$$$, $$$1 \le n \le \min(h, 2 \cdot 10^5)$$$) β€” the height of the cliff and the number of moved out platforms. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$h = p_1 &gt; p_2 &gt; \dots &gt; p_n \ge 1$$$) β€” the corresponding moved out platforms in the descending order of their heights. The sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.
["0\n1\n2\n0"]
#include <stdio.h> int outPlatforms[200001]; int main() { int q; scanf("%d", &q); while (q--) { int h, n; scanf("%d %d", &h, &n); int count1; for (count1 = 0; count1 < n; count1++) { scanf("%d", &outPlatforms[count1]); } outPlatforms[n] = 0; int counter = 0; for (count1 = 1; count1 < n; count1++) { if (outPlatforms[count1] - outPlatforms[count1+1] > 1) { counter++; } else { count1++; } } printf("%d\n", counter); } return 0; }
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height $$$h$$$, and there is a moving platform on each height $$$x$$$ from $$$1$$$ to $$$h$$$.Each platform is either hidden inside the cliff or moved out. At first, there are $$$n$$$ moved out platforms on heights $$$p_1, p_2, \dots, p_n$$$. The platform on height $$$h$$$ is moved out (and the character is initially standing there).If you character is standing on some moved out platform on height $$$x$$$, then he can pull a special lever, which switches the state of two platforms: on height $$$x$$$ and $$$x - 1$$$. In other words, the platform you are currently standing on will hide in the cliff and the platform one unit below will change it state: it will hide if it was moved out or move out if it was hidden. In the second case, you will safely land on it. Note that this is the only way to move from one platform to another.Your character is quite fragile, so it can safely fall from the height no more than $$$2$$$. In other words falling from the platform $$$x$$$ to platform $$$x - 2$$$ is okay, but falling from $$$x$$$ to $$$x - 3$$$ (or lower) is certain death. Sometimes it's not possible to come down from the cliff, but you can always buy (for donate currency) several magic crystals. Each magic crystal can be used to change the state of any single platform (except platform on height $$$h$$$, which is unaffected by the crystals). After being used, the crystal disappears.What is the minimum number of magic crystal you need to buy to safely land on the $$$0$$$ ground level?
For each query print one integer β€” the minimum number of magic crystals you have to spend to safely come down on the ground level (with height $$$0$$$).
C
d0c50562764f2008045fe57e5da5de1c
d4d1cbed80ca38c2139494ca3f9099e6
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "math" ]
1570545300
["4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1"]
null
PASSED
1,600
standard input
2 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) β€” the number of queries. Each query contains two lines and is independent of all other queries. The first line of each query contains two integers $$$h$$$ and $$$n$$$ ($$$1 \le h \le 10^9$$$, $$$1 \le n \le \min(h, 2 \cdot 10^5)$$$) β€” the height of the cliff and the number of moved out platforms. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$h = p_1 &gt; p_2 &gt; \dots &gt; p_n \ge 1$$$) β€” the corresponding moved out platforms in the descending order of their heights. The sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.
["0\n1\n2\n0"]
/* practice with Dukkha */ #include <stdio.h> int main() { int q; scanf("%d", &q); while (q--) { int h, n, i, h_, p, cnt; scanf("%d%d%d", &h_, &n, &h_), h_++; cnt = 0, p = 0; for (i = 1; i < n; i++) { scanf("%d", &h); if (h_ - h > 1) { if (p == 1) cnt++; else p = 1; } else p ^= 1; h_ = h; } if (h_ > 1 && p == 1) cnt++; printf("%d\n", cnt); } return 0; }
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height $$$h$$$, and there is a moving platform on each height $$$x$$$ from $$$1$$$ to $$$h$$$.Each platform is either hidden inside the cliff or moved out. At first, there are $$$n$$$ moved out platforms on heights $$$p_1, p_2, \dots, p_n$$$. The platform on height $$$h$$$ is moved out (and the character is initially standing there).If you character is standing on some moved out platform on height $$$x$$$, then he can pull a special lever, which switches the state of two platforms: on height $$$x$$$ and $$$x - 1$$$. In other words, the platform you are currently standing on will hide in the cliff and the platform one unit below will change it state: it will hide if it was moved out or move out if it was hidden. In the second case, you will safely land on it. Note that this is the only way to move from one platform to another.Your character is quite fragile, so it can safely fall from the height no more than $$$2$$$. In other words falling from the platform $$$x$$$ to platform $$$x - 2$$$ is okay, but falling from $$$x$$$ to $$$x - 3$$$ (or lower) is certain death. Sometimes it's not possible to come down from the cliff, but you can always buy (for donate currency) several magic crystals. Each magic crystal can be used to change the state of any single platform (except platform on height $$$h$$$, which is unaffected by the crystals). After being used, the crystal disappears.What is the minimum number of magic crystal you need to buy to safely land on the $$$0$$$ ground level?
For each query print one integer β€” the minimum number of magic crystals you have to spend to safely come down on the ground level (with height $$$0$$$).
C
d0c50562764f2008045fe57e5da5de1c
520ca54570ac9658147dba8a6e091622
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "math" ]
1570545300
["4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1"]
null
PASSED
1,600
standard input
2 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) β€” the number of queries. Each query contains two lines and is independent of all other queries. The first line of each query contains two integers $$$h$$$ and $$$n$$$ ($$$1 \le h \le 10^9$$$, $$$1 \le n \le \min(h, 2 \cdot 10^5)$$$) β€” the height of the cliff and the number of moved out platforms. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$h = p_1 &gt; p_2 &gt; \dots &gt; p_n \ge 1$$$) β€” the corresponding moved out platforms in the descending order of their heights. The sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.
["0\n1\n2\n0"]
int q,h,n,c,d,x;main(){for(scanf("%d",&q);q--;){scanf("%d%d",&h,&n);for(c=1,d=0;n--;){scanf("%d",&x);if(h-x>1)d+=c,c=0;c^=1;h=x;}printf("%d ",d+c*(x>1));}}
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height $$$h$$$, and there is a moving platform on each height $$$x$$$ from $$$1$$$ to $$$h$$$.Each platform is either hidden inside the cliff or moved out. At first, there are $$$n$$$ moved out platforms on heights $$$p_1, p_2, \dots, p_n$$$. The platform on height $$$h$$$ is moved out (and the character is initially standing there).If you character is standing on some moved out platform on height $$$x$$$, then he can pull a special lever, which switches the state of two platforms: on height $$$x$$$ and $$$x - 1$$$. In other words, the platform you are currently standing on will hide in the cliff and the platform one unit below will change it state: it will hide if it was moved out or move out if it was hidden. In the second case, you will safely land on it. Note that this is the only way to move from one platform to another.Your character is quite fragile, so it can safely fall from the height no more than $$$2$$$. In other words falling from the platform $$$x$$$ to platform $$$x - 2$$$ is okay, but falling from $$$x$$$ to $$$x - 3$$$ (or lower) is certain death. Sometimes it's not possible to come down from the cliff, but you can always buy (for donate currency) several magic crystals. Each magic crystal can be used to change the state of any single platform (except platform on height $$$h$$$, which is unaffected by the crystals). After being used, the crystal disappears.What is the minimum number of magic crystal you need to buy to safely land on the $$$0$$$ ground level?
For each query print one integer β€” the minimum number of magic crystals you have to spend to safely come down on the ground level (with height $$$0$$$).
C
d0c50562764f2008045fe57e5da5de1c
64b3ccaf6fc09079860cdafacc6c705c
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "math" ]
1570545300
["4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1"]
null
PASSED
1,600
standard input
2 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) β€” the number of queries. Each query contains two lines and is independent of all other queries. The first line of each query contains two integers $$$h$$$ and $$$n$$$ ($$$1 \le h \le 10^9$$$, $$$1 \le n \le \min(h, 2 \cdot 10^5)$$$) β€” the height of the cliff and the number of moved out platforms. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$h = p_1 &gt; p_2 &gt; \dots &gt; p_n \ge 1$$$) β€” the corresponding moved out platforms in the descending order of their heights. The sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.
["0\n1\n2\n0"]
#include <stdio.h> struct _g_data { int size, bot; } typedef gd; int list[200005]; gd group[200005]; int main(void) { int q = 0; scanf("%d", &q); while (q--) { int h = 0, n = 0, gcnt = 0, result = 0; scanf("%d%d", &h, &n); for (int i = 0, x; i < n; i++) { scanf("%d", &list[i]); } list[n] = 0; for (int i = 0; i < n; i++) { group[gcnt].size = 1; group[gcnt].bot = list[i]; while (i < n - 1 && list[i] - 1 == list[i + 1]) { group[gcnt].size++; group[gcnt].bot = list[i + 1]; i++; } gcnt++; } if (group[0].size > 1 && group[0].size % 2 == 0 && group[0].bot + 1 > 2) result++; for (int i = 1; i < gcnt; i++) if (group[i].bot + 1 > 2 && group[i].size % 2) result++; printf("%d\n", result); } }
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height $$$h$$$, and there is a moving platform on each height $$$x$$$ from $$$1$$$ to $$$h$$$.Each platform is either hidden inside the cliff or moved out. At first, there are $$$n$$$ moved out platforms on heights $$$p_1, p_2, \dots, p_n$$$. The platform on height $$$h$$$ is moved out (and the character is initially standing there).If you character is standing on some moved out platform on height $$$x$$$, then he can pull a special lever, which switches the state of two platforms: on height $$$x$$$ and $$$x - 1$$$. In other words, the platform you are currently standing on will hide in the cliff and the platform one unit below will change it state: it will hide if it was moved out or move out if it was hidden. In the second case, you will safely land on it. Note that this is the only way to move from one platform to another.Your character is quite fragile, so it can safely fall from the height no more than $$$2$$$. In other words falling from the platform $$$x$$$ to platform $$$x - 2$$$ is okay, but falling from $$$x$$$ to $$$x - 3$$$ (or lower) is certain death. Sometimes it's not possible to come down from the cliff, but you can always buy (for donate currency) several magic crystals. Each magic crystal can be used to change the state of any single platform (except platform on height $$$h$$$, which is unaffected by the crystals). After being used, the crystal disappears.What is the minimum number of magic crystal you need to buy to safely land on the $$$0$$$ ground level?
For each query print one integer β€” the minimum number of magic crystals you have to spend to safely come down on the ground level (with height $$$0$$$).
C
d0c50562764f2008045fe57e5da5de1c
6a9064854e457a0e5e7e5f8795d21d89
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "math" ]
1570545300
["4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1"]
null
PASSED
1,600
standard input
2 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) β€” the number of queries. Each query contains two lines and is independent of all other queries. The first line of each query contains two integers $$$h$$$ and $$$n$$$ ($$$1 \le h \le 10^9$$$, $$$1 \le n \le \min(h, 2 \cdot 10^5)$$$) β€” the height of the cliff and the number of moved out platforms. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$h = p_1 &gt; p_2 &gt; \dots &gt; p_n \ge 1$$$) β€” the corresponding moved out platforms in the descending order of their heights. The sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.
["0\n1\n2\n0"]
#include<stdio.h> int main() { int t; scanf("%d",&t); while(t--) { int h,n; scanf("%d%d",&h,&n); int ar[200001]; int i; for(i=0;i<n;i++) scanf("%d",&ar[i]); int count=0; int curr = h; int index = 1; if(n==1) { printf("0\n"); continue; } while(curr>=3) { if(ar[index]!=curr-1) { curr = ar[index]+1; } else { index++; if(index==n) { count++; break; } if(ar[index]==curr-2) { index++; curr = curr-2; } else { //watch(curr); curr=curr-2; count++; } } //printf("%d t\n",count); } printf("%d\n",count); } return 0; }
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height $$$h$$$, and there is a moving platform on each height $$$x$$$ from $$$1$$$ to $$$h$$$.Each platform is either hidden inside the cliff or moved out. At first, there are $$$n$$$ moved out platforms on heights $$$p_1, p_2, \dots, p_n$$$. The platform on height $$$h$$$ is moved out (and the character is initially standing there).If you character is standing on some moved out platform on height $$$x$$$, then he can pull a special lever, which switches the state of two platforms: on height $$$x$$$ and $$$x - 1$$$. In other words, the platform you are currently standing on will hide in the cliff and the platform one unit below will change it state: it will hide if it was moved out or move out if it was hidden. In the second case, you will safely land on it. Note that this is the only way to move from one platform to another.Your character is quite fragile, so it can safely fall from the height no more than $$$2$$$. In other words falling from the platform $$$x$$$ to platform $$$x - 2$$$ is okay, but falling from $$$x$$$ to $$$x - 3$$$ (or lower) is certain death. Sometimes it's not possible to come down from the cliff, but you can always buy (for donate currency) several magic crystals. Each magic crystal can be used to change the state of any single platform (except platform on height $$$h$$$, which is unaffected by the crystals). After being used, the crystal disappears.What is the minimum number of magic crystal you need to buy to safely land on the $$$0$$$ ground level?
For each query print one integer β€” the minimum number of magic crystals you have to spend to safely come down on the ground level (with height $$$0$$$).
C
d0c50562764f2008045fe57e5da5de1c
28c3199c8a5e28a3d6f4bb149aa0a4c6
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "math" ]
1570545300
["4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1"]
null
PASSED
1,600
standard input
2 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) β€” the number of queries. Each query contains two lines and is independent of all other queries. The first line of each query contains two integers $$$h$$$ and $$$n$$$ ($$$1 \le h \le 10^9$$$, $$$1 \le n \le \min(h, 2 \cdot 10^5)$$$) β€” the height of the cliff and the number of moved out platforms. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$h = p_1 &gt; p_2 &gt; \dots &gt; p_n \ge 1$$$) β€” the corresponding moved out platforms in the descending order of their heights. The sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.
["0\n1\n2\n0"]
#include<stdio.h> int arr[200005], h, n; int main(){ int q; scanf("%d", &q); while(q--){ int i; scanf("%d %d", &h, &n); for(i = 0;i < n;i++)scanf("%d", arr + i); int ans = 0; i = 0; while(i < n - 2){ if(arr[i + 1] == arr[i + 2] + 1)i += 2; else{ i++;ans++; } } if(i < n - 1){ if(arr[i+1] != 1)ans++; } printf("%d\n", ans); } return 0; }
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
In the single line print n positive integers β€” the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
C
71dc07f0ea8962f23457af1d6509aeee
74da107a2fc552c47785974e8aba34b7
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "number theory" ]
1443890700
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
null
PASSED
1,700
standard input
2 seconds
The first line contains number n (1 ≀ n ≀ 500) β€” the length of array a. The second line contains n2 space-separated numbers β€” the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
["4 3 6 2", "42", "1 1"]
#include <stdio.h> #include <stdlib.h> #define MAX 555555 int a[MAX]; int used[MAX]; int alr[MAX]; int rem[MAX]; int gcd(int x, int y) { return x == 0 ? y : gcd(y % x, x); } int cmp(const void *a, const void * b) { return *((int*) a) - *((int*) b); } int main() { int n, i; scanf("%d", &n); for (i = 0; i < n * n; i++) { scanf("%d", &a[i]); } qsort(a, n * n, sizeof(int), cmp); int tot = n * n; for (i = 0; i < n; i++) { int maxv = -1; int maxid = -1; int j; for (j = 0; j < tot; j++) if (!used[j] && a[j] > maxv) { maxv = a[j]; maxid = j; } alr[i] = maxv; int remsz = 0; for (j = 0; j <= i; j++) { int g = gcd(alr[i], alr[j]); rem[remsz++] = g; if (j != i) rem[remsz++] = g; } qsort(rem, remsz, sizeof(int), cmp); int it = 0; for (j = 0; j < remsz; j++) { while (used[it] || a[it] < rem[j]) it++; used[it] = 1; } } for (i = 0; i < n; i++) { printf("%d ", alr[i]); } printf("\n"); return 0; }
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
In the single line print n positive integers β€” the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
C
71dc07f0ea8962f23457af1d6509aeee
09285a4234e5e759f5227dfe596c61e5
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "number theory" ]
1443890700
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
null
PASSED
1,700
standard input
2 seconds
The first line contains number n (1 ≀ n ≀ 500) β€” the length of array a. The second line contains n2 space-separated numbers β€” the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
["4 3 6 2", "42", "1 1"]
#include<stdio.h> #include<stdlib.h> typedef unsigned u; int F(const void*x,const void*y){return*(int*)x-*(int*)y;} typedef struct S { u val; struct S *lc,*rc; }v; v* alloc() { v *x; x=(v*)malloc(sizeof(v)); x->lc=x->rc=NULL; x->val=0;return x; } v *p,*q; u tes(u n) { for(q=p;n;n>>=1) { if(n&1){if(q->lc==NULL)return 0;q=q->lc;} else{if(q->rc==NULL)return 0;q=q->rc;} } if(q->val){q->val--;return 1;} return 0; } void add(u n) { for(q=p;n;n>>=1) { if(n&1){if(q->lc==NULL)q->lc=alloc();q=q->lc;} else{if(q->rc==NULL)q->rc=alloc();q=q->rc;} } ++q->val;return; } u G(u a,u b){return b?G(b,a%b):a;} u N[333333],A[555],Ai; int main() { u n,i=-1,j;p=alloc();scanf("%u",&n); for(n*=n;++i<n;)scanf("%u",N+i); qsort(N,n,sizeof(u),F); while(n--) { if(tes(N[n]))continue; A[Ai]=N[n]; for(i=-1;++i<Ai;) { j=G(A[i],N[n]); add(j);add(j); } ++Ai; } for(i=-1;++i<Ai;)printf("%u%c",A[i],i+1==Ai?'\n':' '); return 0; }
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
In the single line print n positive integers β€” the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
C
71dc07f0ea8962f23457af1d6509aeee
403669e60bc0b61cef2fff17221fe29b
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "number theory" ]
1443890700
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
null
PASSED
1,700
standard input
2 seconds
The first line contains number n (1 ≀ n ≀ 500) β€” the length of array a. The second line contains n2 space-separated numbers β€” the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
["4 3 6 2", "42", "1 1"]
#include <stdio.h> #include <stdlib.h> #define N 500 int compare(const void *a, const void *b) { int ia = *(int *) a; int ib = *(int *) b; return ib - ia; } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { static int gg[N * N], hh[N * 2], aa[N]; static char marked[N * N]; int n, k, h, i, j; scanf("%d", &n); for (i = 0; i < n * n; i++) scanf("%d", &gg[i]); qsort(gg, n * n, sizeof *gg, compare); k = 0; for (i = 0; i < n * n; i++) { if (marked[i]) continue; marked[i] = 1; aa[k++] = gg[i]; for (j = 0; j < k - 1; j++) hh[j + j] = hh[j + j + 1] = gcd(aa[k - 1], aa[j]); qsort(hh, (k - 1) * 2, sizeof *hh, compare); for (h = 0, j = 0; h < n * n && j < (k - 1) * 2; j++) { while (h < n * n && (marked[h] || gg[h] > hh[j])) h++; if (h < n * n && gg[h] == hh[j]) marked[h] = 1; } } for (i = 0; i < n; i++) printf("%d ", aa[i]); printf("\n"); return 0; }
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
In the single line print n positive integers β€” the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
C
71dc07f0ea8962f23457af1d6509aeee
2f8dd8292794146dcbd7e8a7077d3a4f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "number theory" ]
1443890700
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
null
PASSED
1,700
standard input
2 seconds
The first line contains number n (1 ≀ n ≀ 500) β€” the length of array a. The second line contains n2 space-separated numbers β€” the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
["4 3 6 2", "42", "1 1"]
#include <stdio.h> #include <stdlib.h> typedef struct { int num; int cnt; } Node_t; Node_t B[250000]; int Size; int Ans[500]; int AnsSize; int cmp(const void *a, const void *b) { return (*(Node_t *)b).num - (*(Node_t *)a).num; } int GCD(int a, int b) { int temp; while(b) { temp = a; a = b; b = temp % b; } return a; } int BinarySearch(Node_t *array, int len, int key) { int left = 0; int right = len - 1; while(left < right) { int mid = (left + right) >> 1; if(array[mid].num == key) { return mid; } else if(array[mid].num < key) { right = mid - 1; } else { left = mid + 1; } } return left; } int main() { int N, i, j; scanf("%d", &N); for(i = 0; i < N * N; ++i) { scanf("%d", &B[i].num); } qsort(B, N * N, sizeof(Node_t), cmp); ++Size; B[Size - 1].cnt = 1; for(i = 1; i < N * N; ++i) { if(B[i].num == B[Size - 1].num) { ++B[Size - 1].cnt; } else { ++Size; B[Size - 1].num = B[i].num; B[Size - 1].cnt = 1; } } for(i = 0; i < Size; ++i) { while(B[i].cnt) { --B[i].cnt; for(j = 0; j < AnsSize; ++j) { int num = GCD(Ans[j], B[i].num); int idx = BinarySearch(B, Size, num); B[idx].cnt -= 2; } Ans[AnsSize++] = B[i].num; } } for(i = AnsSize - 1; i >= 0; --i) { printf("%d ", Ans[i]); } puts(""); return 0; }
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
In the single line print n positive integers β€” the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
C
71dc07f0ea8962f23457af1d6509aeee
eaa383daa26ed1782a135a09da1e0df9
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "number theory" ]
1443890700
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
null
PASSED
1,700
standard input
2 seconds
The first line contains number n (1 ≀ n ≀ 500) β€” the length of array a. The second line contains n2 space-separated numbers β€” the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
["4 3 6 2", "42", "1 1"]
#include<stdio.h> long a[251111],v[251111],cc[251111],rem[251111]; void swap(long *aaa,long *bbb) { long t; t=*aaa; *aaa=*bbb; *bbb=t; } void qsort(long low,long high) { long i=low,j=high,mid=a[(low+high)/2]; while(i<j) { while(a[i]<mid)i++; while(a[j]>mid)j--; if(i<=j) { swap(&a[i],&a[j]); i++; j--; } } if(j>low)qsort(low,j); if(i<high)qsort(i,high); } void qsort1(long low,long high) { long i=low,j=high,mid=rem[(low+high)/2]; while(i<j) { while(rem[i]<mid)i++; while(rem[j]>mid)j--; if(i<=j) { swap(&rem[i],&rem[j]); i++; j--; } } if(j>low)qsort1(low,j); if(i<high)qsort1(i,high); } long gcd(long aaa,long bbb) { if(bbb==0)return aaa; else return gcd(bbb,aaa%bbb); } int main() { long n,i,cnt,lc,wz,g,tot,j,lr,now,max; scanf("%ld",&n); for(i=1;i<=n*n;i++)scanf("%ld",&a[i]); qsort(1,n*n); cnt=n*n; lc=0; while(cnt>0) { max=-0x7fffffff; wz=0; for(i=1;i<=n*n;i++) { if(v[i]==0&&a[i]>max) { max=a[i]; wz=i; } } cc[++lc]=a[wz]; printf("%ld ",a[wz]); lr=0; for(i=1;i<=lc;i++) { g=gcd(cc[i],cc[lc]); rem[++lr]=g; if(i!=lc)rem[++lr]=g; } qsort1(1,lr); tot=0; now=1; for(j=1;j<=lr;j++) { while(a[now]<rem[j]||v[now]==1)now++; v[now]=1; cnt--; } } return 0; }
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both x and y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table G, restore array a.
In the single line print n positive integers β€” the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
C
71dc07f0ea8962f23457af1d6509aeee
a24b7c68df09d1230ccdfe2d9cea99ba
GNU C
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "number theory" ]
1443890700
["4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "1\n42", "2\n1 1 1 1"]
null
PASSED
1,700
standard input
2 seconds
The first line contains number n (1 ≀ n ≀ 500) β€” the length of array a. The second line contains n2 space-separated numbers β€” the elements of the GCD table of G for array a. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
["4 3 6 2", "42", "1 1"]
#include<stdio.h> #include<stdlib.h> int cmpfunc (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int gcd(int,int); int binsear(int); int map[250005],mlen; int main(){ int n,*ar,i,c,j,ans[502],alen,cnt[250005],ele; scanf("%d",&n); ar=(int *)malloc(sizeof(int)*n*n); for(i=0;i<n*n;i++) scanf("%d",ar+i); qsort(ar,n*n,sizeof(int),cmpfunc); map[0]=ar[0]; mlen=1; cnt[0]=1; for(i=1,j=0;i<n*n;i++){ if(ar[i]!=ar[i-1]){ j++; map[mlen++]=ar[i]; cnt[j]=0; } cnt[j]++; } ele=n*n; i=mlen-1; alen=0; while(ele>0){ if(cnt[i]==0){ i--; continue; } ans[alen++]=i; cnt[i]-=1; ele-=1; for(j=0;j<alen-1;j++){ cnt[binsear(gcd(map[ans[j]],map[ans[alen-1]]))]-=2; ele-=2; } } for(i=0;i<alen;i++) printf("%d ",map[ans[i]]); printf("\n"); return 0; } int binsear(int val){ int s,e,m; s=0;e=mlen-1; while(s<e){ m=(s+e)>>1; if(val<=map[m]){ e=m; } else{ s=m+1; } } return s; } int gcd(int a,int b){ int c; while(a>0){ c=a; a=b%a; b=c; } return b; }
In Aramic language words can only represent objects.Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in $$$y$$$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". Any word in Aramic represents the same object as its root. You have an ancient script in Aramic. What is the number of different objects mentioned in the script?
Output one integerΒ β€” the number of different objects mentioned in the given ancient Aramic script.
C
cf1eb164c4c970fd398ef9e98b4c07b1
ffae398b3c2d4e9a319c4e4ca5a7d6c7
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1525183500
["5\na aa aaa ab abb", "3\namer arem mrea"]
NoteIn the first test, there are two objects mentioned. The roots that represent them are "a","ab".In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
PASSED
900
standard input
1 second
The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$)Β β€” the number of words in the script. The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$Β β€” the script itself. The length of each string does not exceed $$$10^3$$$. It is guaranteed that all characters of the strings are small latin letters.
["2", "1"]
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int n,i; scanf("%d",&n); char word[1000]; int *roots; int rootLen = 0; roots = (int *)malloc(rootLen*sizeof(int)*26); for(i=0;i<n;i++) { int root[26] = {0},j,c=1; scanf("%s",&word); for(j=0;j<strlen(word);j++) { if(root[word[j]-97] == 0) root[word[j]-97] =1; } for(j=0;j<rootLen;j++) { int q,counter = 0; for(q=0;q<26;q++) { if(root[q] == roots[j*26+q]) counter++; } if(counter ==26) c=0; } if(c) { roots = (int *)realloc(roots,(rootLen+1)*sizeof(int)*26 ); for(j=0;j<26;j++) roots[rootLen*26+j] = root[j]; rootLen++; } } printf("%d",rootLen); free(roots); }
In Aramic language words can only represent objects.Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in $$$y$$$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". Any word in Aramic represents the same object as its root. You have an ancient script in Aramic. What is the number of different objects mentioned in the script?
Output one integerΒ β€” the number of different objects mentioned in the given ancient Aramic script.
C
cf1eb164c4c970fd398ef9e98b4c07b1
bd745773cd97747aab6b8caa03e89a37
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1525183500
["5\na aa aaa ab abb", "3\namer arem mrea"]
NoteIn the first test, there are two objects mentioned. The roots that represent them are "a","ab".In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
PASSED
900
standard input
1 second
The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$)Β β€” the number of words in the script. The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$Β β€” the script itself. The length of each string does not exceed $$$10^3$$$. It is guaranteed that all characters of the strings are small latin letters.
["2", "1"]
#include <stdio.h> #include <string.h> char process_str(char string[]){ char temp; int i, j, count = 0, len = strlen(string); for(i = 0; i < len-1; i++){ for(j = i + 1; j < len; j++){ if(string[i] == string[j]){ string[j] = '\0'; } } } for(i = 0; i < len; i++){ if(string[i] != '\0'){ temp = string[i]; string[i] = string[count]; string[count] = temp; count++; } } return (char)string; } char short_str(char string[]){ char temp; int i, j, len = strlen(string); for(i = 0; i < len; i++){ for(j = i+1; j < len; j++){ if(string[i] < string[j]){ temp = string[i]; string[i] = string[j]; string[j] = temp; } } } return (char)string; } int main() { int n; scanf("%d", &n); char string[n][1001]; int count_arr[n]; int i, j, count = 0; for(i = 0; i < n; i++){ count_arr[i] = 0; } for(i = 0; i < n; i++){ scanf("%s", &string[i]); } for(i = 0; i < n; i++){ process_str(string[i]); short_str(string[i]); } for(i = 0; i < n-1; i++){ if(count_arr[i] == 0){ for(j = i+1; j < n; j++){ if(strcmp(string[i], string[j]) == 0){ count_arr[j] = 1; } } } } for(i = 0; i < n; i++){ if(count_arr[i] == 0) count++; } printf("%d\n", count); return 0; }
In Aramic language words can only represent objects.Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in $$$y$$$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". Any word in Aramic represents the same object as its root. You have an ancient script in Aramic. What is the number of different objects mentioned in the script?
Output one integerΒ β€” the number of different objects mentioned in the given ancient Aramic script.
C
cf1eb164c4c970fd398ef9e98b4c07b1
df265face5b54bb1e7d136f60ed9a0a2
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1525183500
["5\na aa aaa ab abb", "3\namer arem mrea"]
NoteIn the first test, there are two objects mentioned. The roots that represent them are "a","ab".In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
PASSED
900
standard input
1 second
The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$)Β β€” the number of words in the script. The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$Β β€” the script itself. The length of each string does not exceed $$$10^3$$$. It is guaranteed that all characters of the strings are small latin letters.
["2", "1"]
#include<stdio.h> int used[27][1001]; int cnt,par; char c[1001]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%s",&c); for(int t=0;c[t]!='\0';t++) used[c[t]-'a'+1][i]=1; par=0; for(int j=0;j<i;j++) { int tt=1; for(int k=1;k<=26;k++) { if(used[k][j]!=used[k][i]) { tt=0; break; } } if(tt==1) { par=1; break; } } if(par==0) cnt++; } printf("%d",cnt); }
In Aramic language words can only represent objects.Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in $$$y$$$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". Any word in Aramic represents the same object as its root. You have an ancient script in Aramic. What is the number of different objects mentioned in the script?
Output one integerΒ β€” the number of different objects mentioned in the given ancient Aramic script.
C
cf1eb164c4c970fd398ef9e98b4c07b1
8c91dc5f3520baea890628f31bcbce5a
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1525183500
["5\na aa aaa ab abb", "3\namer arem mrea"]
NoteIn the first test, there are two objects mentioned. The roots that represent them are "a","ab".In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
PASSED
900
standard input
1 second
The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$)Β β€” the number of words in the script. The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$Β β€” the script itself. The length of each string does not exceed $$$10^3$$$. It is guaranteed that all characters of the strings are small latin letters.
["2", "1"]
#include <stdio.h> #include <string.h> #include <stdlib.h> #define NO_OF_CHARS 256 #define bool int void sort_string(char *s); char *removeDups(char *str); void sort_string(char *s) { int c, d = 0, length; char *pointer, *result, ch; length = strlen(s); result = (char*)malloc(length+1); pointer = s; for ( ch = 'a' ; ch <= 'z' ; ch++ ) { for ( c = 0 ; c < length ; c++ ) { if ( *pointer == ch ) { *(result+d) = *pointer; d++; } pointer++; } pointer = s; } *(result+d) = '\0'; strcpy(s, result); free(result); } char *removeDups(char *str) { bool bin_hash[NO_OF_CHARS] = {0}; int ip_ind = 0, res_ind = 0; char temp; while (*(str + ip_ind)) { temp = *(str + ip_ind); if (bin_hash[temp] == 0) { bin_hash[temp] = 1; *(str + res_ind) = *(str + ip_ind); res_ind++; } ip_ind++; } *(str+res_ind) = '\0'; return str; } int main() { int n; scanf("%d", &n); char str[n][1000]; for(int i=0; i<n; i++) { scanf("%s ", str[i]); sort_string(removeDups(str[i])); //printf("%s\n", str[i]); } int counter = 0; for(int j=0; j<n-1; j++) { if(str[j][0]!='_') { for(int k=j+1; k<n; k++) { if(!strcmp(str[j], str[k])) { str[k][0] = '_'; } } } } for(int j=0; j<n; j++) { if(str[j][0]!='_') { //printf("%s\n", str[j]); counter++; } } printf("%d", counter); return 0; }
In Aramic language words can only represent objects.Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in $$$y$$$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". Any word in Aramic represents the same object as its root. You have an ancient script in Aramic. What is the number of different objects mentioned in the script?
Output one integerΒ β€” the number of different objects mentioned in the given ancient Aramic script.
C
cf1eb164c4c970fd398ef9e98b4c07b1
bfbc90403222250d7b92c5e28056b1a0
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1525183500
["5\na aa aaa ab abb", "3\namer arem mrea"]
NoteIn the first test, there are two objects mentioned. The roots that represent them are "a","ab".In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
PASSED
900
standard input
1 second
The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$)Β β€” the number of words in the script. The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$Β β€” the script itself. The length of each string does not exceed $$$10^3$$$. It is guaranteed that all characters of the strings are small latin letters.
["2", "1"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { //code int n; scanf("%d",&n); char **A=(char**)malloc(n*sizeof(char*)); char **R=(char**)malloc(n*sizeof(char*)); for(int i=0;i<n;i++) A[i]=(char*)malloc(1000*sizeof(char)); for(int i=0;i<n;i++) R[i]=(char*)malloc(27*sizeof(char)); for(int i=0;i<n;i++) scanf("%s",A[i]); int a[26]; for(int i=0;i<n;i++) { for(int p=0;p<26;p++) a[p]=0; int j=0; while(A[i][j]!='\0') { a[A[i][j]-'a']++; j++; } int k=0; j=0; while(j<26) { if(a[j]) { R[i][k]='a'+j; k++; } j++; } R[i][k]='\0'; } int c=0; for(int i=0;i<n;i++) { int d=0; for(int j=i+1;j<n;j++) if(strcmp(R[i],R[j])==0){ d++;break;} if(d==0) c++; } printf("%d",c); return 0; }
In Aramic language words can only represent objects.Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root $$$x$$$ of a word $$$y$$$ is the word that contains all letters that appear in $$$y$$$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". Any word in Aramic represents the same object as its root. You have an ancient script in Aramic. What is the number of different objects mentioned in the script?
Output one integerΒ β€” the number of different objects mentioned in the given ancient Aramic script.
C
cf1eb164c4c970fd398ef9e98b4c07b1
1f93bf245b5acebad9e1c4e1788c9c1e
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1525183500
["5\na aa aaa ab abb", "3\namer arem mrea"]
NoteIn the first test, there are two objects mentioned. The roots that represent them are "a","ab".In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer".
PASSED
900
standard input
1 second
The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^3$$$)Β β€” the number of words in the script. The second line contains $$$n$$$ words $$$s_1, s_2, \ldots, s_n$$$Β β€” the script itself. The length of each string does not exceed $$$10^3$$$. It is guaranteed that all characters of the strings are small latin letters.
["2", "1"]
#include<stdio.h> #include<string.h> int mark[1005][30]; char a[1005]; int main() { int n,sum=0; scanf("%d",&n); for(int i=1;i<=n;i++) { int flag=1; scanf("%s",a); int l=strlen(a); for(int j=0;j<l;j++) mark[i][a[j]-'a']=1; for(int j=1;j<i;j++) { int ok=1; for(int g=0;g<30;g++) if(mark[j][g]!=mark[i][g]) ok=0; if(ok)flag=0; } sum+=flag; } printf("%d\n",sum); }
You are given two integers $$$a$$$ and $$$b$$$. Moreover, you are given a sequence $$$s_0, s_1, \dots, s_{n}$$$. All values in $$$s$$$ are integers $$$1$$$ or $$$-1$$$. It's known that sequence is $$$k$$$-periodic and $$$k$$$ divides $$$n+1$$$. In other words, for each $$$k \leq i \leq n$$$ it's satisfied that $$$s_{i} = s_{i - k}$$$.Find out the non-negative remainder of division of $$$\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}$$$ by $$$10^{9} + 9$$$.Note that the modulo is unusual!
Output a single integerΒ β€” value of given expression modulo $$$10^{9} + 9$$$.
C
607e670403a40e4fddf389caba79607e
7be42db86a154f0f7e706b0639b9a065
GNU C
standard output
256 megabytes
train_000.jsonl
[ "number theory", "math", "matrices" ]
1523973900
["2 2 3 3\n+-+", "4 1 5 1\n-"]
NoteIn the first example:$$$(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i})$$$ = $$$2^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2}$$$ = 7In the second example:$$$(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9}$$$.
PASSED
1,800
standard input
1 second
The first line contains four integers $$$n, a, b$$$ and $$$k$$$ $$$(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})$$$. The second line contains a sequence of length $$$k$$$ consisting of characters '+' and '-'. If the $$$i$$$-th character (0-indexed) is '+', then $$$s_{i} = 1$$$, otherwise $$$s_{i} = -1$$$. Note that only the first $$$k$$$ members of the sequence are given, the rest can be obtained using the periodicity property.
["7", "999999228"]
#include<stdio.h> #include<string.h> #include<stdlib.h> #define mod 1000000009 typedef long long int ll; char arr[100001]; ll power(ll number,ll power) { ll answer=1; while(power) { if(power%2) answer=(answer*number)%mod; number=(number*number)%mod; power=power/2; } return answer; } int main() { //freopen("program.txt","r",stdin); int n,a,b,k; int i,j,l; scanf("%d %d %d %d",&n,&a,&b,&k); scanf("%s",arr); //first get the value of pow ll pow=power(power(a,mod-2)*b%mod,k); if(pow==1) pow=(n+1)/k; else { pow=(power(pow,n/k+1)-1)*power(pow-1,mod-2)%mod; } ll ans=0; for(i=0;i<k;i++) { int sign=(arr[i]=='+'?1:-1); ans=(ans+(power(a,n-i)*power(b,i))%mod*pow%mod*sign)%mod; //ans+=power(a,n-i)*power(b,i)%mod*pow%mod*sign; } printf("%I64d\n",(ans+mod)%mod); return 0; }
You are given an undirected graph consisting of $$$n$$$ vertices. A number is written on each vertex; the number on vertex $$$i$$$ is $$$a_i$$$. Initially there are no edges in the graph.You may add some edges to this graph, but you have to pay for them. The cost of adding an edge between vertices $$$x$$$ and $$$y$$$ is $$$a_x + a_y$$$ coins. There are also $$$m$$$ special offers, each of them is denoted by three numbers $$$x$$$, $$$y$$$ and $$$w$$$, and means that you can add an edge connecting vertices $$$x$$$ and $$$y$$$ and pay $$$w$$$ coins for it. You don't have to use special offers: if there is a pair of vertices $$$x$$$ and $$$y$$$ that has a special offer associated with it, you still may connect these two vertices paying $$$a_x + a_y$$$ coins for it.What is the minimum number of coins you have to spend to make the graph connected? Recall that a graph is connected if it's possible to get from any vertex to any other vertex using only the edges belonging to this graph.
Print one integer β€” the minimum number of coins you have to pay to make the graph connected.
C
e52ec2fa5bcf5d2027d57b0694b4e15a
c55850491ec853c07e8697f1bc18e193
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dsu", "greedy", "graphs" ]
1545921300
["3 2\n1 3 3\n2 3 5\n2 1 1", "4 0\n1 3 3 7", "5 4\n1 2 3 4 5\n1 2 8\n1 3 10\n1 4 7\n1 5 15"]
NoteIn the first example it is possible to connect $$$1$$$ to $$$2$$$ using special offer $$$2$$$, and then $$$1$$$ to $$$3$$$ without using any offers.In next two examples the optimal answer may be achieved without using special offers.
PASSED
1,900
standard input
2 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) β€” the number of vertices in the graph and the number of special offers, respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$) β€” the numbers written on the vertices. Then $$$m$$$ lines follow, each containing three integers $$$x$$$, $$$y$$$ and $$$w$$$ ($$$1 \le x, y \le n$$$, $$$1 \le w \le 10^{12}$$$, $$$x \ne y$$$) denoting a special offer: you may add an edge connecting vertex $$$x$$$ and vertex $$$y$$$, and this edge will cost $$$w$$$ coins.
["5", "16", "18"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> #define N 200000 #define M 200000 void init_rand() { struct timeval tv; gettimeofday(&tv, NULL); srand(tv.tv_sec ^ tv.tv_usec); } int rand_(int n) { return (rand() * 45677LL + rand()) % n; } struct E { int i, j; long long w; } ee[N + M]; int compare(const void *a, const void *b) { struct E *e = (struct E *) a; struct E *f = (struct E *) b; return e->w == f->w ? 0 : e->w < f->w ? -1 : 1; } int dsu[N]; int find(int i) { return dsu[i] < 0 ? i : (dsu[i] = find(dsu[i])); } int join(int i, int j) { i = find(i); j = find(j); if (i == j) return 0; if (dsu[i] > dsu[j]) dsu[i] = j; else { if (dsu[i] == dsu[j]) dsu[i]--; dsu[j] = i; } return 1; } int main() { static long long aa[N]; int n, m, h, i, i_, j, k; long long w, ans; struct E *e, tmp; scanf("%d%d", &n, &m); i_ = -1; for (i = 0; i < n; i++) { scanf("%lld", &aa[i]); if (i_ == -1 || aa[i_] > aa[i]) i_ = i; } k = 0; for (i = 0; i < n; i++) if (i_ != i) { e = &ee[k++]; e->i = i_, e->j = i, e->w = aa[i_] + aa[i]; } while (m--) { e = &ee[k++]; scanf("%d%d%lld", &i, &j, &w), i--, j--; e->i = i, e->j = j, e->w = w; } init_rand(); for (j = k - 1; j >= 0; j--) { i = rand_(j + 1); tmp = ee[i], ee[i] = ee[j], ee[j] = tmp; } qsort(ee, k, sizeof *ee, compare); memset(dsu, -1, sizeof dsu); ans = 0; for (h = 0; h < k; h++) { e = &ee[h]; if (join(e->i, e->j)) ans += e->w; } printf("%lld\n", ans); return 0; }
You are given an undirected graph consisting of $$$n$$$ vertices. A number is written on each vertex; the number on vertex $$$i$$$ is $$$a_i$$$. Initially there are no edges in the graph.You may add some edges to this graph, but you have to pay for them. The cost of adding an edge between vertices $$$x$$$ and $$$y$$$ is $$$a_x + a_y$$$ coins. There are also $$$m$$$ special offers, each of them is denoted by three numbers $$$x$$$, $$$y$$$ and $$$w$$$, and means that you can add an edge connecting vertices $$$x$$$ and $$$y$$$ and pay $$$w$$$ coins for it. You don't have to use special offers: if there is a pair of vertices $$$x$$$ and $$$y$$$ that has a special offer associated with it, you still may connect these two vertices paying $$$a_x + a_y$$$ coins for it.What is the minimum number of coins you have to spend to make the graph connected? Recall that a graph is connected if it's possible to get from any vertex to any other vertex using only the edges belonging to this graph.
Print one integer β€” the minimum number of coins you have to pay to make the graph connected.
C
e52ec2fa5bcf5d2027d57b0694b4e15a
7b7b60eecf4d520e713eba3f43a34667
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dsu", "greedy", "graphs" ]
1545921300
["3 2\n1 3 3\n2 3 5\n2 1 1", "4 0\n1 3 3 7", "5 4\n1 2 3 4 5\n1 2 8\n1 3 10\n1 4 7\n1 5 15"]
NoteIn the first example it is possible to connect $$$1$$$ to $$$2$$$ using special offer $$$2$$$, and then $$$1$$$ to $$$3$$$ without using any offers.In next two examples the optimal answer may be achieved without using special offers.
PASSED
1,900
standard input
2 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) β€” the number of vertices in the graph and the number of special offers, respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$) β€” the numbers written on the vertices. Then $$$m$$$ lines follow, each containing three integers $$$x$$$, $$$y$$$ and $$$w$$$ ($$$1 \le x, y \le n$$$, $$$1 \le w \le 10^{12}$$$, $$$x \ne y$$$) denoting a special offer: you may add an edge connecting vertex $$$x$$$ and vertex $$$y$$$, and this edge will cost $$$w$$$ coins.
["5", "16", "18"]
#include<stdio.h> #include<stdlib.h> #include<stdint.h> #include<inttypes.h> void msort_memcpy (uint8_t * restrict dst, uint8_t * restrict src, size_t size) { while (size--) { *dst++ = *src++; } } void msort (void * const array, const size_t num, const size_t size, int (* const cmp) (const void *, const void *)) { typedef struct operation { size_t l; size_t r; int32_t type; } op; uint8_t * const a = (uint8_t *) array; uint8_t * const tmp = (uint8_t *) malloc (size * num); op stack[64]; int32_t top = 0; stack[top++] = (op) {0, num, 0}; while (top > 0) { const op t = stack[--top]; if (t.l + 1 >= t.r) continue; const size_t m = (t.l + t.r) / 2; if (t.type == 0) { stack[top++] = (op) {t.l, t.r, 1}; stack[top++] = (op) {t.l, m , 0}; stack[top++] = (op) {m , t.r, 0}; continue; } msort_memcpy (tmp, a + t.l * size, (m - t.l) * size); size_t i = 0; size_t j = m * size; size_t k = t.l * size; while (i < (m - t.l) * size && j < t.r * size) { if (cmp (tmp + i, a + j) <= 0) { msort_memcpy (a + k, tmp + i, size); i += size; } else { msort_memcpy (a + k, a + j, size); j += size; } k += size; } msort_memcpy (a + k, tmp + i, (m - t.l) * size - i); } free (tmp); } typedef struct union_find { int32_t *parent; int32_t size; } union_find; void init_union_find (union_find * const u) { for (int32_t i = 0; i < u->size; ++i){ u->parent[i] = -1; } } union_find* new_union_find (const int32_t size) { union_find * const u = (union_find *) calloc (1, sizeof (union_find)); u->parent = (int32_t *) calloc (size, sizeof (int32_t)); u->size = size; init_union_find (u); return u; } int32_t root (union_find * const u, int32_t x) { if (u->parent[x] < 0) return x; return u->parent[x] = root (u, u->parent[x]); } int same (union_find * const u, const int32_t x, const int32_t y) { return root (u, x) == root (u, y); } void unite (union_find * const u, int32_t x, int32_t y) { x = root (u, x); y = root (u, y); if (x == y) return; if (u->parent[x] > u->parent[y]) { const int32_t swap = x; x = y; y = swap; } u->parent[x] += u->parent[y]; u->parent[y] = x; } typedef int64_t i64; typedef int32_t i32; static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}} static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;} #define ALLOC(size,type) ((type*)calloc((size),sizeof(type))) #define SORT(a,n,cmp) msort((a),(n),sizeof(*(a)),cmp) typedef struct edge { i32 a, b; i64 c; } edge; int cmp_edge (const void *a, const void *b) { i64 d = ((edge *)a)->c - ((edge *)b)->c; return d == 0 ? 0 : d < 0 ? -1 : 1; } void run (void) { i32 n = read_int(); i32 m = read_int(); i64 *a = ALLOC (n, i64); i32 min = 0; for (i32 i = 0; i < n; ++i) { a[i] = read_int(); if (a[min] > a[i]) { min = i; } } edge *e = ALLOC (n + m, edge); i32 len = 0; for (i32 i = 0; i < n; ++i) { if (i == min) continue; e[len++] = (edge) {i, min, a[i] + a[min]}; } for (i32 i = 0; i < m; ++i) { i32 x = read_int() - 1; i32 y = read_int() - 1; i64 w = read_int(); e[len++] = (edge) {x, y, w}; } SORT (e, len, cmp_edge); union_find *u = new_union_find (n); i64 sum = 0; for (i32 i = 0; i < len; ++i) { i32 a = e[i].a; i32 b = e[i].b; i64 c = e[i].c; if (same (u, a, b)) continue; unite (u, a ,b); sum += c; } print_int (sum); puts (""); } int main (void) { run (); return 0; }
You are given an undirected graph consisting of $$$n$$$ vertices. A number is written on each vertex; the number on vertex $$$i$$$ is $$$a_i$$$. Initially there are no edges in the graph.You may add some edges to this graph, but you have to pay for them. The cost of adding an edge between vertices $$$x$$$ and $$$y$$$ is $$$a_x + a_y$$$ coins. There are also $$$m$$$ special offers, each of them is denoted by three numbers $$$x$$$, $$$y$$$ and $$$w$$$, and means that you can add an edge connecting vertices $$$x$$$ and $$$y$$$ and pay $$$w$$$ coins for it. You don't have to use special offers: if there is a pair of vertices $$$x$$$ and $$$y$$$ that has a special offer associated with it, you still may connect these two vertices paying $$$a_x + a_y$$$ coins for it.What is the minimum number of coins you have to spend to make the graph connected? Recall that a graph is connected if it's possible to get from any vertex to any other vertex using only the edges belonging to this graph.
Print one integer β€” the minimum number of coins you have to pay to make the graph connected.
C
e52ec2fa5bcf5d2027d57b0694b4e15a
cfbcb4ef2b8c53b1b9808c6a5749d6eb
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dsu", "greedy", "graphs" ]
1545921300
["3 2\n1 3 3\n2 3 5\n2 1 1", "4 0\n1 3 3 7", "5 4\n1 2 3 4 5\n1 2 8\n1 3 10\n1 4 7\n1 5 15"]
NoteIn the first example it is possible to connect $$$1$$$ to $$$2$$$ using special offer $$$2$$$, and then $$$1$$$ to $$$3$$$ without using any offers.In next two examples the optimal answer may be achieved without using special offers.
PASSED
1,900
standard input
2 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) β€” the number of vertices in the graph and the number of special offers, respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$) β€” the numbers written on the vertices. Then $$$m$$$ lines follow, each containing three integers $$$x$$$, $$$y$$$ and $$$w$$$ ($$$1 \le x, y \le n$$$, $$$1 \le w \le 10^{12}$$$, $$$x \ne y$$$) denoting a special offer: you may add an edge connecting vertex $$$x$$$ and vertex $$$y$$$, and this edge will cost $$$w$$$ coins.
["5", "16", "18"]
#include<stdio.h> #include<stdlib.h> #define N 200043 typedef struct road{ int x; int y; long long distance; }road; int p[N]; int getRoot(int x){ return ((x==p[x])?x:(p[x]=getRoot(p[x]))); } int compare(const void *a,const void *b){ if(((road*)a)->distance-((road*)b)->distance>0)return 1; else if(((road*)a)->distance-((road*)b)->distance==0)return 0; else return -1; } int main(){ int n,m,i,j,x1,y1,x2,y2,x,y; int min; long long a[N]; long long ans; road d[N*2]; //printf("%lld",10308315); scanf("%d %d",&n,&m); for(i=0;i<n;i++)scanf("%lld",&a[i]); for(i=0;i<m;i++){ scanf("%d %d",&d[i].x,&d[i].y); scanf("%lld",&d[i].distance); d[i].x--; d[i].y--; //printf("%d\n",ans); } min=0; p[0]=0; for(i=1;i<n;i++){ p[i]=i; if(a[i]<a[min])min=i; } //printf("%d",min); for(i=m;i<min+m;i++){ d[i].x=i-m; d[i].y=min; d[i].distance=a[i-m]+a[min]; } for(i=min+m;i<m+n-1;i++){ d[i].x=min; d[i].y=i-m+1; d[i].distance=a[min]+a[i-m+1]; } qsort(d,m+n-1,sizeof(road),compare); ans=0; for(i=0;i<m+n-1;i++){ x=getRoot(d[i].x); y=getRoot(d[i].y); if(x!=y){ ans+=d[i].distance; p[x]=y; } } printf("%lld",ans); }
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.There are non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
C
f292c099e4eac9259a5bc9e42ff6d1b5
78dc992fb3b646cee344269b8ee1f97d
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "data structures", "implementation", "brute force" ]
1462633500
["4\n1 2 1 2", "3\n1 1 1"]
NoteIn the first sample, color 2 is dominant in three intervals: An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color. An interval [4, 4] contains one ball, with color 2 again. An interval [2, 4] contains two balls of color 2 and one ball of color 1. There are 7 more intervals and color 1 is dominant in all of them.
PASSED
1,500
standard input
2 seconds
The first line of the input contains a single integer n (1 ≀ n ≀ 5000)Β β€” the number of balls. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ n) where ti is the color of the i-th ball.
["7 3 0 0", "6 0 0"]
/* practice with Dukkha */ #include <stdio.h> #include <string.h> #define N 5000 int main() { static int aa[N], kk[N], ans[N]; int n, i, j, a, a_; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &aa[i]), aa[i]--; for (i = 0; i < n; i++) { memset(kk, 0, n * sizeof *kk); a_ = -1; for (j = i; j < n; j++) { a = aa[j]; kk[a]++; if (a_ == -1 || kk[a_] < kk[a] || kk[a_] == kk[a] && a_ > a) a_ = a; ans[a_]++; } } for (a = 0; a < n; a++) printf("%d ", ans[a]); printf("\n"); return 0; }
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.There are non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
C
f292c099e4eac9259a5bc9e42ff6d1b5
821391d00c11053ca894ca76faac60f6
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "data structures", "implementation", "brute force" ]
1462633500
["4\n1 2 1 2", "3\n1 1 1"]
NoteIn the first sample, color 2 is dominant in three intervals: An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color. An interval [4, 4] contains one ball, with color 2 again. An interval [2, 4] contains two balls of color 2 and one ball of color 1. There are 7 more intervals and color 1 is dominant in all of them.
PASSED
1,500
standard input
2 seconds
The first line of the input contains a single integer n (1 ≀ n ≀ 5000)Β β€” the number of balls. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ n) where ti is the color of the i-th ball.
["7 3 0 0", "6 0 0"]
#include <stdio.h> #include <string.h> #define N 5000 int main() { static int tt[N], ans[N + 1]; int n, i, t; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &tt[i]); for (i = 0; i < n; i++) { static int kk[N + 1]; int j; memset(kk, 0, (n + 1) * sizeof *kk); t = -1; for (j = i; j < n; j++) { kk[tt[j]]++; if (t == -1 || kk[tt[j]] > kk[t] || kk[tt[j]] == kk[t] && tt[j] < t) t = tt[j]; ans[t]++; } } for (t = 1; t <= n; t++) printf("%d ", ans[t]); printf("\n"); return 0; }
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.There are non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
C
f292c099e4eac9259a5bc9e42ff6d1b5
f2317a2e837c80af8a1f4e65f0c5d717
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "data structures", "implementation", "brute force" ]
1462633500
["4\n1 2 1 2", "3\n1 1 1"]
NoteIn the first sample, color 2 is dominant in three intervals: An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color. An interval [4, 4] contains one ball, with color 2 again. An interval [2, 4] contains two balls of color 2 and one ball of color 1. There are 7 more intervals and color 1 is dominant in all of them.
PASSED
1,500
standard input
2 seconds
The first line of the input contains a single integer n (1 ≀ n ≀ 5000)Β β€” the number of balls. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ n) where ti is the color of the i-th ball.
["7 3 0 0", "6 0 0"]
#include <stdio.h> #include <string.h> #define N 5000 int main() { static int tt[N], ans[N + 1]; int n, i, t; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &tt[i]); for (i = 0; i < n; i++) { static int kk[N + 1]; int j; memset(kk, 0, (n + 1) * sizeof *kk); t = -1; for (j = i; j < n; j++) { kk[tt[j]]++; if (t == -1 || kk[tt[j]] == kk[t] && tt[j] < t || kk[tt[j]] > kk[t]) t = tt[j]; ans[t]++; } } for (t = 1; t <= n; t++) printf("%d ", ans[t]); printf("\n"); return 0; }
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.There are non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
C
f292c099e4eac9259a5bc9e42ff6d1b5
bb722cea8f9fd7e87708819d25f95d78
GNU C
standard output
256 megabytes
train_000.jsonl
[ "data structures", "implementation", "brute force" ]
1462633500
["4\n1 2 1 2", "3\n1 1 1"]
NoteIn the first sample, color 2 is dominant in three intervals: An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color. An interval [4, 4] contains one ball, with color 2 again. An interval [2, 4] contains two balls of color 2 and one ball of color 1. There are 7 more intervals and color 1 is dominant in all of them.
PASSED
1,500
standard input
2 seconds
The first line of the input contains a single integer n (1 ≀ n ≀ 5000)Β β€” the number of balls. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ n) where ti is the color of the i-th ball.
["7 3 0 0", "6 0 0"]
#include<stdio.h> typedef unsigned u; u N[5555],S[5555],A[5555],x; int main() { u n,i=-1,j,k,d; for(scanf("%u",&n);++i<n;)scanf("%u",N+i); for(i=-1;++i<n;) { for(x=0,d=j=-1;++j<=n;)S[j]=0; for(j=i-1;++j<n;++A[d]) { if((k=++S[N[j]])>x){x=k;d=N[j];} else if(k==x&&N[j]<d)d=N[j]; } } for(i=0;++i<=n;)printf("%u%c",A[i],i<n?' ':'\n'); return 0; }
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.There are non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
C
f292c099e4eac9259a5bc9e42ff6d1b5
7dadc8e1e5c914ffb812c48999bb3ce5
GNU C
standard output
256 megabytes
train_000.jsonl
[ "data structures", "implementation", "brute force" ]
1462633500
["4\n1 2 1 2", "3\n1 1 1"]
NoteIn the first sample, color 2 is dominant in three intervals: An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color. An interval [4, 4] contains one ball, with color 2 again. An interval [2, 4] contains two balls of color 2 and one ball of color 1. There are 7 more intervals and color 1 is dominant in all of them.
PASSED
1,500
standard input
2 seconds
The first line of the input contains a single integer n (1 ≀ n ≀ 5000)Β β€” the number of balls. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ n) where ti is the color of the i-th ball.
["7 3 0 0", "6 0 0"]
#include<stdio.h> int m[5010],d[5010][5010]={}; int main(){ int n,i,j,a,c[5010]={}; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&a); m[j]=a; for(j=0;j<=i;j++){ d[j][a]++; if(d[j][a]>d[j][m[j]]||d[j][a]==d[j][m[j]]&&m[j]>a)m[j]=a; c[m[j]]++; } } for(i=1;i<n;i++)printf("%d ",c[i]); printf("%d\n",c[n]); return 0; }
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i &gt; 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Print a single number representing the minimum number of dollars paid by Caisa.
C
d03ad531630cbecc43f8da53b02d842e
0b219838c670ace5c420c913f617ce09
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force", "math" ]
1409383800
["5\n3 4 3 2 4", "3\n4 4 4"]
NoteIn the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
PASSED
1,100
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 105). The next line contains n integers h1, h2, ..., hn (1  ≀  hi  ≀  105) representing the heights of the pylons.
["4", "4"]
#include<stdio.h> int main(){ int i,n,l=0 ; scanf("%d", &n); int arr[n+1]; arr[0] = 0; for(i=1;i<n+1;i++){ scanf("%d", &arr[i]); if(arr[i] > l) l=arr[i]; } printf("%d", l); return 0; }
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i &gt; 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Print a single number representing the minimum number of dollars paid by Caisa.
C
d03ad531630cbecc43f8da53b02d842e
6a8286d5fb7fa71aff039f3362c0b166
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force", "math" ]
1409383800
["5\n3 4 3 2 4", "3\n4 4 4"]
NoteIn the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
PASSED
1,100
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 105). The next line contains n integers h1, h2, ..., hn (1  ≀  hi  ≀  105) representing the heights of the pylons.
["4", "4"]
#include <stdio.h> int main() { int n,x,max=0; scanf("%d",&n); for (int i=0;i<n;i++,max=x>max?x:max) scanf("%d",&x); printf("%d\n",max); return 0; }
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i &gt; 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Print a single number representing the minimum number of dollars paid by Caisa.
C
d03ad531630cbecc43f8da53b02d842e
494a24a3ae8c39c7d3d251359cfa0403
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force", "math" ]
1409383800
["5\n3 4 3 2 4", "3\n4 4 4"]
NoteIn the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
PASSED
1,100
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 105). The next line contains n integers h1, h2, ..., hn (1  ≀  hi  ≀  105) representing the heights of the pylons.
["4", "4"]
#include<stdio.h> int main() { int a,i; scanf("%d",&a); int b=0; for(i=0;i<a;i++) { int q; scanf("%d",&q); if(q>b) b=q; } printf("%d\n",b); return 0; }
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i &gt; 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Print a single number representing the minimum number of dollars paid by Caisa.
C
d03ad531630cbecc43f8da53b02d842e
543891f2bdc6b172efe6fe41b3c85bb6
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force", "math" ]
1409383800
["5\n3 4 3 2 4", "3\n4 4 4"]
NoteIn the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
PASSED
1,100
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 105). The next line contains n integers h1, h2, ..., hn (1  ≀  hi  ≀  105) representing the heights of the pylons.
["4", "4"]
#include<stdio.h> int a[1000001]; int main() { int n,m,i,j,ans=0; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); if(ans<a[i]) ans+=(a[i]-ans); } printf("%d",ans); return 0; }
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i &gt; 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Print a single number representing the minimum number of dollars paid by Caisa.
C
d03ad531630cbecc43f8da53b02d842e
be2c5aaebe108cde001fbb1da4859c1c
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force", "math" ]
1409383800
["5\n3 4 3 2 4", "3\n4 4 4"]
NoteIn the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
PASSED
1,100
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 105). The next line contains n integers h1, h2, ..., hn (1  ≀  hi  ≀  105) representing the heights of the pylons.
["4", "4"]
#include<stdio.h> int a[1000001]; int main() { int n,m,i,j,ans=0; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); if(ans<a[i]) ans=a[i]; } printf("%d",ans); return 0; }
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i &gt; 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Print a single number representing the minimum number of dollars paid by Caisa.
C
d03ad531630cbecc43f8da53b02d842e
6f9d73d699129618e745876bfb9d0520
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force", "math" ]
1409383800
["5\n3 4 3 2 4", "3\n4 4 4"]
NoteIn the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
PASSED
1,100
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 105). The next line contains n integers h1, h2, ..., hn (1  ≀  hi  ≀  105) representing the heights of the pylons.
["4", "4"]
#include<stdio.h> int main() { int n,i,j; scanf("%d",&n); int a[n+1]; a[0]=0;long long total=0,sum=0; for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) a[i-1]=a[i-1]-a[i]; for(i=0;i<n;i++) { if((sum+a[i])<0) { total+=-1*(sum+a[i]); sum=0; } else sum+=a[i]; } printf("%I64d\n",total); return 0; }
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i &gt; 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Print a single number representing the minimum number of dollars paid by Caisa.
C
d03ad531630cbecc43f8da53b02d842e
3c65d5d20de7333947ea31a238bbd5e0
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force", "math" ]
1409383800
["5\n3 4 3 2 4", "3\n4 4 4"]
NoteIn the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
PASSED
1,100
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 105). The next line contains n integers h1, h2, ..., hn (1  ≀  hi  ≀  105) representing the heights of the pylons.
["4", "4"]
#include <stdio.h> int main(){ int i,n,cost=0,energy=0; scanf("%d", &n); int pylons[n + 1]; pylons[0] = 0; for(i = 1; i <= n; i++){ scanf("%d", &pylons[i]); } for(i = 0; i < n; i++){ if(pylons[i + 1] < pylons[i]){ energy = energy + pylons[i] - pylons[i + 1]; } else if(pylons[i + 1] - pylons[i] > energy){ cost = cost + (pylons[i + 1] - pylons[i] - energy); energy = 0; } else { energy = energy - (pylons[i + 1] - pylons[i]); } } printf("%d", cost); return 0; }
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i &gt; 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
Print a single number representing the minimum number of dollars paid by Caisa.
C
d03ad531630cbecc43f8da53b02d842e
6adb58f12aa03db49e09e98c18e4c845
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force", "math" ]
1409383800
["5\n3 4 3 2 4", "3\n4 4 4"]
NoteIn the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
PASSED
1,100
standard input
1 second
The first line contains integer n (1 ≀ n ≀ 105). The next line contains n integers h1, h2, ..., hn (1  ≀  hi  ≀  105) representing the heights of the pylons.
["4", "4"]
r;main(n,x){ for(scanf("%d",&n);n--;r=r>x?r:x)scanf("%d",&x); printf("%d\n",r); exit(0);}
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
4cfb5402003e54d55411c6e0c1036b25
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { long long int sum1=0,sum2=0,x,i,j,n,a[200010]; scanf("%lld",&n); for(i=0;i<n;i++){ scanf("%lld",&a[i]); } for(i=0;i<n;i++){ sum1+=a[i]; } if(sum1%2==0) { x=sum1/2; } else { x=sum1/2; x++; } for(i=0;i<n;i++) { sum2+=a[i]; if(sum2>=x) { printf("%d",i+1); break; } } }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
ad98a50ed487d1d77ffc6eb3eb1bbe1b
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> #include<math.h> int main(){ int n,i,a[200000]; long long int c=0,d=0,x; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",&a[i]); c+=(long long int)a[i]; } for(i=1;i<=n;i++){ d+=(long long int)a[i]; x=ceil((double)c/2); if(d>=x) break; } printf("%d",i); return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
ba440488e047a19a3806717aa5bdd1e8
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> #include<math.h> int main() { int i,n,sum=0,x=0; int equator; scanf("%d",&n); int a[n]; for(i=0;i<n;i++) { scanf("%d",&a[i]); sum=sum+a[i]; } equator =ceil(sum/2.0); for(i=0;i<n;i++) { x=x+a[i]; if(x>=equator) { break; } } printf("%d",i+1); }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
afcfc06d1586f52fefe23573ac757821
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { int n,i,s=0,a[200020],su=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); s+=a[i]; } if(s%2!=0) s=s+1; su=0; for(i=0;i<n;i++) { su+=a[i]; if(su>=s/2) break; } printf("%d",i+1); }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
9b038355d50162bc82d3b19fe84a8e13
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { long int n; scanf("%ld",&n); long int a[n],sum1=0,sum2=0,i; long int p=0; for(i=0;i<n;i++) { scanf("%ld",&a[i]); sum1=sum1+a[i]; } p=(sum1/2); if(n>1){ if(sum1%2==0){ for(i=0;i<n;i++) { sum2=sum2+a[i]; if(sum2==p) { printf("%ld",i+1); break; } else { if(sum2>p&&i==n-1) printf("%ld",i+1); } }} else {for(i=0;i<n;i++){ sum2=sum2+a[i]; if(sum2>p) { printf("%ld",i+1); break; } else { if(sum2==p&&i==n-1) printf("%ld",i+1); } } }} else printf("1"); return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
ff5fcb3e12abd11663d8906f79502119
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { int n,i,sum=0,b=0; float j; scanf("%d",&n); int a[n]; for(i=0;i<n;i++){ scanf("%d",&a[i]); sum=sum+a[i]; } for(i=0;i<n;i++){ b=b+a[i]; if(b>=sum/2.0){ break; } } printf("%d\n",i+1); return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
bdfbbe975b36530d2d7833336cb6e3b9
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> #include <stdlib.h> int main() { int numberOfProblem; scanf("%d",&numberOfProblem); int problem[numberOfProblem]; int sumOfProblem=0; for(int i = 0 ; i < numberOfProblem ; i ++) { scanf("%d",&problem[i]); sumOfProblem+=problem[i]; } if (sumOfProblem%2==0) { sumOfProblem=sumOfProblem/2; } else { sumOfProblem=(sumOfProblem-1)/2; sumOfProblem++; } for(int i = 0 ; i < numberOfProblem ; i ++) { sumOfProblem-=problem[i]; if (sumOfProblem<0 || sumOfProblem==0) { printf("%d",(i+1)); break; } } return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
f67b4f2846f397dfa1d61d20e81661dc
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> int main() { int n; scanf("%d", &n); int arr[n]; unsigned long long int sum=0; for (int i=0;i<n;i++) { scanf("%d", &arr[i]); sum+=arr[i]; } unsigned long long int half=0, idx=0; if (sum%2==1) sum=sum/2+1; else sum=sum/2; while (half<sum) { half+=arr[idx++]; } printf("%d\n", idx); }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
4b92e49adcb47dcc7118fb79ce8dc0eb
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { int n; scanf("%d",&n); int a[n],i,sum=0,j=0; for(i=1;i<=n;i++) { scanf("%d",&a[i]); sum=sum+a[i]; } for(i=1;i<=n;i++) { j=j+a[i]; if(j*2>=sum) { printf("%d",i); break; } } }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
abddc212e0c8234a075ca60d05789ce8
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
// WTFPL - Copyright (C) 2018 // 962A - Equator #include <stdio.h> #include <math.h> #include <stdlib.h> int kind_of_search(long int *arr, int size, long int needle) { int L = 0; int R = size; while (L < R) { int mid = L + (R - L) / 2; if (needle <= arr[mid]) R = mid; else L = mid + 1; } return L; } int main() { long int *dp, x; int N; scanf("%d", &N); dp = (long int*)malloc(sizeof (long int) * N); for (int i = 0; i < N; ++i) { scanf("%ld", &x); if (i) dp[i] = dp[i - 1] + x; else dp[i] = x; } //printf("%f\n", ceilf((float)(dp[N - 1] / 2.0))); printf("%d\n", kind_of_search(dp, N, ceil(dp[N - 1] / 2.0)) + 1); free(dp); return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
e89b511772c7b64ed37698ba01d4ee2e
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { int n,i,a[200000],s=0,k=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); s+=a[i]; } if(s%2==0) { s/=2; } else { s++; s/=2; } for(i=0;i<n;i++) { k+=a[i]; if(k>=s) { printf("%d",i+1); return 0; } } }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
553186ce2c3a6ea4ae6ea91ab1272d10
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> long long cmpfunc (const void * a, const void * b) { return ( *(long long*)a - *(long long*)b ); } int main(void){ long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,k,sum2,min,f,r,o,sum1,sum=0,y,b,count1, a[1000000]; scanf("%lld",&n); sum=0; for(i=1;i<=n;i++){ scanf("%lld",&a[i]); sum+=a[i]; } sum1=0; sum=(sum%2==0)?sum/2:sum/2+1; for(i=1;i<=n;i++){ sum1+=a[i]; if(sum<=sum1){ printf("%lld",i); return 0; } // printf("%lld %lld\n",sum1,sum); } return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
e50e394ff78ccf56dfbf40c4f0b9f8fa
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> int compre( void *a, void *b){ return strlen(a)-strlen(b); } int main(void){ long long int test,i,j,n,count,flag,flag2,b1,l,p,i1,i2,m,u,r,q,d,x,max,max2,min,f,sum1,sum,a[2000000],b,c; scanf("%lld",&n); sum=0; for(i=0;i<n;i++){ scanf("%lld",&a[i]); sum+=a[i]; } sum1=sum/2+sum%2; i1=1; i=0; while(sum1>0){ sum1-=a[i]; i++; } printf("%lld",i); return 0; }

No dataset card yet

Downloads last month
13