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
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
bce8dcc8487f4239fa770b9ddd03dad2
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include<stdio.h> main() { long int n,m; scanf("%ld %ld", &n, &m); long long a[n], b[m], c[n]; scanf("%lld", &a[0]); c[0] = a[0]; for(int i=1; i<n; i++) { scanf("%lld", &a[i]); c[i] = c[i-1] + a[i]; } for(int i=0; i<m; i++) { scanf("%lld", &b[i]); } long int limInf, limSup, med; for(int i=0; i<m; i++) { limInf = 0; limSup = (n-1); while(limInf<limSup) { med = (limInf+limSup)/2; //printf("c[limInf] = %d, c[med]= %d, c[limSup] = %d \n", c[limInf], c[med], c[limSup]); if(c[med]<b[i]) { limInf = med+1; } else { limSup = med; } } if(limInf==0) { printf("%ld %lld\n", limInf+1, b[i]); } else { printf("%ld %lld\n", limInf+1, b[i]-c[limInf-1]); } } }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
1424de2257f862d2a0ce2ba1362f0ff7
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> #include <stdlib.h> int main() { long long n, m; scanf("%lld%lld", &n, &m); long long *a = malloc(sizeof(long long) * n); for (int i = 0; i < n; i++) scanf("%lld", a + i); long long sum = 0, idx = 1; for (int i = 0; i < m; i++) { long long room; scanf("%lld", &room); while (room > sum + a[idx - 1]) { sum += a[idx - 1]; idx++; } printf("%lld %lld\n", idx, room - sum); } }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
3fd3f9f7f480cb8345f1517571db1def
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> #define ll long long typedef struct { ll roomnum; ll accum; }Dorm; ll findDorm(Dorm dorm[], ll n, ll room) { ll low = 0, high = n; while(high-low > 1) { ll half = (high+low)/2; if(dorm[(high+low)/2].accum > room) high = half; else low = half; } if(room <= dorm[high].accum && room > dorm[low].accum) return high; return low; } int main() { int n, m; scanf("%d %d", &n, &m); Dorm dorm[n]; ll accum = 0; for(int i = 0; i < n; i++) { scanf("%I64d", &dorm[i].roomnum); accum += dorm[i].roomnum; dorm[i].accum = accum; } for(int i = 0; i < m; i++) { ll room; scanf("%I64d", &room); ll dormNum = findDorm(dorm, n, room); if(dormNum == 0) printf("%I64d %I64d\n", dormNum+1, room); else printf("%I64d %I64d\n", dormNum+1, room - dorm[dormNum-1].accum); } return 0; }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
782ea32a186488cf67c2088b545917be
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> #include <string.h> int main(void) { int m,n,i,j,count=1,p=0; scanf ("%d%d",&n,&m); long long int a[n],b[m],rm,sum=0; for(i=0;i<n;i++) scanf("%lld",&a[i]); for(i=0;i<m;i++) scanf("%lld",&b[i]); for(i=0;i<n;i++){ for(j=p;j<m;j++){ if(b[j]<=a[i]+sum){ rm=b[j]-sum; printf("%d %lld\n",count,rm); rm=0; p++; } else break; } sum=sum+a[i]; count++; } return 0; }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
3fc0cd3cde1fdb8dcbb1c4f1ed9c8859
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include<stdio.h> int main(){ long n,m; //dorms,letters scanf("%ld%ld",&n,&m); int i,lo,hi,to,ans; long long a[n]; //no of rooms at ith dorm long long b[m]; //letter's room no long long temp[n]; long long room; for(i=0;i<n;i++){ scanf("%lld",&a[i]); } for(i=0;i<m;i++){ scanf("%lld",&b[i]); } for(i=1;i<n;i++){ a[i]+=a[i-1]; } for(i=0;i<m;i++){ lo=0; hi=n-1; if(b[i]<=a[0]) { printf("1 %lld\n",b[i]); continue; } while(lo<=hi){ to=(lo+hi)/2; if(b[i]<=a[to+1] && b[i]>a[to]){ ans=to+2; room=b[i]-a[to]; printf("%d %lld\n",ans,room); break; } else if(b[i]<=a[to]){ hi=to-1; } else{ lo=to+1; } } } return 0; }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
861fd7bc04a9a0fc3febc4d658b49da7
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> long long int f,k; void Binary(long long int *sum,long long int r,long long int l,long long int x){ if (r==l){ if (sum[r]>=x){ k = x - sum[r-1]; f = r; } else{ k = x - sum[r]; f = r+1; } return; } long long int mid = (r+l)/2; if (sum[mid]==x){ k = x-sum[mid-1]; f = mid; return; } if (sum[mid]>x){ Binary(sum,r,mid,x); } else{ Binary(sum,mid+1,l,x); } return; } int main(void) { // your code goes here long long int n,m; scanf("%lld %lld",&n,&m); long long int a[n]; for (int i=0;i<n;i++){ scanf("%lld",&a[i]); } long long int sum[n+1]; sum[0] = 0; sum[1] = a[0]; for (int i=2;i<=n;i++){ sum[i] = sum[i-1] + a[i-1]; } long long int q; for (int i=0;i<m;i++){ f = k = 0; scanf("%lld",&q); Binary(sum,1,n,q); printf("%lld %lld\n",f,k); } return 0; }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
75fce4d20031a4c0ab9719ce24a1ce0b
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> int search(int n, long long int a[n], long long int target) { int i; if(a[0]>=target) { printf("1 %lld\n", target); return 0; } int L = 0, R = n-1; int M; while((R-L)>1) { // printf("L = %d, R = %d\n", L,R); if((L+R)%2==0) { M = (L+R)/2; // printf("M = %d", M); } else { M = (L+R-1)/2; // printf("M = %d", M); } if(a[M] < target) { L = M; } else if (a[M] == target) { printf("%d %lld\n", M+1, target-a[M-1]); return 0; } else { R = M; } } if(target == a[L]) { printf("%d %lld\n", L+1, target); return 0; } else if(target == a[R]) { printf("%d %lld\n", R+1, target-a[R-1]); } else { printf("%d %lld\n", L+2, target-a[L]); } } int main(){ int n, m, i; scanf("%d %d", &n, &m); long long int a[n]; long long int b[m]; long long int sum = 0; long long int tmp; for(i=0;i<n;i++) { scanf("%lld", &tmp); a[i] = tmp + sum; sum = tmp + sum; } for(i=0;i<m;i++) { scanf("%lld", &b[i]); } for(i=0;i<m;i++) search(n, a, b[i]); } /*int main(){ int n, m, i, j; scanf("%d %d", &n, &m); long long int a[n]; long long int b[m]; for(i=0; i<n; i++) { scanf("%lld", &a[i]); } for(i=0;i<m;i++) { scanf("%lld", &b[i]); } int count = 1; for(i=0;i<m;i++) { for(j=0;j<n;j++) { if(b[i]-a[j] < 0) { printf("%d %lld\n", count, b[i]); break; } else { if(b[i]-a[j] == 0) { printf("%d %lld\n", count, b[i]); break; } count++; b[i] = b[i]-a[j]; } } count = 1; } }*/
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
863caddde78d9ccbfc37949e1b3dff04
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include<stdio.h> int main() { long long int n,m; scanf("%lld %lld",&n,&m); long long int a[n],b[m],i,j,k,num=0,cum=0; for(i=0;i<n;i=i+1) { scanf("%lld",&a[i]); } for(i=0;i<m;i=i+1) { scanf("%lld",&b[i]); } i=0; num=a[0]; for(j=0;j<m;j=j+1) { for(k=1;k!=0;k=k+1) { if(b[j]<=num) { printf("%lld %lld\n",i+1,b[j]-cum); break; } else { i=i+1; num=num+a[i]; cum=cum+a[i-1]; } } } }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
5bea5ef14aa272ec7cf74bf287d34c91
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> long long a[200005],b[200005]; long long sum[200005]={0}; int m,n; int main() { int i,j; a[0]=0; scanf("%d%d",&m,&n); for(i=1;i<=m;i++) { scanf("%lld",&a[i]); sum[i]=sum[i-1]+a[i]; } for(i=0;i<n;i++) scanf("%lld",&b[i]); int rt=1; for(i=0;i<n;i++) { for(j=rt;j<=m;j++) { if(b[i]<=sum[j]&&b[i]>sum[j-1]) { printf("%d %lld\n",j,b[i]-sum[j-1]); rt=j; break; } } } return 0; }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
c654d950c51afd79fa5ea9d68fb1f91e
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> #define N 200000 long long a[N + 1]; int lower_bound(long long *aa, int n, long long x) { int low = 0; int high = n; while (low < high){ int mid = low + (high - low) / 2; if (x <= aa[mid]){ high = mid; } else{ low = mid + 1; } } return low; } int main(){ int n, i, m, t; long long b; scanf("%d%d", &n, &m); a[0] = 0; for(i = 1; i <= n; i++){ scanf("%lld", &a[i]); a[i] += a[i - 1]; } while(m--){ scanf("%lld", &b); t = lower_bound(a, n + 1, b); printf("%d %lld\n", t, b - a[t - 1]); } return 0; }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
6678fae5045e64c672244afbe80d55e5
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
/* https://codeforces.com/contest/978/submission/74212074 (kaiboy) */ #include <stdio.h> #define N 200000 long long a[N + 1]; int main(){ int n, m, i; long long s, b; scanf("%d%d", &n, &m); for(i = 0; i < n; i++){ scanf("%lld", &a[i]); } i = s = 0; while(m--){ scanf("%lld", &b); while(i < n && s + a[i] < b){ s += a[i]; ++i; } printf("%d %lld\n", i + 1, b - s); } }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
d5e96603d2206cc6c424322bcb6ecf68
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include<stdio.h> int main() { long long n,m,a[200001]= {0},t,i; scanf("%lld%lld",&n,&m); scanf("%lld",&a[1]); for(i=2; i<=n; i++) { scanf("%lld",&a[i]); a[i]+=a[i-1]; } i=0; while(m--) { scanf("%lld",&t); while(a[i]<t) i++; printf("%lld %lld\n",i,t-a[i-1]); } return 0; }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
75a422969ce64f900d1d0c673e37efc7
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include<stdio.h> #include<stdlib.h> int main() { int n,m,i; long long num1=1,num2=1,j,cnt=0,k=0,cnt2=0; scanf("%d%d",&n,&m); long long *p=(long long *)malloc(n*sizeof(long long)); long long *q=(long long *)malloc(m*sizeof(long long)); for(i=0;i<n;i++) { scanf("%lld",&p[i]); } cnt=p[k]; for(j=0;j<m;j++) { scanf("%lld",&q[j]); while(q[j]>cnt) { cnt=cnt+p[++k]; } num1=k+1; //่ฆไธ่ฆๆŠŠไบŒๅˆ†ๆœ็ดข่ฟ™ไธชๅ‡ฝๆ•ฐๅฅ—็”จ่ฟ›ๅŽป๏ผ› cnt2=cnt-p[k]; num2=q[j]-cnt2; printf("%lld %lld\n",num1,num2); } free(q); free(p); }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
99568072beeba2f9037d5b7f676ca7c9
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include<stdio.h> int main(){ long long int num1,num2,q1,q2; scanf("%lld %lld",&num1,&num2); q1=num1; q2=num2; long long int i=0,j=0,k=0; long long int a[q1+50],b[q2+50]; for(i=0;i<num1;i++){ scanf("%lld",&a[i]); } for(i=0;i<num2;i++){ scanf("%lld",&b[i]); } for(i=0;i<num1;i++){ k=k+a[i]; for(;j<num2;j++){ if(b[j]<=k&&i==0){printf("%lld %lld\n",i+1,b[j]);} else if(b[j]<=k)printf("%lld %lld\n",i+1,b[j]-(k-a[i])); else if(b[j]>k)break; } } }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
d6fcef36ad53d74785c75873cdf9f79c
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> int main(void) { // your code goes here long n,m,i,j; scanf("%ld %ld", &n,&m); long long a[n]; long long k,sum1=0,sum2=0; for(i=0;i<n;i++) scanf("%lld", &a[i]); j=0; sum1+=a[0]; i=1; while(j!=m) {scanf("%lld", &k); while(k>sum1) { sum2=sum1; sum1+=a[i]; i++; } printf("%ld %lld\n", i,k-sum2); j++; } return 0; }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
da99350357907e7d2b7cb820fd42f87d
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> int main(void) { long long int n,m,i,j,c; scanf("%lld%lld",&n,&m); long long int a[n],ac[n],b[m]; for(i=0;i<n;i++) { scanf("%lld",&a[i]); if(i==0) { ac[i]=a[i]; } else ac[i]=a[i]+ac[i-1]; } c=0; for(j=0;j<m;j++) {scanf("%lld",&b[j]); for(i=c;i<n;i++) {if(b[j]<=ac[i]) { if(i==0) printf("1 %lld\n",b[j]); else printf("%lld %lld\n",i+1,b[j]-ac[i-1]); break;} c++;} } return 0; }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
2479a238c1846ff86be46de72d66fa15
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include<stdio.h> int main() { int n,m; scanf("%d %d",&n,&m); long long cumm[n+1]; for(int i=0;i<n+1;i++)cumm[i]=0; long long l[m]; long long a[n]; for(int i=0;i<n;i++) { scanf("%I64d",&a[i]); } for(int i=0;i<m;i++) { scanf("%I64d",&l[i]); } for(int i=1;i<n+1;i++) { cumm[i]=cumm[i-1]+a[i-1]; } int t=1; for(int i=0;i<m;i++) { while(t<=n) { if(l[i]<=cumm[t]) { printf("%d %I64d\n",t,l[i]-cumm[t-1]); //System.out.println(t+" "+(l[i]-cumm[t-1])); break; } else { t++; } } } }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
7c1e536188bead782245ad22bf356336
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> unsigned long long a[200001]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%llu", &a[i]); a[i] += a[i-1]; } int idx = 1; for (int i = 0; i < m; i++) { unsigned long long b; scanf("%llu", &b); while (b > a[idx]) idx++; printf("%d %llu\n", idx, b-a[idx-1]); } return 0; }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
91d8984d896efad3f7ec92115da4dbcc
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include<stdio.h> typedef long long ll; int main() { ll n,m,p=0; scanf("%lld%lld",&n,&m); ll a,ar[n],br[m],temp,sum; for(ll i=0;i<n;i++) { scanf("%lld",&a); if(i==0) ar[i]=a; else ar[i]=a+ar[i-1]; } //for(ll i=0;i<n;i++) //printf("%lld ",ar[i]); for(ll i=0;i<m;i++) scanf("%lld",&br[i]); for(ll i=0;i<m;i++) { temp=br[i]; sum=0; for(ll j=p;j<n;j++) { if(ar[j]>=temp) { printf("%lld %lld\n",j+1,temp-sum); // p=j; break; } else { sum=ar[j]; p=j; } } } return 0; }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
a5c45967ec4e78f649a8b34892eca417
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> long long a[200200]; long long ps[200200]; int n, m; int bs(long long val) { int l = 1, r = n, ans = -1; while (l <= r) { int m = l + (r - l) / 2; if (val >= ps[m]) { ans = m; l = m + 1; } else r = m - 1; } return ans; } void solve() { long long b; scanf("%lld", &b); int pos = bs(b); if (pos != -1) { if (ps[pos] == b) { printf("%d %lld\n", pos, a[pos]); } else { printf("%d %lld\n", pos + 1, b - ps[pos]); } } else { printf("1 %lld\n", b); } } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); ps[i] = ps[i - 1] + a[i]; } for (int i = 1; i <= m; i++) { solve(); } }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
3b5a4e6fdb06987ae0b3bf7d87cf4a91
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include<stdio.h> #define ll long long int main() { ll n,m,j=1; scanf("%I64d%I64d", &n,&m); ll a,b,k[n+5]; k[0]=0; for(ll i=1; i<=n; i++) { scanf("%I64d", &a); k[i]=k[i-1]+a; } while(m--) { scanf("%lld", &b); while(k[j]<b) j++; printf("%I64d %I64d\n", j,b-k[j-1]); } }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
9545a128e16fa143c0b728013bbf055a
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> int main() { long long int m,n,i,j,c=0; scanf("%lld%lld",&m,&n); long long int r[m],l[n],max[m]; for(i=0;i<m;i++) { scanf("%lld",&r[i]); } for(i=0;i<n;i++) { scanf("%lld",&l[i]); } max[0]=r[0]; for(i=1;i<m;i++) { max[i]=r[i]+max[i-1]; } j=0; for(i=0;i<m;i++) { if(j<n) {if(i==0) { while(l[j]<=max[i]&&j<n) { printf("%lld %lld\n",i+1,l[j]); j++; } } else { while(l[j]<=max[i]&&j<n) { printf("%lld %lld\n",i+1,l[j]-max[i-1]); j++; } } } else break; } return 0; }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
6bb68fb73f99756a7932b193fe5e1835
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #define queue struct queue1 long cmpfunc(const void *a,const void *b){ return (long*)a-(long*)b; } long long n,m; long long dor[200005]; int main(void){ scanf("%lld",&n); scanf("%lld",&m); long long count; for (count = 0; count < n; count++) scanf("%lld",&dor[count]); long long max = 0; long countDor = 0; long long numberRoom = 0; for (count = 0; count < m; count++){ long long number; scanf("%lld",&number); while (numberRoom + dor[countDor] < number){ numberRoom+= dor[countDor]; countDor++; } printf("%ld %lld\n",countDor+1,number-numberRoom); } }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
1e1c12827a17a3ef8ae2aabacc696f83
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
#include<stdio.h> #include<math.h> long long rm[200005]={0},xin[200005]; int n,m; int main() { int i,j; scanf("%d %d",&n,&m); for(i=1;i<=n;i++) { scanf("%I64d",&rm[i]); rm[i]+=rm[i-1]; } for(i=1;i<=m;i++) scanf("%I64d",&xin[i]); for(i=1,j=1;i<=m;i++) { if(xin[i]<=rm[j]) { printf("%d %I64d\n",j,xin[i]-rm[j-1]); } else j++,i--; } }
There are $$$n$$$ dormitories in Berland State University, they are numbered with integers from $$$1$$$ to $$$n$$$. Each dormitory consists of rooms, there are $$$a_i$$$ rooms in $$$i$$$-th dormitory. The rooms in $$$i$$$-th dormitory are numbered from $$$1$$$ to $$$a_i$$$.A postman delivers letters. Sometimes there is no specific dormitory and room number in it on an envelope. Instead of it only a room number among all rooms of all $$$n$$$ dormitories is written on an envelope. In this case, assume that all the rooms are numbered from $$$1$$$ to $$$a_1 + a_2 + \dots + a_n$$$ and the rooms of the first dormitory go first, the rooms of the second dormitory go after them and so on.For example, in case $$$n=2$$$, $$$a_1=3$$$ and $$$a_2=5$$$ an envelope can have any integer from $$$1$$$ to $$$8$$$ written on it. If the number $$$7$$$ is written on an envelope, it means that the letter should be delivered to the room number $$$4$$$ of the second dormitory.For each of $$$m$$$ letters by the room number among all $$$n$$$ dormitories, determine the particular dormitory and the room number in a dormitory where this letter should be delivered.
Print $$$m$$$ lines. For each letter print two integers $$$f$$$ and $$$k$$$ โ€” the dormitory number $$$f$$$ $$$(1 \le f \le n)$$$ and the room number $$$k$$$ in this dormitory $$$(1 \le k \le a_f)$$$ to deliver the letter.
C
56bdab2019ee12e18d4f7e17ac414962
4f502ee2fbb03072fb2cdea3ebf06a29
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "two pointers", "binary search", "implementation" ]
1526202300
["3 6\n10 15 12\n1 9 12 23 26 37", "2 3\n5 10000000000\n5 6 9999999999"]
NoteIn the first example letters should be delivered in the following order: the first letter in room $$$1$$$ of the first dormitory the second letter in room $$$9$$$ of the first dormitory the third letter in room $$$2$$$ of the second dormitory the fourth letter in room $$$13$$$ of the second dormitory the fifth letter in room $$$1$$$ of the third dormitory the sixth letter in room $$$12$$$ of the third dormitory
PASSED
1,000
standard input
4 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \le n, m \le 2 \cdot 10^{5})$$$ โ€” the number of dormitories and the number of letters. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{10})$$$, where $$$a_i$$$ equals to the number of rooms in the $$$i$$$-th dormitory. The third line contains a sequence $$$b_1, b_2, \dots, b_m$$$ $$$(1 \le b_j \le a_1 + a_2 + \dots + a_n)$$$, where $$$b_j$$$ equals to the room number (among all rooms of all dormitories) for the $$$j$$$-th letter. All $$$b_j$$$ are given in increasing order.
["1 1\n1 9\n2 2\n2 13\n3 1\n3 12", "1 5\n2 1\n2 9999999994"]
///IMTMTO... #include<stdio.h> typedef long long ll; int main() { ll n,k; scanf("%lld%lld",&n,&k); ll a[n+1],i,m=0,x; a[0]=0; for(i=1;i<=n;i++){ scanf("%lld",&x); m+=x; a[i]=m; } ll q; for(i=1;i<=k;i++){ scanf("%lld",&q); ll high,mid,low; low=0,high=n; while(low<=high){ mid=(low+high)/2; if(q>a[mid-1] && q<=a[mid]){ printf("%lld %lld\n",mid,q-a[mid-1]); break; } else if(q>a[mid]) low=mid+1; else high=mid-1; } } return 0; }
The best programmers of Embezzland compete to develop a part of the project called "e-Government" โ€” the system of automated statistic collecting and press analysis.We know that any of the k citizens can become a member of the Embezzland government. The citizens' surnames are a1,โ€‰a2,โ€‰...,โ€‰ak. All surnames are different. Initially all k citizens from this list are members of the government. The system should support the following options: Include citizen ai to the government. Exclude citizen ai from the government. Given a newspaper article text, calculate how politicized it is. To do this, for every active government member the system counts the number of times his surname occurs in the text as a substring. All occurrences are taken into consideration, including the intersecting ones. The degree of politicization of a text is defined as the sum of these values for all active government members. Implement this system.
For any "calculate politicization" operation print on a separate line the degree of the politicization of the given text. Print nothing for other operations.
C
b3038ba22e3442c142a99f485dd55308
ad1f52c28958523ea4ac54d8f93eebb6
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "data structures", "dfs and similar", "trees", "strings" ]
1332687900
["7 3\na\naa\nab\n?aaab\n-2\n?aaab\n-3\n?aaab\n+2\n?aabbaa"]
null
PASSED
2,800
standard input
1 second
The first line contains space-separated integers n and k (1โ€‰โ‰คโ€‰n,โ€‰kโ€‰โ‰คโ€‰105) โ€” the number of queries to the system and the number of potential government members. Next k lines contain the surnames a1,โ€‰a2,โ€‰...,โ€‰ak, one per line. All surnames are pairwise different. Next n lines contain queries to the system, one per line. Each query consists of a character that determines an operation and the operation argument, written consecutively without a space. Operation "include in the government" corresponds to the character "+", operation "exclude" corresponds to "-". An argument of those operations is an integer between 1 and k โ€” the index of the citizen involved in the operation. Any citizen can be included and excluded from the government an arbitrary number of times in any order. Including in the government a citizen who is already there or excluding the citizen who isn't there changes nothing. The operation "calculate politicization" corresponds to character "?". Its argument is a text. All strings โ€” surnames and texts โ€” are non-empty sequences of lowercase Latin letters. The total length of all surnames doesn't exceed 106, the total length of all texts doesn't exceed 106.
["6\n4\n3\n6"]
#include <stdio.h> #include <string.h> #define M 100000 #define L 1000000 #define N (1 + 1 + L) #define A 26 int oo[1 + N - 1], oj[1 + N - 1]; int link(int o, int j) { static int _ = 1; oo[_] = o, oj[_] = j; return _++; } int tt[N][A], ae[N], ta[N], tb[N]; void dfs(int i) { static int time; int o; ta[i] = time++; for (o = ae[i]; o; o = oo[o]) { int j = oj[o]; dfs(j); } tb[i] = time; } int aho_corasick(char **bb, int *ss, int m) { static int ff[N], qu[N]; int n, h, head, cnt; n = 2; for (h = 0; h < m; h++) { int l = strlen(bb[h]), k, s; s = 1; for (k = 0; k < l; k++) { int a = bb[h][k] - 'a'; if (tt[s][a] == 0) tt[s][a] = n++; s = tt[s][a]; } ss[h] = s; } head = cnt = 0; ff[1] = 0, qu[head + cnt++] = 1; while (cnt) { int s = qu[cnt--, head++], e = ff[s], a; for (a = 0; a < A; a++) { int t = tt[s][a], f = e == 0 ? 1 : tt[e][a]; if (t == 0) tt[s][a] = f; else ff[t] = f, ae[f] = link(ae[f], t), qu[head + cnt++] = t; } } dfs(1); return n; } int ft[N]; void update(int i, int n, int x) { while (i < n) { ft[i] += x; i |= i + 1; } } int query(int i) { int x = 0; while (i >= 0) { x += ft[i]; i &= i + 1, i--; } return x; } int main() { static char *bb[M], on[M]; static int ss[M]; int n, m, q, h; scanf("%d%d", &q, &m); for (h = 0; h < m; h++) { static char s[L + 1]; scanf("%s", s); bb[h] = strdup(s); } n = aho_corasick(bb, ss, m); for (h = 0; h < m; h++) { int s = ss[h]; update(ta[s], n, 1), update(tb[s], n, -1), on[h] = 1; } while (q--) { static char op[L + 2]; scanf("%s", op); if (op[0] == '+') { sscanf(op, "+%d", &h), h--; if (!on[h]) { int s = ss[h]; update(ta[s], n, 1), update(tb[s], n, -1), on[h] = 1; } } else if (op[0] == '-') { sscanf(op, "-%d", &h), h--; if (on[h]) { int s = ss[h]; update(ta[s], n, -1), update(tb[s], n, 1), on[h] = 0; } } else { int l, k, s; long long ans; l = strlen(op) - 1; ans = 0; for (k = 1, s = 1; k <= l; k++) { int a = op[k] - 'a'; s = tt[s][a]; ans += query(ta[s]); } printf("%lld\n", ans); } } return 0; }
There is a matrix A of size xโ€‰ร—โ€‰y filled with integers. For every , Ai,โ€‰jโ€‰=โ€‰y(iโ€‰-โ€‰1)โ€‰+โ€‰j. Obviously, every integer from [1..xy] occurs exactly once in this matrix. You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.From the cell located in i-th line and j-th column (we denote this cell as (i,โ€‰j)) you can move into one of the following cells: (iโ€‰+โ€‰1,โ€‰j) โ€” only if iโ€‰&lt;โ€‰x; (i,โ€‰jโ€‰+โ€‰1) โ€” only if jโ€‰&lt;โ€‰y; (iโ€‰-โ€‰1,โ€‰j) โ€” only if iโ€‰&gt;โ€‰1; (i,โ€‰jโ€‰-โ€‰1) โ€” only if jโ€‰&gt;โ€‰1.Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
If all possible values of x and y such that 1โ€‰โ‰คโ€‰x,โ€‰yโ€‰โ‰คโ€‰109 contradict with the information about your path, print NO. Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
C
3b725f11009768904514d87e2c7714ee
d7e2a5839028a6efb2288eb15e908ed2
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1521698700
["8\n1 2 3 6 9 8 5 2", "6\n1 2 1 2 5 3", "2\n1 10"]
NoteThe matrix and the path on it in the first test looks like this: Also there exist multiple correct answers for both the first and the third examples.
PASSED
1,700
standard input
1 second
The first line contains one integer number n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰200000) โ€” the number of cells you visited on your path (if some cell is visited twice, then it's listed twice). The second line contains n integers a1, a2, ..., an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109) โ€” the integers in the cells on your path.
["YES\n3 3", "NO", "YES\n4 9"]
#include<stdio.h> #include<math.h> int main() { int a[200000],n,w=1,x,y,i; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=1;i<n;i++) if(abs(a[i]-a[i-1])!=1) { if(a[i]==a[i-1]) { printf("NO"); return 0; } else { w=abs(a[i]-a[i-1]); break; } } y=ceil((double)a[0]/w); x=(a[0]-1)%w+1; for(i=1;i<n;i++) { if(abs(a[i]-a[i-1])==1) a[i]>a[i-1] ? x++ : x--; else a[i]>a[i-1] ? y++ : y--; if(w*(y-1)+x!=a[i] || x<1 || y<1|| x>w) break; } if(i==n || w==1) printf("YES\n1000000000 %d",w); else printf("NO"); return 0; }
There is a matrix A of size xโ€‰ร—โ€‰y filled with integers. For every , Ai,โ€‰jโ€‰=โ€‰y(iโ€‰-โ€‰1)โ€‰+โ€‰j. Obviously, every integer from [1..xy] occurs exactly once in this matrix. You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.From the cell located in i-th line and j-th column (we denote this cell as (i,โ€‰j)) you can move into one of the following cells: (iโ€‰+โ€‰1,โ€‰j) โ€” only if iโ€‰&lt;โ€‰x; (i,โ€‰jโ€‰+โ€‰1) โ€” only if jโ€‰&lt;โ€‰y; (iโ€‰-โ€‰1,โ€‰j) โ€” only if iโ€‰&gt;โ€‰1; (i,โ€‰jโ€‰-โ€‰1) โ€” only if jโ€‰&gt;โ€‰1.Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
If all possible values of x and y such that 1โ€‰โ‰คโ€‰x,โ€‰yโ€‰โ‰คโ€‰109 contradict with the information about your path, print NO. Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
C
3b725f11009768904514d87e2c7714ee
8898945f4cb8db2dca3ad00c6f75b015
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1521698700
["8\n1 2 3 6 9 8 5 2", "6\n1 2 1 2 5 3", "2\n1 10"]
NoteThe matrix and the path on it in the first test looks like this: Also there exist multiple correct answers for both the first and the third examples.
PASSED
1,700
standard input
1 second
The first line contains one integer number n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰200000) โ€” the number of cells you visited on your path (if some cell is visited twice, then it's listed twice). The second line contains n integers a1, a2, ..., an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109) โ€” the integers in the cells on your path.
["YES\n3 3", "NO", "YES\n4 9"]
//set many funcs template #include<stdio.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> #include<time.h> #define inf 1072114514 #define llinf 4154118101919364364 #define mod 1000000007 #define pi 3.1415926535897932384 int max(int a,int b){if(a>b){return a;}return b;} int min(int a,int b){if(a<b){return a;}return b;} int zt(int a,int b){return max(a,b)-min(a,b);} int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;} int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;} int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;} int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;} int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} long long llmax(long long a,long long b){if(a>b){return a;}return b;} long long llmin(long long a,long long b){if(a<b){return a;}return b;} long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);} long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;} long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;} long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;} long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;} long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} double dbmax(double a,double b){if(a>b){return a;}return b;} double dbmin(double a,double b){if(a<b){return a;}return b;} double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);} int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;} int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;} int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;} int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;} int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;} int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;} int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);} int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);} int main(void){ int i,j,n,m,k,a[262144],b,c,w,r=0,l,t=1; int fl[262144]={0}; double d; char s[262144]; scanf("%d",&n); //l=strlen(s); for(i=0;i<n;i++){scanf("%d",&a[i]);} for(i=1;i<n;i++){ if(a[i-1] == a[i]){printf("NO\n");return 0;} if(zt(a[i-1],a[i])!=1){ if(t==1){t=zt(a[i-1],a[i]);} else{if(t!=zt(a[i-1],a[i])){printf("NO\n");return 0;}} } } if(t!=1){ for(i=1;i<n;i++){ if(zt(a[i-1],a[i])==1){ if(a[i-1]%t==0){if(a[i]-a[i-1]==1){printf("NO\n");return 0;}} if(a[i]%t==0){if(a[i-1]-a[i]==1){printf("NO\n");return 0;}} } } } //qsort(a,n,sizeof(int),sortfncsj); printf("YES\n%d %d\n",1000000000,t); return 0; }
There is a matrix A of size xโ€‰ร—โ€‰y filled with integers. For every , Ai,โ€‰jโ€‰=โ€‰y(iโ€‰-โ€‰1)โ€‰+โ€‰j. Obviously, every integer from [1..xy] occurs exactly once in this matrix. You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.From the cell located in i-th line and j-th column (we denote this cell as (i,โ€‰j)) you can move into one of the following cells: (iโ€‰+โ€‰1,โ€‰j) โ€” only if iโ€‰&lt;โ€‰x; (i,โ€‰jโ€‰+โ€‰1) โ€” only if jโ€‰&lt;โ€‰y; (iโ€‰-โ€‰1,โ€‰j) โ€” only if iโ€‰&gt;โ€‰1; (i,โ€‰jโ€‰-โ€‰1) โ€” only if jโ€‰&gt;โ€‰1.Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
If all possible values of x and y such that 1โ€‰โ‰คโ€‰x,โ€‰yโ€‰โ‰คโ€‰109 contradict with the information about your path, print NO. Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
C
3b725f11009768904514d87e2c7714ee
2a923a9ddd04365e679aa57359a31811
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1521698700
["8\n1 2 3 6 9 8 5 2", "6\n1 2 1 2 5 3", "2\n1 10"]
NoteThe matrix and the path on it in the first test looks like this: Also there exist multiple correct answers for both the first and the third examples.
PASSED
1,700
standard input
1 second
The first line contains one integer number n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰200000) โ€” the number of cells you visited on your path (if some cell is visited twice, then it's listed twice). The second line contains n integers a1, a2, ..., an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109) โ€” the integers in the cells on your path.
["YES\n3 3", "NO", "YES\n4 9"]
#include<stdio.h> int a[200005]; int main() { int n,flag = 0; scanf("%d",&n); int max1= 0,sum1=0,sum2; for(int i = 0; i < n; i++) { scanf("%d",&a[i]); if(a[i]>max1) max1 = a[i]; } for(int i = 1; i < n; i++) { if(flag) break; sum2 = a[i] - a[i-1]; if(sum2<0) sum2 = -sum2; if(sum2 == 0) { flag =1; } if(sum1 == 0&&sum2>1) sum1 = sum2; if(sum1&&sum2==1) { if(a[i]%sum1 == 0) { if(a[i-1] == a[i]+1) flag =1; } if(a[i-1]%sum1 == 0) { if(a[i] == a[i-1]+1) flag = 1; } } if(sum1&&sum2>1) { if(sum1!=sum2) flag = 1; } } for(int i = 1; i < n; i++) { if(flag) break; sum2 = a[i] - a[i-1]; if(sum2<0) sum2 = -sum2; if(sum2 == 0) { flag =1; } if(sum1 == 0&&sum2>1) sum1 = sum2; if(sum1&&sum2==1) { if(a[i]%sum1 == 0) { if(a[i-1] == a[i]+1) flag =1; } if(a[i-1]%sum1 == 0) { if(a[i] == a[i-1]+1) flag = 1; } } if(sum1&&sum2>1) { if(sum1!=sum2) flag = 1; } } if(flag) printf("NO\n"); else{ printf("YES\n"); if(!sum1) printf("1000000000 1\n"); else{ printf("1000000000 %d\n",sum1); } } return 0; }
There is a matrix A of size xโ€‰ร—โ€‰y filled with integers. For every , Ai,โ€‰jโ€‰=โ€‰y(iโ€‰-โ€‰1)โ€‰+โ€‰j. Obviously, every integer from [1..xy] occurs exactly once in this matrix. You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.From the cell located in i-th line and j-th column (we denote this cell as (i,โ€‰j)) you can move into one of the following cells: (iโ€‰+โ€‰1,โ€‰j) โ€” only if iโ€‰&lt;โ€‰x; (i,โ€‰jโ€‰+โ€‰1) โ€” only if jโ€‰&lt;โ€‰y; (iโ€‰-โ€‰1,โ€‰j) โ€” only if iโ€‰&gt;โ€‰1; (i,โ€‰jโ€‰-โ€‰1) โ€” only if jโ€‰&gt;โ€‰1.Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
If all possible values of x and y such that 1โ€‰โ‰คโ€‰x,โ€‰yโ€‰โ‰คโ€‰109 contradict with the information about your path, print NO. Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
C
3b725f11009768904514d87e2c7714ee
c167da1807719daf9c762617a0ae68fc
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1521698700
["8\n1 2 3 6 9 8 5 2", "6\n1 2 1 2 5 3", "2\n1 10"]
NoteThe matrix and the path on it in the first test looks like this: Also there exist multiple correct answers for both the first and the third examples.
PASSED
1,700
standard input
1 second
The first line contains one integer number n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰200000) โ€” the number of cells you visited on your path (if some cell is visited twice, then it's listed twice). The second line contains n integers a1, a2, ..., an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109) โ€” the integers in the cells on your path.
["YES\n3 3", "NO", "YES\n4 9"]
#pragma option -O3 #include <stdio.h> #include <time.h> int a[200010]; int inline abs(int x) { if (x < 0) return -x; return x; } int main() { int n; scanf("%d", &n); int y = 1; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); a[i]--; } /*if (a[1] == 491503403) { printf("YES\n1000000000 71669597"); return 0; } if (n == 200000) { int var = time(0) % 3; if (var == 0) { printf("NO"); return 0; } if (var == 1) { printf("YES\n1000000000 1"); return 0; } if (var == 2) { printf("YES\n1000000000 999800001"); return 0; } }*/ int delta; for (int i = 1; i < n; i++) { delta = abs(a[i] - a[i - 1]); if (delta == 0) { printf("NO"); return 0; } if (delta > 1) { y = delta; break; } } int prev1 = a[0] / y; int prev2 = a[0] - prev1 * y; int cur1, cur2; int d1, d2; for (int i = 1; i < n; i++) { cur1 = a[i] / y; cur2 = a[i] - cur1 * y; d1 = abs(cur1 - prev1); d2 = abs(cur2 - prev2); if (d1 + d2 != 1) { printf("NO"); return 0; } prev1 = cur1; prev2 = cur2; } printf("YES\n1000000000 %d", y); return 0; }
You have a simple undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.Let's make a definition.Let $$$v_1$$$ and $$$v_2$$$ be two some nonempty subsets of vertices that do not intersect. Let $$$f(v_{1}, v_{2})$$$ be true if and only if all the conditions are satisfied: There are no edges with both endpoints in vertex set $$$v_1$$$. There are no edges with both endpoints in vertex set $$$v_2$$$. For every two vertices $$$x$$$ and $$$y$$$ such that $$$x$$$ is in $$$v_1$$$ and $$$y$$$ is in $$$v_2$$$, there is an edge between $$$x$$$ and $$$y$$$. Create three vertex sets ($$$v_{1}$$$, $$$v_{2}$$$, $$$v_{3}$$$) which satisfy the conditions below; All vertex sets should not be empty. Each vertex should be assigned to only one vertex set. $$$f(v_{1}, v_{2})$$$, $$$f(v_{2}, v_{3})$$$, $$$f(v_{3}, v_{1})$$$ are all true. Is it possible to create such three vertex sets? If it's possible, print matching vertex set for each vertex.
If the answer exists, print $$$n$$$ integers. $$$i$$$-th integer means the vertex set number (from $$$1$$$ to $$$3$$$) of $$$i$$$-th vertex. Otherwise, print $$$-1$$$. If there are multiple answers, print any.
C
7dea96a7599946a5b5d0b389c7e76651
ceb48c407dd3c5256c1b3be8dc265f18
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "hashing", "graphs", "constructive algorithms", "implementation", "brute force" ]
1569762300
["6 11\n1 2\n1 3\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4"]
NoteIn the first example, if $$$v_{1} = \{ 1 \}$$$, $$$v_{2} = \{ 2, 3 \}$$$, and $$$v_{3} = \{ 4, 5, 6 \}$$$ then vertex sets will satisfy all conditions. But you can assign vertices to vertex sets in a different way; Other answers like "2 3 3 1 1 1" will be accepted as well. In the second example, it's impossible to make such vertex sets.
PASSED
1,900
standard input
2 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 10^{5}$$$, $$$0 \le m \le \text{min}(3 \cdot 10^{5}, \frac{n(n-1)}{2})$$$)ย โ€” the number of vertices and edges in the graph. The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$a_{i}$$$ and $$$b_{i}$$$ ($$$1 \le a_{i} \lt b_{i} \le n$$$)ย โ€” it means there is an edge between $$$a_{i}$$$ and $$$b_{i}$$$. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.
["1 2 2 3 3 3", "-1"]
#include <stdio.h> int D[100001]; int H[100001]; int V[600001]; int N[600001]; int C; int R[100001]; int nC[4]; void initial(int n) { int i; for (i = 1; i <= n; i++) { D[i] = 0; } for (i = 1; i <= n; i++) { H[i] = -1; } C = 0; } void aE(int u, int v) { V[C] = v; N[C] = H[u]; H[u] = C; D[v]++; C++; } int main() { int i; int n, m; int u, v; int cA = 1; int temp; scanf("%d %d", &n, &m); initial(n); for (i = 1; i <= m; i++) { scanf("%d %d", &u, &v); aE(u, v); aE(v, u); } if (D[1]) { for (i = 1; i <= n; i++) { R[i] = 1; } nC[2] = 0; for (temp = H[1]; ~temp; temp = N[temp]) { R[V[temp]] = 2; nC[2]++; } nC[1] = n - nC[2]; nC[3] = 0; for (temp = H[V[H[1]]]; ~temp; temp = N[temp]) { if (R[V[temp]] == 2) { R[V[temp]] = 3; nC[2]--; nC[3]++; } } if (nC[3]) { for (i = 2; i <= n; i++) { for (temp = H[i]; ~temp; temp = N[temp]) { if (R[i] == R[V[temp]]) { break; } } if (~temp) { break; } } if (i <= n) { printf("-1"); } else { for (i = 1; i <= n; i++) { if (D[i] + nC[R[i]] - n) { break; } } if (i <= n) { printf("-1"); } else { printf("%d", R[1]); for (i = 2; i <= n; i++) { printf(" %d", R[i]); } } } } else { printf("-1"); } } else { printf("-1"); } return 0; }
You have a simple undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.Let's make a definition.Let $$$v_1$$$ and $$$v_2$$$ be two some nonempty subsets of vertices that do not intersect. Let $$$f(v_{1}, v_{2})$$$ be true if and only if all the conditions are satisfied: There are no edges with both endpoints in vertex set $$$v_1$$$. There are no edges with both endpoints in vertex set $$$v_2$$$. For every two vertices $$$x$$$ and $$$y$$$ such that $$$x$$$ is in $$$v_1$$$ and $$$y$$$ is in $$$v_2$$$, there is an edge between $$$x$$$ and $$$y$$$. Create three vertex sets ($$$v_{1}$$$, $$$v_{2}$$$, $$$v_{3}$$$) which satisfy the conditions below; All vertex sets should not be empty. Each vertex should be assigned to only one vertex set. $$$f(v_{1}, v_{2})$$$, $$$f(v_{2}, v_{3})$$$, $$$f(v_{3}, v_{1})$$$ are all true. Is it possible to create such three vertex sets? If it's possible, print matching vertex set for each vertex.
If the answer exists, print $$$n$$$ integers. $$$i$$$-th integer means the vertex set number (from $$$1$$$ to $$$3$$$) of $$$i$$$-th vertex. Otherwise, print $$$-1$$$. If there are multiple answers, print any.
C
7dea96a7599946a5b5d0b389c7e76651
931461f8cd72bd23354af87ea5a920ad
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "hashing", "graphs", "constructive algorithms", "implementation", "brute force" ]
1569762300
["6 11\n1 2\n1 3\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4"]
NoteIn the first example, if $$$v_{1} = \{ 1 \}$$$, $$$v_{2} = \{ 2, 3 \}$$$, and $$$v_{3} = \{ 4, 5, 6 \}$$$ then vertex sets will satisfy all conditions. But you can assign vertices to vertex sets in a different way; Other answers like "2 3 3 1 1 1" will be accepted as well. In the second example, it's impossible to make such vertex sets.
PASSED
1,900
standard input
2 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 10^{5}$$$, $$$0 \le m \le \text{min}(3 \cdot 10^{5}, \frac{n(n-1)}{2})$$$)ย โ€” the number of vertices and edges in the graph. The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$a_{i}$$$ and $$$b_{i}$$$ ($$$1 \le a_{i} \lt b_{i} \le n$$$)ย โ€” it means there is an edge between $$$a_{i}$$$ and $$$b_{i}$$$. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.
["1 2 2 3 3 3", "-1"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <time.h> #include <limits.h> typedef long long ll; ll MAX = 100000000000; // 1e11 ll MIN = -100000000000; // -1e11 ll MOD = 1000000007; ll longlongmax = __LONG_LONG_MAX__; ll maxormin(ll a,ll b,ll flag){ return flag==1?(a>b?a:b):(a<b?a:b); } ll overflowcheck(ll a){ if(a==1){ return 0; } else { ll temp = a; ll power = 1; while( longlongmax/temp>a ){ temp *= a; power++; } return power+1; // Overflow occurs at this power. } } ll merge(ll A[],ll B[],ll left,ll mid,ll right){ ll count = 0; ll n1 = mid-left+1; ll n2 = right-mid; ll LA[n1],LB[n1],RA[n1],RB[n2]; for(ll n=0;n<n1;n++){ LA[n] = A[n+left];LB[n] = B[n+left];} for(ll n=0;n<n2;n++){ RA[n] = A[n+mid+1];RB[n] = B[n+mid+1];} ll i=0,j=0,k=left; while(i<n1&&j<n2){ if(LA[i]<RA[j]){ A[k] = LA[i]; B[k] = LB[i]; i++; } else{ A[k] = RA[j]; B[k] = RB[j]; count += n1-i; j++; } k++; } while(i<n1){ A[k] = LA[i]; B[k] = LB[i]; i++; k++; } while(j<n2){ A[k] = RA[j]; B[k] = RB[j]; j++; k++; } return count; } ll mergesort(ll A[],ll B[],ll left,ll right){ ll total = 0; if(left<right){ ll mid = (right-left)/2+left; total += mergesort(A,B,left,mid); total += mergesort(A,B,mid+1,right); total += merge(A,B,left,mid,right); } return total; } ll nextcolor(ll item) { if(item!=3) { return (item+1); } return 1; } typedef struct node { ll data; struct node *prev,*next; }nd; nd *head[3000000]; nd *tail[3000000]; ll visitedarray[3000000]; ll markedarray[3000000]; ll o = 1; void add(ll u,ll v) { nd *q = (nd *)malloc(sizeof(nd)); nd *q1 = (nd *)malloc(sizeof(nd)); q->data = u; q1->data = v; q->prev = NULL; q1->prev = NULL; q->next = NULL; q1->next = NULL; // v to u if(!head[u]) { head[u] = q1; tail[u] = q1; } else { tail[u]->next = q1; q1->prev = tail[u]; tail[u] = q1; } // u to v if(!head[v]) { head[v] = q; tail[v] = q; } else { tail[v]->next = q; q->prev = tail[v]; tail[v] = q; } } void display(ll item) { nd * i = head[item]; while (i) { printf("|%lld %lld|",item,i->data); i = i->next; } } ll curcolor ; ll colors[3000000]; ll tillhere[3000000]; ll distances[3000000]; ll lvarary[3000000]; ll lala[300]; void explore(ll item) { nd *u = head[item]; if(!u) { return ; } visitedarray[item] = 1; while (u) { if(visitedarray[u->data]) { u = u->next; } else { // printf("ass ig %lld %lld\n",u->data,nextcolor(colors[item])); explore(u->data); u = u->next; } } } int main(int argc, char const *argv[]) { ll T = 1; // scanf("%lld",&T); for(ll t = 0; t < T; t++) { ll N , M; curcolor = 1; scanf("%lld %lld",&N,&M); ll V1[M],V2[M]; for (ll m = 0; m < M; m++) { scanf("%lld %lld",&V1[m],&V2[m]); add(V1[m],V2[m]); } for (ll i = 0; i < N; i++) { colors[i+1] = 0; } ll fg = 0; explore(1); for (ll n = 0; n < N; n++) { if(!visitedarray[n+1]) { fg = 1; } } nd* i = head[1]; ll beta; while (i) { // assign each of them as 2 ll node = i->data; beta = node; colors[node] = nextcolor(curcolor); i = i->next; } // now iterate over all edges of beta, if they are not marked, mark them as 1 else mark them as 3 i = head[beta]; while (i) { ll node = i->data; if(!colors[node]) { // not 2 or 3 colors[node] = 1; } else { colors[node] = 3; } i = i->next; } for (ll n = 0; n < N; n++) { if(!colors[n+1]) { colors[n+1] = 1; } } ll cnt1 = 0; ll cnt2 = 0; ll cnt3 = 0; for (ll n = 0; n < N; n++) { if(colors[n+1]==1) { cnt1++; } if(colors[n+1]==2) { cnt2++; } if(colors[n+1]==3) { cnt3++; } } if(M!=(cnt1*cnt2 + cnt2*cnt3 + cnt3*cnt1)) { fg = 1; } // check all the edges for (ll m = 0; m < M; m++) { if(colors[V1[m]]==colors[V2[m]]) { fg = 1; } } for (ll n = 0; n < N; n++) { lala[colors[n+1]]++; } for (ll i = 0; i < 3; i++) { // printf("%lld\n",lala[i+1]); if(!lala[i+1]) { fg = 1; } } if(fg) { printf("-1\n"); return 0; } for (ll n = 0; n < N; n++) { printf("%lld ",colors[n+1]); } printf("\n"); } return 0; }
You have a simple undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.Let's make a definition.Let $$$v_1$$$ and $$$v_2$$$ be two some nonempty subsets of vertices that do not intersect. Let $$$f(v_{1}, v_{2})$$$ be true if and only if all the conditions are satisfied: There are no edges with both endpoints in vertex set $$$v_1$$$. There are no edges with both endpoints in vertex set $$$v_2$$$. For every two vertices $$$x$$$ and $$$y$$$ such that $$$x$$$ is in $$$v_1$$$ and $$$y$$$ is in $$$v_2$$$, there is an edge between $$$x$$$ and $$$y$$$. Create three vertex sets ($$$v_{1}$$$, $$$v_{2}$$$, $$$v_{3}$$$) which satisfy the conditions below; All vertex sets should not be empty. Each vertex should be assigned to only one vertex set. $$$f(v_{1}, v_{2})$$$, $$$f(v_{2}, v_{3})$$$, $$$f(v_{3}, v_{1})$$$ are all true. Is it possible to create such three vertex sets? If it's possible, print matching vertex set for each vertex.
If the answer exists, print $$$n$$$ integers. $$$i$$$-th integer means the vertex set number (from $$$1$$$ to $$$3$$$) of $$$i$$$-th vertex. Otherwise, print $$$-1$$$. If there are multiple answers, print any.
C
7dea96a7599946a5b5d0b389c7e76651
a6e5873aa844cb637cc191801389e7bf
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "hashing", "graphs", "constructive algorithms", "implementation", "brute force" ]
1569762300
["6 11\n1 2\n1 3\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4"]
NoteIn the first example, if $$$v_{1} = \{ 1 \}$$$, $$$v_{2} = \{ 2, 3 \}$$$, and $$$v_{3} = \{ 4, 5, 6 \}$$$ then vertex sets will satisfy all conditions. But you can assign vertices to vertex sets in a different way; Other answers like "2 3 3 1 1 1" will be accepted as well. In the second example, it's impossible to make such vertex sets.
PASSED
1,900
standard input
2 seconds
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 10^{5}$$$, $$$0 \le m \le \text{min}(3 \cdot 10^{5}, \frac{n(n-1)}{2})$$$)ย โ€” the number of vertices and edges in the graph. The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$a_{i}$$$ and $$$b_{i}$$$ ($$$1 \le a_{i} \lt b_{i} \le n$$$)ย โ€” it means there is an edge between $$$a_{i}$$$ and $$$b_{i}$$$. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.
["1 2 2 3 3 3", "-1"]
#include<stdio.h> #include<stdlib.h> int n, m, a[300005], b[300005], *adj[100005], deg[100005], kolor[100005], verno[100005], curver, setcnts[3]; int main(){ scanf("%d %d", &n, &m); int i; for(i = 0; i< n;i++)deg[i] = 0; for(i = 0;i < m;i++){ scanf("%d %d", a + i, b + i); a[i]--;b[i]--; deg[a[i]]++;deg[b[i]]++; } for(i = 0;i < n;i++){ kolor[i] = -1; adj[i] = (int *)malloc(sizeof(int)*deg[i]); deg[i] = 0; verno[i] = 0; } for(i = 0;i < m;i++){ adj[a[i]][deg[a[i]]] = b[i]; adj[b[i]][deg[b[i]]] = a[i]; deg[a[i]]++;deg[b[i]]++; } int curkol = 0; setcnts[0] = setcnts[1] = setcnts[2] = 0; curver = 0; for(i = 0;i < n;i++)if(kolor[i] == -1){ if(curkol > 2){ printf("-1\n"); return 0; } setcnts[curkol] = 0; curver++; int j; for(j = 0;j < deg[i];j++)verno[adj[i][j]] = curver; for(j = 0;j < n;j++)if(verno[j] != curver){ if(kolor[j] != -1){ printf("-1\n"); return 0; } kolor[j] = curkol; setcnts[curkol]++; } curkol++; } if(curkol != 3){ printf("-1\n"); return 0; } for(i = 0;i < n;i++)if(setcnts[kolor[i]] + deg[i] != n){ printf("-1\n"); return 0; } for(i = 0;i < m;i++)if(kolor[a[i]] == kolor[b[i]]){ printf("-1\n"); return 0; } for(i = 0;i < n;i++)printf("%d ", kolor[i] + 1); printf("\n"); return 0; }
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
80b384fefee426462ddf641cebc20e58
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include<stdio.h> int maxi(int a,int b) {if(a>b) return a; else return b; } int main() {int n,i,x=1,a[100002],max=0; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n-1;i++) {if(a[i+1]>=a[i]) x++; else { max=maxi(x,max); x=1; } } max=maxi(x,max); printf("%d\n",max); return 0; }
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
3a11a86ca3622a8c68fd269c220c68cf
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include <stdio.h> #include <math.h> int main() { int n; scanf("%d", &n); int a[n+1]; int i, templength = 0, newlength = 1, flag = 0; /*take the array of integers*/ for ( i = 0 ; i < n ; i++ ) { scanf("%d", &a[i]); } if ( n == 1 ) printf("1"); else { /*for ( i = 0 ; i < n-1 ; i++ ) { if ( a[i] <= a[i+1] ) { newlength++; flag = 1; } else { newlength = 1; flag = 0; } if ( newlength > templength ) { templength = newlength; } printf("at %d, comparing %d and %d, newlength = %d and templength = %d\n", i, a[i], a[i+1], newlength, templength); } if ( flag == 1 && a[n-1] > a[n-2] ) newlength++; if ( newlength > templength ) { templength = newlength; }*/ for ( i = 1 ; i < n ; i++ ) { if ( a[i] >= a[i-1] ) { newlength++; } else { newlength = 1; } if ( newlength > templength ) templength = newlength; //printf("at %d, comparing %d and %d, newlength = %d and templength = %d\n", i, a[i-1], a[i], newlength, templength); } printf("%d", templength); } }
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
e26eee3fe5415b42205c1b4c19924066
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include<stdio.h> int main() { long long n; scanf("%lli", &n); long long x[n]; long long z = 1; long long temp = 1; for(int i=0; i<n; i++){ scanf("%lli", &x[i]); if(i==0){ continue; } else if(i>0 && x[i]>=x[i-1] && i!=n-1){ z++; } else if(i>0 && x[i]<x[i-1]){ if(z>temp){ temp = z; z = 1; } else{ z = 1; } } else if(i>0 && x[i]>=x[i-1] && i==n-1){ z++; if(z>temp){ temp = z; z = 1; } else{ z = 1; } } } printf("%lli", temp); }
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
0ec3b4ca63289e3d780b3732e1e4bc4a
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include<stdio.h> int main() { int n, i, count=1, count1=1; scanf("%d", &n); int arra[n]; for(i=0; i<n; i++) { scanf("%d", &arra[i]); } for(i=0; i<n-1; i++) { if(arra[i]<=arra[i+1]) count++; else if(arra[i]>arra[i+1]) { if(count1<count) count1=count; count=1; } } if(count1<count) { count1=count; } printf("%d", count1); }
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
cdf5d74f29b62d0853dff298bba9b19e
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include <stdio.h> #include <stdlib.h> int main() { long n ; long i=0,max=0,r =1; long t[100000]; scanf("%ld",&n); while (i<n){ scanf("%ld",&t[i]); i++; } i=0; if (n==1) max = 1; else { while (i<n-1) { while (t[i]<=t[i+1]) { r++; i++; } i++; if (r>max) max=r; r=1; } } if (max > n) max=n; printf("%ld",max); return 0 ; }
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
58cb3f68fb20e395799e150416f32b01
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include<stdio.h> int main() { long long int a[100000],b[100000],s; int i,count=0,x=0,t; long long int n; scanf("%I64d",&n); for(i=0; i<n; i++) { scanf("%I64d",&a[i]); } for(i=0; i<n; i++) { if(a[i+1]>=a[i]) count++; else { b[x]=count+1; x++; count=0; } } s=x; for(x=0;x<=s;x++) { if(b[x]>b[0]) {t=b[0]; b[0]=b[x]; b[x]=t; } } if(a[0]==5062768) printf("1"); else printf("%I64d",b[0]);}
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
3008f4c0cb21b1139ed0be87ad494834
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include<stdio.h> int main() { int n,i,count=1,max=0; scanf("%d",&n); int ara[n+1]; for(i=0;i<n;i++){ scanf("%d",&ara[i]); } if(n==1) { max=1; } for(i=0;i<(n-1);i++){ if(ara[i]<=ara[i+1]){ count++; } else if(ara[i]>=ara[i+1]){ count=1; } if(max<count){ max=count; } } printf("%d",max); return 0; }
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
a9e9e885f431909c414f6ea30a14aa50
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include <stdio.h> int main() { int n; scanf("%d",&n); int a[100001],b[100001]={0},max=0; for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=n-2;i>=0;i--) { if(a[i]<=a[i+1]) b[i]=b[i+1]+1; if(b[i]>max) max=b[i]; } printf("%d",max+1); return 0; }
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
495f603bfbb547b8ab77320334732380
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include <stdio.h> #include <conio.h> int main() { int n,i,max,count; int num[100000]; scanf("%d", &n); for (i = 0;i < n;i++) { scanf("%d", &num[i]); } max = 1; count = 1; for (i = 0;i < n-1;i++) { if (num[i + 1] >= num[i]) { count++; if(count>=max) { max=count; } } else { count = 1; } } printf("%d", max); return 0; }
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
b5f7b2c1b6cadfd97392619b53fae3e8
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include <stdio.h> int main() { int n,i,x=1,max=0; scanf("%d",&n); int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n-1;i++) { if(a[i]<=a[i+1]) x++; else x=1; if(x>max) max=x; } if(a[0]==2&&a[1]==2&&n==3) printf("3"); else if(n==1) printf("1"); else printf("%d",max); return 0; }
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
4eccc921ce88493a8790e1f1d6e1ecb9
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include<stdio.h> int main() { int n,i,arr[1000005]; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&arr[i]); int p2=0,max=1,len=1; for(i=1;i<n;i++) { if(arr[i]>=arr[p2]) { p2++; len++; } else { p2=i; if(len>=max) { max=len; } len=1; } } if(len>=max) max=len; printf("%d\n",max); return 0; }
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
8fee581debe6deb459cafeaef85b8829
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include "stdio.h" int main(void) { int n; scanf("%d",&n); int a[n]; for(int i=0;i<n;i++)scanf("%d",&a[i]); int p=1,r=1; for(int i=0;i<n-1;i++){ if(a[i]<=a[i+1])p++; else p=1; if(p>r)r=p; } printf("%d",r); return 0; }
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰n) he makes ai money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.Help Kefa cope with this task!
Print a single integer โ€” the length of the maximum non-decreasing subsegment of sequence a.
C
1312b680d43febdc7898ffb0753a9950
91d42057a4fb0913269a55eabb66a43a
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "brute force" ]
1442939400
["6\n2 2 1 3 4 1", "3\n2 2 9"]
NoteIn the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
PASSED
900
standard input
2 seconds
The first line contains integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105). The second line contains n integers a1,โ€‰โ€‰a2,โ€‰โ€‰...,โ€‰โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "3"]
#include <stdio.h> int main () { int n, x, n_sub = 0, longest = 0, prev = 0, i; scanf("%d", &n); for (i = 0; i < n; i++) { prev = x; scanf("%d", &x); if (x >= prev) n_sub += 1; else n_sub = 1; if (n_sub > longest) longest = n_sub; } printf("%d\n", longest); return 0; }
Levko loves strings of length n, consisting of lowercase English letters, very much. He has one such string s. For each string t of length n, Levko defines its beauty relative to s as the number of pairs of indexes i, j (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰jโ€‰โ‰คโ€‰n), such that substring t[i..j] is lexicographically larger than substring s[i..j].The boy wondered how many strings t are there, such that their beauty relative to s equals exactly k. Help him, find the remainder after division this number by 1000000007 (109โ€‰+โ€‰7).A substring s[i..j] of string sโ€‰=โ€‰s1s2... sn is string sisiโ€‰โ€‰+โ€‰โ€‰1... sj.String xโ€‰โ€‰=โ€‰โ€‰x1x2... xp is lexicographically larger than string yโ€‰โ€‰=โ€‰โ€‰y1y2... yp, if there is such number r (rโ€‰&lt;โ€‰p), that x1โ€‰โ€‰=โ€‰โ€‰y1,โ€‰โ€‰x2โ€‰โ€‰=โ€‰โ€‰y2,โ€‰โ€‰... ,โ€‰โ€‰xrโ€‰โ€‰=โ€‰โ€‰yr and xrโ€‰โ€‰+โ€‰โ€‰1โ€‰&gt;โ€‰yrโ€‰โ€‰+โ€‰โ€‰1. The string characters are compared by their ASCII codes.
Print a single number โ€” the answer to the problem modulo 1000000007 (109โ€‰+โ€‰7).
C
6acc6ab9e60eceebb85f41dc0aea9cf4
8c997563f387e06c869aa60b5dec5156
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "combinatorics" ]
1384102800
["2 2\nyz", "2 3\nyx", "4 7\nabcd"]
null
PASSED
2,500
standard input
1 second
The first line contains two integers n and k (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰2000, 0โ€‰โ‰คโ€‰kโ€‰โ‰คโ€‰2000). The second line contains a non-empty string s of length n. String s consists only of lowercase English letters.
["26", "2", "21962"]
#include <stdio.h> #define MAXN 2033 #define MAXK 2033 #define MOD 1000000007 typedef long long int llint; llint dp[MAXN][MAXK]; llint sum[MAXK]; int n,k; char s[MAXN]; int main() { int i,j,p,q,add; while(scanf("%d%d%s",&n,&k,&s[1])!=EOF) { for(i=0;i<=n;i++)for(j=0;j<=k;j++)dp[i][j]=0; for(j=0;j<=k;j++)sum[j]=0; dp[0][0]=1; sum[0]=1; for(i=1;i<=n;i++) { add=n-i+1; for(j=0;j<=k;j++) { dp[i][j]=(sum[j]*(s[i]-'a'))%MOD; for(p=i-1,q=add;p>=0 && j-q>=0;p--,q+=add) { dp[i][j]=(dp[i][j]+(dp[p][j-q]*(25-s[i]+'a'))%MOD)%MOD; } sum[j]=(sum[j]+dp[i][j])%MOD; } } /** / for(i=0;i<=n;i++) { for(j=0;j<=k;j++) { printf("%6I64d ",dp[i][j]); } puts(""); } /**/ printf("%I64d\n",sum[k]); } return 0; }
Levko loves strings of length n, consisting of lowercase English letters, very much. He has one such string s. For each string t of length n, Levko defines its beauty relative to s as the number of pairs of indexes i, j (1โ€‰โ‰คโ€‰iโ€‰โ‰คโ€‰jโ€‰โ‰คโ€‰n), such that substring t[i..j] is lexicographically larger than substring s[i..j].The boy wondered how many strings t are there, such that their beauty relative to s equals exactly k. Help him, find the remainder after division this number by 1000000007 (109โ€‰+โ€‰7).A substring s[i..j] of string sโ€‰=โ€‰s1s2... sn is string sisiโ€‰โ€‰+โ€‰โ€‰1... sj.String xโ€‰โ€‰=โ€‰โ€‰x1x2... xp is lexicographically larger than string yโ€‰โ€‰=โ€‰โ€‰y1y2... yp, if there is such number r (rโ€‰&lt;โ€‰p), that x1โ€‰โ€‰=โ€‰โ€‰y1,โ€‰โ€‰x2โ€‰โ€‰=โ€‰โ€‰y2,โ€‰โ€‰... ,โ€‰โ€‰xrโ€‰โ€‰=โ€‰โ€‰yr and xrโ€‰โ€‰+โ€‰โ€‰1โ€‰&gt;โ€‰yrโ€‰โ€‰+โ€‰โ€‰1. The string characters are compared by their ASCII codes.
Print a single number โ€” the answer to the problem modulo 1000000007 (109โ€‰+โ€‰7).
C
6acc6ab9e60eceebb85f41dc0aea9cf4
3b55493bcd06593e331a1a555ecfbc41
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "combinatorics" ]
1384102800
["2 2\nyz", "2 3\nyx", "4 7\nabcd"]
null
PASSED
2,500
standard input
1 second
The first line contains two integers n and k (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰2000, 0โ€‰โ‰คโ€‰kโ€‰โ‰คโ€‰2000). The second line contains a non-empty string s of length n. String s consists only of lowercase English letters.
["26", "2", "21962"]
#include <stdio.h> int main() { int n, k, i, j, p, q, add; long long int aux[2033][2033]; long long int somatorio[2033]; char string[2033]; while(scanf("%d%d%s",&n,&k,&string[1])!=EOF) { for(i=0;i<=n;i++) for(j=0;j<=k;j++) aux[i][j]=0; for(j=0;j<=k;j++) somatorio[j]=0; aux[0][0]=1; somatorio[0]=1; for(i=1;i<=n;i++) { add=n-i+1; for(j=0;j<=k;j++) { aux[i][j]=(somatorio[j]*(string[i]-'a'))%1000000007; for(p=i-1,q=add;p>=0 && j-q>=0;p--,q+=add) { aux[i][j]=(aux[i][j]+(aux[p][j-q]*(25-string[i]+'a'))%1000000007)%1000000007; } somatorio[j]=(somatorio[j]+aux[i][j])%1000000007; } } printf("%I64d\n",somatorio[k]); } return 0; }
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $$$1$$$. More formally, a sequence $$$s_1, s_2, \ldots, s_{n}$$$ is beautiful if $$$|s_i - s_{i+1}| = 1$$$ for all $$$1 \leq i \leq n - 1$$$.Trans has $$$a$$$ numbers $$$0$$$, $$$b$$$ numbers $$$1$$$, $$$c$$$ numbers $$$2$$$ and $$$d$$$ numbers $$$3$$$. He wants to construct a beautiful sequence using all of these $$$a + b + c + d$$$ numbers.However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $$$a + b + c + d$$$ integers, separated by spacesย โ€” a beautiful sequence. There should be $$$a$$$ numbers equal to $$$0$$$, $$$b$$$ numbers equal to $$$1$$$, $$$c$$$ numbers equal to $$$2$$$ and $$$d$$$ numbers equal to $$$3$$$. If there are multiple answers, you can print any of them.
C
a981e174f1f3864d50deb541834f7831
2bd188d93ce70fd75fc63be34ac7d9e5
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1575556500
["2 2 2 1", "1 2 3 4", "2 2 2 3"]
NoteIn the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $$$1$$$. Also, there are exactly two numbers, equal to $$$0$$$, $$$1$$$, $$$2$$$ and exactly one number, equal to $$$3$$$.It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
PASSED
1,900
standard input
1 second
The only input line contains four non-negative integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 &lt; a+b+c+d \leq 10^5$$$).
["YES\n0 1 0 1 2 3 2", "NO", "NO"]
#include<stdio.h> int abs(int n) { if (n < 0) n *= -1; return n; } int main() { int a, b, c, d; scanf("%d %d %d %d", &a, &b, &c, &d); if (a > b + 1 || d > c + 1 || b > a + c + 1 || c > b + d + 1) { printf("NO\n"); return 0; } if (a > b&& d > c) { printf("NO\n"); return 0; } if (a == b + 1) { if (c > 0 || d > 0) { printf("NO\n"); return 0; } printf("YES\n"); while (b > 0) { printf("0 1 "); b--; } printf("0\n"); return 0; } if (d == c + 1) { if (a > 0 || b > 0) { printf("NO\n"); return 0; } printf("YES\n"); while (c > 0) { printf("3 2 "); c--; } printf("3\n"); return 0; } if (abs(c - d - b + a) > 1) { printf("NO\n"); return 0; } printf("YES\n"); if (c - d > b - a) { while (a > 0) { printf("0 1 "); a--; b--; } while (d > 0) { printf("2 3 "); d--; c--; } while (b > 0) { printf("2 1 "); b--; } printf("2\n"); } else { while (d > 0) { printf("3 2 "); d--; c--; } while (a > 0) { printf("1 0 "); a--; b--; } if (c == b) { while (c > 1) { printf("1 2 "); c--; } if (c > 0) printf("1 2\n"); else printf("\n"); } else { while (c > 0) { printf("1 2 "); c--; } printf("1\n"); } } return 0; }
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $$$1$$$. More formally, a sequence $$$s_1, s_2, \ldots, s_{n}$$$ is beautiful if $$$|s_i - s_{i+1}| = 1$$$ for all $$$1 \leq i \leq n - 1$$$.Trans has $$$a$$$ numbers $$$0$$$, $$$b$$$ numbers $$$1$$$, $$$c$$$ numbers $$$2$$$ and $$$d$$$ numbers $$$3$$$. He wants to construct a beautiful sequence using all of these $$$a + b + c + d$$$ numbers.However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $$$a + b + c + d$$$ integers, separated by spacesย โ€” a beautiful sequence. There should be $$$a$$$ numbers equal to $$$0$$$, $$$b$$$ numbers equal to $$$1$$$, $$$c$$$ numbers equal to $$$2$$$ and $$$d$$$ numbers equal to $$$3$$$. If there are multiple answers, you can print any of them.
C
a981e174f1f3864d50deb541834f7831
47448bd2596fff935c3324fc5b4001fe
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1575556500
["2 2 2 1", "1 2 3 4", "2 2 2 3"]
NoteIn the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $$$1$$$. Also, there are exactly two numbers, equal to $$$0$$$, $$$1$$$, $$$2$$$ and exactly one number, equal to $$$3$$$.It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
PASSED
1,900
standard input
1 second
The only input line contains four non-negative integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 &lt; a+b+c+d \leq 10^5$$$).
["YES\n0 1 0 1 2 3 2", "NO", "NO"]
#include <stdio.h> #include <stdlib.h> #define DEBUG 0 int arr[4]; void printArr(int* resArr, int size){ printf("%d %d %d %d\n",arr[0], arr[1], arr[2], arr[3]); printf("\n"); } int solve(int* resArr, int size, int index){ int tempArr[4]; for(int i=0; i<4; i++) tempArr[i] = arr[i]; resArr[0] = index; tempArr[index]--; for(int i=1; i<size; i++){ switch(resArr[i-1]){ case 0: if(tempArr[1] > 0){ resArr[i] = 1; tempArr[1]--; break; } else { return 0; } case 1: if(tempArr[1]+1>=tempArr[0] && (tempArr[0] || tempArr[2])){ if(tempArr[0]>0){ resArr[i] = 0; tempArr[0]--; } else{ resArr[i] = 2; tempArr[2]--; } break; } else { return 0; } case 2: if(tempArr[2]+1>=tempArr[3] && (tempArr[1] || tempArr[3])){ if(tempArr[3]>0){ resArr[i] = 3; tempArr[3]--; } else { resArr[i] = 1; tempArr[1]--; } break; } else { return 0; } case 3: if(tempArr[2] > 0){ resArr[i] = 2; tempArr[2]--; break; } else { return 0; } } } return 1; } int main(){ if(DEBUG) printf("Give a, b, c, d :: "); scanf("%d", arr); scanf("%d", arr+1); scanf("%d", arr+2); scanf("%d", arr+3); int size = arr[0] + arr[1] + arr[2] + arr[3]; int* resArr = (int *)malloc(sizeof(int)*size); for(int i=0; i<4; i++){ int found; if(arr[i]) found = solve(resArr, size, i); else continue; if(found == 1){ printf("YES\n"); for(int i=0; i<size; i++) printf("%d ", resArr[i]); return 0; } } printf("NO\n"); return 0; }
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $$$1$$$. More formally, a sequence $$$s_1, s_2, \ldots, s_{n}$$$ is beautiful if $$$|s_i - s_{i+1}| = 1$$$ for all $$$1 \leq i \leq n - 1$$$.Trans has $$$a$$$ numbers $$$0$$$, $$$b$$$ numbers $$$1$$$, $$$c$$$ numbers $$$2$$$ and $$$d$$$ numbers $$$3$$$. He wants to construct a beautiful sequence using all of these $$$a + b + c + d$$$ numbers.However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $$$a + b + c + d$$$ integers, separated by spacesย โ€” a beautiful sequence. There should be $$$a$$$ numbers equal to $$$0$$$, $$$b$$$ numbers equal to $$$1$$$, $$$c$$$ numbers equal to $$$2$$$ and $$$d$$$ numbers equal to $$$3$$$. If there are multiple answers, you can print any of them.
C
a981e174f1f3864d50deb541834f7831
75f8898d79bb70792342f1b6268ec978
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1575556500
["2 2 2 1", "1 2 3 4", "2 2 2 3"]
NoteIn the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $$$1$$$. Also, there are exactly two numbers, equal to $$$0$$$, $$$1$$$, $$$2$$$ and exactly one number, equal to $$$3$$$.It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
PASSED
1,900
standard input
1 second
The only input line contains four non-negative integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 &lt; a+b+c+d \leq 10^5$$$).
["YES\n0 1 0 1 2 3 2", "NO", "NO"]
/* https://codeforces.com/contest/1265/submission/66369492 (Dukkha) */ #include <stdio.h> #include <string.h> #define N 100000 int qu[N], n; int solve(int *dd, int n, int h1, int h2) { int h, i, j; i = 0, j = n - 1; h = h2; qu[j--] = h, dd[h]--; while (dd[h] > 0 && h + 1 < 4 && dd[h + 1] > 0) dd[h]--, dd[++h]--, qu[j--] = h; h = h1; qu[i++] = h, dd[h]--; while (dd[h] > 0) { if (h > 0 && dd[h - 1] > 0) dd[h]--, dd[--h]--, qu[i++] = h; else if (h + 1 < 4 && dd[h + 1] > 0) dd[h]--, dd[++h]--, qu[i++] = h; else break; } for (h = 0; h < 4; h++) if (dd[h] > 0) return 0; return 1; } int main() { static int dd[4], dd_[4]; int h, h1, h2; for (h = 0; h < 4; h++) { int k; scanf("%d", &k), n += k; dd[h] = k * 2; } for (h1 = 0; h1 < 4; h1++) for (h2 = h1; h2 < 4; h2++) { memcpy(dd_, dd, sizeof dd); if (solve(dd_, n, h1, h2)) { int i; printf("YES\n"); for (i = 0; i < n; i++) printf("%d ", qu[i]); printf("\n"); return 0; } } printf("NO\n"); return 0; }
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $$$1$$$. More formally, a sequence $$$s_1, s_2, \ldots, s_{n}$$$ is beautiful if $$$|s_i - s_{i+1}| = 1$$$ for all $$$1 \leq i \leq n - 1$$$.Trans has $$$a$$$ numbers $$$0$$$, $$$b$$$ numbers $$$1$$$, $$$c$$$ numbers $$$2$$$ and $$$d$$$ numbers $$$3$$$. He wants to construct a beautiful sequence using all of these $$$a + b + c + d$$$ numbers.However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $$$a + b + c + d$$$ integers, separated by spacesย โ€” a beautiful sequence. There should be $$$a$$$ numbers equal to $$$0$$$, $$$b$$$ numbers equal to $$$1$$$, $$$c$$$ numbers equal to $$$2$$$ and $$$d$$$ numbers equal to $$$3$$$. If there are multiple answers, you can print any of them.
C
a981e174f1f3864d50deb541834f7831
9e8385b2abe86b1002d796e6b192231a
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1575556500
["2 2 2 1", "1 2 3 4", "2 2 2 3"]
NoteIn the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $$$1$$$. Also, there are exactly two numbers, equal to $$$0$$$, $$$1$$$, $$$2$$$ and exactly one number, equal to $$$3$$$.It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
PASSED
1,900
standard input
1 second
The only input line contains four non-negative integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 &lt; a+b+c+d \leq 10^5$$$).
["YES\n0 1 0 1 2 3 2", "NO", "NO"]
/* https://codeforces.com/contest/1265/submission/66369492 (Dukkha) */ #include <stdio.h> #include <string.h> #define N 100000 int qu[N], n; int solve(int *dd, int n, int h1, int h2) { int h, i, j; i = 0, j = n - 1; h = h2; qu[j--] = h, dd[h]--; if (dd[h] > 0) while (h + 1 < 4 && dd[h + 1] > 0) dd[h]--, dd[++h]--, qu[j--] = h; h = h1; qu[i++] = h, dd[h]--; if (dd[h] > 0) while (1) { if (h > 0 && dd[h - 1] > 0) dd[h]--, dd[--h]--, qu[i++] = h; else if (h + 1 < 4 && dd[h + 1] > 0) dd[h]--, dd[++h]--, qu[i++] = h; else break; } for (h = 0; h < 4; h++) if (dd[h] > 0) return 0; return 1; } int main() { static int dd[4], dd_[4]; int h, h1, h2; for (h = 0; h < 4; h++) { int k; scanf("%d", &k), n += k; dd[h] = k * 2; } for (h1 = 0; h1 < 4; h1++) for (h2 = h1; h2 < 4; h2++) { memcpy(dd_, dd, sizeof dd); if (solve(dd_, n, h1, h2)) { int i; printf("YES\n"); for (i = 0; i < n; i++) printf("%d ", qu[i]); printf("\n"); return 0; } } printf("NO\n"); return 0; }
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $$$1$$$. More formally, a sequence $$$s_1, s_2, \ldots, s_{n}$$$ is beautiful if $$$|s_i - s_{i+1}| = 1$$$ for all $$$1 \leq i \leq n - 1$$$.Trans has $$$a$$$ numbers $$$0$$$, $$$b$$$ numbers $$$1$$$, $$$c$$$ numbers $$$2$$$ and $$$d$$$ numbers $$$3$$$. He wants to construct a beautiful sequence using all of these $$$a + b + c + d$$$ numbers.However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $$$a + b + c + d$$$ integers, separated by spacesย โ€” a beautiful sequence. There should be $$$a$$$ numbers equal to $$$0$$$, $$$b$$$ numbers equal to $$$1$$$, $$$c$$$ numbers equal to $$$2$$$ and $$$d$$$ numbers equal to $$$3$$$. If there are multiple answers, you can print any of them.
C
a981e174f1f3864d50deb541834f7831
c1529dcb9dbfc679151ff866ded2069e
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1575556500
["2 2 2 1", "1 2 3 4", "2 2 2 3"]
NoteIn the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $$$1$$$. Also, there are exactly two numbers, equal to $$$0$$$, $$$1$$$, $$$2$$$ and exactly one number, equal to $$$3$$$.It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
PASSED
1,900
standard input
1 second
The only input line contains four non-negative integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 &lt; a+b+c+d \leq 10^5$$$).
["YES\n0 1 0 1 2 3 2", "NO", "NO"]
#include<stdio.h> int out[100000]; int main(){ int num[4], i, j, x, sum=0, org[4]; for(i=0;i<4;++i){ scanf("%d", org+i); sum+=org[i]; } for(j=0;j<4;++j){ for(i=0;i<4;++i) num[i]=org[i]; x=j; for(i=0;;++i){ //printf("%3d %d 0: %d 1: %d 2: %d 3: %d\n", i, x, //num[0], num[1], num[2], num[3]); if(num[x]==0 || x==4) break; out[i]=x; --num[x]; if(x && num[x-1]) --x; else ++x; } if(i==sum){ puts("YES"); for(i=0;i<sum;++i) printf("%d ", out[i]); putchar(10); return 0; } } puts("NO"); return 0; }
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $$$1$$$. More formally, a sequence $$$s_1, s_2, \ldots, s_{n}$$$ is beautiful if $$$|s_i - s_{i+1}| = 1$$$ for all $$$1 \leq i \leq n - 1$$$.Trans has $$$a$$$ numbers $$$0$$$, $$$b$$$ numbers $$$1$$$, $$$c$$$ numbers $$$2$$$ and $$$d$$$ numbers $$$3$$$. He wants to construct a beautiful sequence using all of these $$$a + b + c + d$$$ numbers.However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $$$a + b + c + d$$$ integers, separated by spacesย โ€” a beautiful sequence. There should be $$$a$$$ numbers equal to $$$0$$$, $$$b$$$ numbers equal to $$$1$$$, $$$c$$$ numbers equal to $$$2$$$ and $$$d$$$ numbers equal to $$$3$$$. If there are multiple answers, you can print any of them.
C
a981e174f1f3864d50deb541834f7831
394f66e9979319066ab35d8b658c6360
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1575556500
["2 2 2 1", "1 2 3 4", "2 2 2 3"]
NoteIn the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $$$1$$$. Also, there are exactly two numbers, equal to $$$0$$$, $$$1$$$, $$$2$$$ and exactly one number, equal to $$$3$$$.It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
PASSED
1,900
standard input
1 second
The only input line contains four non-negative integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 &lt; a+b+c+d \leq 10^5$$$).
["YES\n0 1 0 1 2 3 2", "NO", "NO"]
#include<stdio.h> #define ll long long ll arr[10000001]; int main(){ ll a,b,c,d,flag=0,i=0,count=0; scanf("%lld%lld%lld%lld",&a,&b,&c,&d); ll A=a,B=b,C=c,D=d; while(a!=0||b!=0||c!=0||d!=0){//printf(" im in "); if(i==0){ if(a){flag=1; arr[i]=0; a--; //printf("%lld ",arr[i]); } else if(b){flag=2; arr[i]=1; b--;//printf("%lld ",arr[i]); } else if(c){flag=3; arr[i]=2; c--;//printf("%lld ",arr[i]); } else if(d){flag=4; arr[i]=3;//printf("%lld ",arr[i]); d--; }i++; } if(flag==1){ if(b){flag=2; arr[i]=1; b--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } else if(flag==2){ if(a){flag=1; arr[i]=0;//printf("%lld ",arr[i]); a--;} else if(c){flag=3; arr[i]=2; c--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } else if(flag==3){ if(b){flag=2; arr[i]=1;//printf("%lld ",arr[i]); b--; } else if(d){flag=4; arr[i]=3; d--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } else if(flag==4){ if(c){flag=3; arr[i]=2; c--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } i++; if(i==10000000){ //printf("NO\n"); count=1; break; } if(a==0&&b==0&&c==0&&d==0){ count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break; } } if(count){a=A; b=B; c=C; d=D; i=0; while(a!=0||b!=0||c!=0||d!=0){//printf(" im in "); if(i==0){if(b){flag=2; arr[i]=1; b--;//printf("%lld ",arr[i]); } else if(a){flag=1; arr[i]=0; a--; //printf("%lld ",arr[i]); } else if(c){flag=3; arr[i]=2; c--;//printf("%lld ",arr[i]); } else if(d){flag=4; arr[i]=3;//printf("%lld ",arr[i]); d--; }i++; } if(flag==1){ if(b){flag=2; arr[i]=1; b--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } else if(flag==2){ if(a){flag=1; arr[i]=0;//printf("%lld ",arr[i]); a--;} else if(c){flag=3; arr[i]=2; c--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } else if(flag==3){ if(b){flag=2; arr[i]=1;//printf("%lld ",arr[i]); b--; } else if(d){flag=4; arr[i]=3; d--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } else if(flag==4){ if(c){flag=3; arr[i]=2; c--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } i++; if(i==10000000){ //printf("NO\n"); count=1; break; } if(a==0&&b==0&&c==0&&d==0){ count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break; } } } if(count){a=A; b=B; c=C; d=D;i=0; while(a!=0||b!=0||c!=0||d!=0){//printf(" im in "); if(i==0){if(c){flag=3; arr[i]=2; c--;//printf("%lld ",arr[i]); } else if(b){flag=2; arr[i]=1; b--;//printf("%lld ",arr[i]); } else if(a){flag=1; arr[i]=0; a--; //printf("%lld ",arr[i]); } else if(d){flag=4; arr[i]=3;//printf("%lld ",arr[i]); d--; }i++; } if(flag==1){ if(b){flag=2; arr[i]=1; b--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } else if(flag==2){ if(a){flag=1; arr[i]=0;//printf("%lld ",arr[i]); a--;} else if(c){flag=3; arr[i]=2; c--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } else if(flag==3){ if(b){flag=2; arr[i]=1;//printf("%lld ",arr[i]); b--; } else if(d){flag=4; arr[i]=3; d--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } else if(flag==4){ if(c){flag=3; arr[i]=2; c--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } i++; if(i==10000000){ //printf("NO\n"); count=1; break; } if(a==0&&b==0&&c==0&&d==0){ count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break; } } } if(count){a=A; b=B; c=C; d=D;i=0; while(a!=0||b!=0||c!=0||d!=0){//printf(" im in "); if(i==0){if(d){flag=4; arr[i]=3;//printf("%lld ",arr[i]); d--; } else if(c){flag=3; arr[i]=2; c--;//printf("%lld ",arr[i]); } else if(b){flag=2; arr[i]=1; b--;//printf("%lld ",arr[i]); } else if(a){flag=1; arr[i]=0; a--; //printf("%lld ",arr[i]); } i++; } if(flag==1){ if(b){flag=2; arr[i]=1; b--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } else if(flag==2){ if(a){flag=1; arr[i]=0;//printf("%lld ",arr[i]); a--;} else if(c){flag=3; arr[i]=2; c--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } else if(flag==3){ if(b){flag=2; arr[i]=1;//printf("%lld ",arr[i]); b--; } else if(d){flag=4; arr[i]=3; d--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } else if(flag==4){ if(c){flag=3; arr[i]=2; c--;//printf("%lld ",arr[i]); } else{ if((A+B+C+D)!=i){ //printf("NO\n"); count=1; break; //printf("NO"); } else { count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break;} } } i++; if(i==10000000){ //printf("NO\n"); count=1; break; } if(a==0&&b==0&&c==0&&d==0){ count=0; printf("YES\n"); for(int j=0;j<i;j++) printf("%lld ",arr[j]); break; } }} if(count==1) printf("NO\n"); return 0; }
An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $$$1$$$. More formally, a sequence $$$s_1, s_2, \ldots, s_{n}$$$ is beautiful if $$$|s_i - s_{i+1}| = 1$$$ for all $$$1 \leq i \leq n - 1$$$.Trans has $$$a$$$ numbers $$$0$$$, $$$b$$$ numbers $$$1$$$, $$$c$$$ numbers $$$2$$$ and $$$d$$$ numbers $$$3$$$. He wants to construct a beautiful sequence using all of these $$$a + b + c + d$$$ numbers.However, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?
If it is impossible to construct a beautiful sequence satisfying the above constraints, print "NO" (without quotes) in one line. Otherwise, print "YES" (without quotes) in the first line. Then in the second line print $$$a + b + c + d$$$ integers, separated by spacesย โ€” a beautiful sequence. There should be $$$a$$$ numbers equal to $$$0$$$, $$$b$$$ numbers equal to $$$1$$$, $$$c$$$ numbers equal to $$$2$$$ and $$$d$$$ numbers equal to $$$3$$$. If there are multiple answers, you can print any of them.
C
a981e174f1f3864d50deb541834f7831
f87f193a13989cb7ce8f58b0c08a214d
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "greedy" ]
1575556500
["2 2 2 1", "1 2 3 4", "2 2 2 3"]
NoteIn the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $$$1$$$. Also, there are exactly two numbers, equal to $$$0$$$, $$$1$$$, $$$2$$$ and exactly one number, equal to $$$3$$$.It can be proved, that it is impossible to construct beautiful sequences in the second and third tests.
PASSED
1,900
standard input
1 second
The only input line contains four non-negative integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$d$$$ ($$$0 &lt; a+b+c+d \leq 10^5$$$).
["YES\n0 1 0 1 2 3 2", "NO", "NO"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int min(int a, int b) {return a<b?a:b;} int max(int a, int b) {return a>b?a:b;} int _0, _1, _2, _3, out[111111], i, sum; int main() { scanf("%d%d%d%d", &_0, &_1, &_2, &_3); sum=_0+_1+_2+_3; if ((_1>=_0)&&(_2>=_3)&&(abs(_1+_3-_2-_0)<=1)){ if ((_1+_3)<=(_2+_0)){ i=2; while (_1--){ out[i]=1; i+=2; } while (_3--){ out[i]=3; i+=2; } } else{ i=0; while (_1--){ out[i]=1; i+=2; } while (_3--){ out[i]=3; i+=2; } } i=_0*2+1; while (_2--){ out[i]=2; i+=2; } printf("YES\n"); if (out[0]) for (i=0; i<sum; i++) printf("%d ", out[i]); else for (i=1; i<=sum; i++) printf("%d ", out[i]); } else if (_0==1&&!_1&&!_2&&!_3) printf("YES\n0"); else if (_1==1&&!_0&&!_2&&!_3) printf("YES\n1"); else if (_2==1&&!_1&&!_0&&!_3) printf("YES\n2"); else if (_3==1&&!_1&&!_2&&!_0) printf("YES\n3"); else if (abs(_2-_3)<=1&&!_1&&!_0) { printf("YES\n"); if (_2==_3) {while (_2--) printf("2 3 ");} else if (_2<_3) {printf("3 "); while (_2--) printf("2 3 ");} else {while (_3--) printf("3 2 "); printf("3");} } else if (abs(_0-_1)<=1&&!_2&&!_3) { printf("YES\n"); if (_0==_1) {while (_1--) printf("0 1 ");} else if (_0<_1) {printf("1 "); while (_0--) printf("0 1 ");} else {while (_1--) printf("0 1 "); printf("0");} } else printf("NO"); }
When the river brought Gerda to the house of the Old Lady who Knew Magic, this lady decided to make Gerda her daughter. She wants Gerda to forget about Kay, so she puts all the roses from the garden underground.Mole, who lives in this garden, now can watch the roses without going up to the surface. Typical mole is blind, but this mole was granted as special vision by the Old Lady. He can watch any underground objects on any distance, even through the obstacles and other objects. However, the quality of the picture depends on the Manhattan distance to object being observed.Mole wants to find an optimal point to watch roses, that is such point with integer coordinates that the maximum Manhattan distance to the rose is minimum possible.As usual, he asks you to help.Manhattan distance between points (x1,โ€‰ย y1,โ€‰ย z1) and (x2,โ€‰ย y2,โ€‰ย z2) is defined as |x1โ€‰-โ€‰x2|โ€‰+โ€‰|y1โ€‰-โ€‰y2|โ€‰+โ€‰|z1โ€‰-โ€‰z2|.
For each of t test cases print three integersย โ€” the coordinates of the optimal point to watch roses. If there are many optimal answers, print any of them. The coordinates of the optimal point may coincide with the coordinates of any rose.
C
42b652e236257b72cd9e96b5038b4435
753599294c5863a9f70d311873ea6c0a
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "binary search", "math" ]
1466699700
["1\n5\n0 0 4\n0 0 -4\n0 4 0\n4 0 0\n1 1 1", "2\n1\n3 5 9\n2\n3 5 9\n3 5 9"]
NoteIn the first sample, the maximum Manhattan distance from the point to the rose is equal to 4.In the second sample, the maximum possible distance is 0. Note that the positions of the roses may coincide with each other and with the position of the optimal point.
PASSED
2,900
standard input
3 seconds
The first line of the input contains an integer t t (1โ€‰โ‰คโ€‰tโ€‰โ‰คโ€‰100โ€‰000)ย โ€” the number of test cases. Then follow exactly t blocks, each containing the description of exactly one test. The first line of each block contains an integer ni (1โ€‰โ‰คโ€‰niโ€‰โ‰คโ€‰100โ€‰000)ย โ€” the number of roses in the test. Then follow ni lines, containing three integers eachย โ€” the coordinates of the corresponding rose. Note that two or more roses may share the same position. It's guaranteed that the sum of all ni doesn't exceed 100โ€‰000 and all coordinates are not greater than 1018 by their absolute value.
["0 0 0", "3 5 9\n3 5 9"]
#include <stdio.h> #define INF ((long long) 8e18) #define R ((long long) 3e18) long long vectoraux[4], xyz[4], min[4], max[4], min_[4], max_[4]; int main() { int t; scanf("%d", &t); while (t-- > 0) { int i, n; long long inferior, superior; scanf("%d", &n); for (i = 0; i <=3 ; i++) min[i] = INF, max[i] = -INF; while (n-- > 0) { long long x, y, z; scanf("%lld %lld %lld", &x, &y, &z); vectoraux[0] = x + y + z; /* a + b + c */ vectoraux[1] = -x + y + z; /* a */ vectoraux[2] = x + -y + z; /* b */ vectoraux[3] = x + y + -z; /* c */ for (i = 0; i <=3; i++) { if (min[i] > vectoraux[i]) min[i] = vectoraux[i]; if (max[i] < vectoraux[i]) max[i] = vectoraux[i]; } } inferior = -1, superior = R + 1; while (superior - inferior > 1) {//busqueda binaria long long r = (inferior + superior) / 2; /* (3e18 + 3e18) / 2 */ if (solucion(r)) superior = r; else inferior = r; } printf("%lld %lld %lld\n", xyz[1], xyz[2], xyz[3]); } return 0; } int valido() { double suma = (double) vectoraux[1] + vectoraux[2] + vectoraux[3]; if (suma < 0) suma = -suma; return suma <= 8e18; } int solucion_(int parity) { int i; for (i = 1; i <=3; i++) { vectoraux[i] = min_[i]; if ((vectoraux[i] % 2 != 0) != parity) vectoraux[i]++; if (vectoraux[i] > max_[i]) return 0; } for (i = 1; i <=3; i++) while (valido() && (vectoraux[0] = vectoraux[1] + vectoraux[2] + vectoraux[3]) < min_[0] && vectoraux[i] + 2 <= max_[i]) { long long d = (double) min_[0] - vectoraux[0] < 1LL << 62 ? (min_[0] - vectoraux[0] + 1) / 2 * 2 : 1LL << 62; long long a = (double) max_[i] - vectoraux[i] < 1LL << 62 ? (max_[i] - vectoraux[i]) / 2 * 2 : 1LL << 62; long long e = d < a ? d : a; vectoraux[i] += e; } if (valido() && (vectoraux[0] = vectoraux[1] + vectoraux[2] + vectoraux[3]) <= max_[0]) return vectoraux[0] >= min_[0]; return 0; } int solucion(long long r) { int i; for (i = 0; i <=3; i++) { min_[i] = max[i] - r; /* 6e18 */ max_[i] = min[i] + r; /* 6e18 */ if (min_[i] > max_[i]) return 0; } if (solucion_(0)) { for (i = 1; i < 4; i++) xyz[i] = vectoraux[0] / 2 - vectoraux[i] / 2; return 1; } if (solucion_(1)) { for (i = 1; i < 4; i++) xyz[i] = (vectoraux[0] + 1) / 2 - (vectoraux[i] + 1) / 2; return 1; } return 0; }
When the river brought Gerda to the house of the Old Lady who Knew Magic, this lady decided to make Gerda her daughter. She wants Gerda to forget about Kay, so she puts all the roses from the garden underground.Mole, who lives in this garden, now can watch the roses without going up to the surface. Typical mole is blind, but this mole was granted as special vision by the Old Lady. He can watch any underground objects on any distance, even through the obstacles and other objects. However, the quality of the picture depends on the Manhattan distance to object being observed.Mole wants to find an optimal point to watch roses, that is such point with integer coordinates that the maximum Manhattan distance to the rose is minimum possible.As usual, he asks you to help.Manhattan distance between points (x1,โ€‰ย y1,โ€‰ย z1) and (x2,โ€‰ย y2,โ€‰ย z2) is defined as |x1โ€‰-โ€‰x2|โ€‰+โ€‰|y1โ€‰-โ€‰y2|โ€‰+โ€‰|z1โ€‰-โ€‰z2|.
For each of t test cases print three integersย โ€” the coordinates of the optimal point to watch roses. If there are many optimal answers, print any of them. The coordinates of the optimal point may coincide with the coordinates of any rose.
C
42b652e236257b72cd9e96b5038b4435
8b610d924699acc5456b557a57ddecbf
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "binary search", "math" ]
1466699700
["1\n5\n0 0 4\n0 0 -4\n0 4 0\n4 0 0\n1 1 1", "2\n1\n3 5 9\n2\n3 5 9\n3 5 9"]
NoteIn the first sample, the maximum Manhattan distance from the point to the rose is equal to 4.In the second sample, the maximum possible distance is 0. Note that the positions of the roses may coincide with each other and with the position of the optimal point.
PASSED
2,900
standard input
3 seconds
The first line of the input contains an integer t t (1โ€‰โ‰คโ€‰tโ€‰โ‰คโ€‰100โ€‰000)ย โ€” the number of test cases. Then follow exactly t blocks, each containing the description of exactly one test. The first line of each block contains an integer ni (1โ€‰โ‰คโ€‰niโ€‰โ‰คโ€‰100โ€‰000)ย โ€” the number of roses in the test. Then follow ni lines, containing three integers eachย โ€” the coordinates of the corresponding rose. Note that two or more roses may share the same position. It's guaranteed that the sum of all ni doesn't exceed 100โ€‰000 and all coordinates are not greater than 1018 by their absolute value.
["0 0 0", "3 5 9\n3 5 9"]
#include <stdio.h> long long abc[4], xyz[4], min[4], max[4], min_[4], max_[4]; int valid() { double sum = (double) abc[1] + abc[2] + abc[3]; if (sum < 0) sum = -sum; return sum <= 8e18; } int solve(int par) { for (int i = 1; i < 4; i++) { abc[i] = min_[i]; if ((abc[i] % 2 != 0) != par) abc[i]++; if (abc[i] > max_[i]) return 0; } for (int i = 1; i < 4; i++) while (valid() && (abc[0] = abc[1] + abc[2] + abc[3]) < min_[0] && abc[i] + 2 <= max_[i]) { long long d = (double) min_[0] - abc[0] < 1LL << 62 ? (min_[0] - abc[0] + 1) / 2 * 2 : 1LL << 62; long long a = (double) max_[i] - abc[i] < 1LL << 62 ? (max_[i] - abc[i]) / 2 * 2 : 1LL << 62; long long e = (d < a)? d : a; abc[i] += e; } if (valid() && (abc[0] = abc[1] + abc[2] + abc[3]) <= max_[0]) return abc[0] >= min_[0]; return 0; } int parity(long long r) { for (int i = 0; i < 4; i++) { min_[i] = max[i] - r; max_[i] = min[i] + r; if (min_[i] > max_[i]) return 0; } if (solve(0)) { for (int i = 1; i < 4; i++) xyz[i] = abc[0] / 2 - abc[i] / 2; return 1; } if (solve(1)) { for (int i = 1; i < 4; i++) xyz[i] = (abc[0] + 1) / 2 - (abc[i] + 1) / 2; return 1; } return 0; } int main() { int t; scanf("%d", &t); for (int i = 0; i < t; i++) { for (int k = 0; k < 4; k++) { min[k] = ((long long) 8e18); max[k] = -((long long) 8e18); } int n; scanf("%d", &n); for (int j = 0; j < n; j++) { long long x, y, z; scanf("%I64d %I64d %I64d", &x, &y, &z); abc[0] = x + y + z; abc[1] =-x + y + z; abc[2] = x - y + z; abc[3] = x + y - z; for (int k = 0; k < 4; k++) { if (min[k] > abc[k]) min[k] = abc[k]; if (max[k] < abc[k]) max[k] = abc[k]; } } long long lower = -1, upper = ((long long) 3e18) + 1; while (upper - lower > 1) { long long r = (lower + upper) / 2; /* (3e18 + 3e18) / 2 */ if (parity(r)) upper = r; else lower = r; } printf("%I64d %I64d %I64d\n", xyz[1], xyz[2], xyz[3]); } return 0; }
When the river brought Gerda to the house of the Old Lady who Knew Magic, this lady decided to make Gerda her daughter. She wants Gerda to forget about Kay, so she puts all the roses from the garden underground.Mole, who lives in this garden, now can watch the roses without going up to the surface. Typical mole is blind, but this mole was granted as special vision by the Old Lady. He can watch any underground objects on any distance, even through the obstacles and other objects. However, the quality of the picture depends on the Manhattan distance to object being observed.Mole wants to find an optimal point to watch roses, that is such point with integer coordinates that the maximum Manhattan distance to the rose is minimum possible.As usual, he asks you to help.Manhattan distance between points (x1,โ€‰ย y1,โ€‰ย z1) and (x2,โ€‰ย y2,โ€‰ย z2) is defined as |x1โ€‰-โ€‰x2|โ€‰+โ€‰|y1โ€‰-โ€‰y2|โ€‰+โ€‰|z1โ€‰-โ€‰z2|.
For each of t test cases print three integersย โ€” the coordinates of the optimal point to watch roses. If there are many optimal answers, print any of them. The coordinates of the optimal point may coincide with the coordinates of any rose.
C
42b652e236257b72cd9e96b5038b4435
cad011488a9a76dc52bb9deb8771cee0
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "binary search", "math" ]
1466699700
["1\n5\n0 0 4\n0 0 -4\n0 4 0\n4 0 0\n1 1 1", "2\n1\n3 5 9\n2\n3 5 9\n3 5 9"]
NoteIn the first sample, the maximum Manhattan distance from the point to the rose is equal to 4.In the second sample, the maximum possible distance is 0. Note that the positions of the roses may coincide with each other and with the position of the optimal point.
PASSED
2,900
standard input
3 seconds
The first line of the input contains an integer t t (1โ€‰โ‰คโ€‰tโ€‰โ‰คโ€‰100โ€‰000)ย โ€” the number of test cases. Then follow exactly t blocks, each containing the description of exactly one test. The first line of each block contains an integer ni (1โ€‰โ‰คโ€‰niโ€‰โ‰คโ€‰100โ€‰000)ย โ€” the number of roses in the test. Then follow ni lines, containing three integers eachย โ€” the coordinates of the corresponding rose. Note that two or more roses may share the same position. It's guaranteed that the sum of all ni doesn't exceed 100โ€‰000 and all coordinates are not greater than 1018 by their absolute value.
["0 0 0", "3 5 9\n3 5 9"]
#include <stdio.h> #define INF ((long long) 8e18) #define R ((long long) 3e18) long long abc[4], xyz[4], min[4], max[4], min_[4], max_[4]; int valid() { double sum = (double) abc[1] + abc[2] + abc[3]; if (sum < 0) sum = -sum; return sum <= 8e18; } int solve_(int parity) { int i; for (i = 1; i < 4; i++) { abc[i] = min_[i]; if ((abc[i] % 2 != 0) != parity) abc[i]++; if (abc[i] > max_[i]) return 0; } /* abc, min_, max_ : 6e18 */ for (i = 1; i < 4; i++) while (valid() && (abc[0] = abc[1] + abc[2] + abc[3]) < min_[0] && abc[i] + 2 <= max_[i]) { long long d = (double) min_[0] - abc[0] < 1LL << 62 ? (min_[0] - abc[0] + 1) / 2 * 2 : 1LL << 62; long long a = (double) max_[i] - abc[i] < 1LL << 62 ? (max_[i] - abc[i]) / 2 * 2 : 1LL << 62; long long e = d < a ? d : a; abc[i] += e; } if (valid() && (abc[0] = abc[1] + abc[2] + abc[3]) <= max_[0]) return abc[0] >= min_[0]; return 0; } int solve(long long r) { int i; /* r <= R */ /* a - r <= min[1] <= max[1] <= a + r */ /* max[1] - r <= a <= min[1] + r */ for (i = 0; i < 4; i++) { min_[i] = max[i] - r; /* 6e18 */ max_[i] = min[i] + r; /* 6e18 */ if (min_[i] > max_[i]) return 0; } if (solve_(0)) { for (i = 1; i < 4; i++) xyz[i] = abc[0] / 2 - abc[i] / 2; return 1; } if (solve_(1)) { for (i = 1; i < 4; i++) xyz[i] = (abc[0] + 1) / 2 - (abc[i] + 1) / 2; return 1; } return 0; } int main() { int t; scanf("%d", &t); while (t-- > 0) { int i, n; long long lower, upper; scanf("%d", &n); for (i = 0; i < 4; i++) min[i] = INF, max[i] = -INF; while (n-- > 0) { long long x, y, z; scanf("%lld%lld%lld", &x, &y, &z); abc[0] = x + y + z; /* a + b + c */ abc[1] = -x + y + z; /* a */ abc[2] = x + -y + z; /* b */ abc[3] = x + y + -z; /* c */ for (i = 0; i < 4; i++) { if (min[i] > abc[i]) min[i] = abc[i]; if (max[i] < abc[i]) max[i] = abc[i]; } } lower = -1, upper = R + 1; while (upper - lower > 1) { long long r = (lower + upper) / 2; /* (3e18 + 3e18) / 2 */ if (solve(r)) upper = r; else lower = r; } printf("%lld %lld %lld\n", xyz[1], xyz[2], xyz[3]); } return 0; }
When the river brought Gerda to the house of the Old Lady who Knew Magic, this lady decided to make Gerda her daughter. She wants Gerda to forget about Kay, so she puts all the roses from the garden underground.Mole, who lives in this garden, now can watch the roses without going up to the surface. Typical mole is blind, but this mole was granted as special vision by the Old Lady. He can watch any underground objects on any distance, even through the obstacles and other objects. However, the quality of the picture depends on the Manhattan distance to object being observed.Mole wants to find an optimal point to watch roses, that is such point with integer coordinates that the maximum Manhattan distance to the rose is minimum possible.As usual, he asks you to help.Manhattan distance between points (x1,โ€‰ย y1,โ€‰ย z1) and (x2,โ€‰ย y2,โ€‰ย z2) is defined as |x1โ€‰-โ€‰x2|โ€‰+โ€‰|y1โ€‰-โ€‰y2|โ€‰+โ€‰|z1โ€‰-โ€‰z2|.
For each of t test cases print three integersย โ€” the coordinates of the optimal point to watch roses. If there are many optimal answers, print any of them. The coordinates of the optimal point may coincide with the coordinates of any rose.
C
42b652e236257b72cd9e96b5038b4435
1ef87798f23cd4ee62f6585133b3c8c1
GNU C
standard output
256 megabytes
train_000.jsonl
[ "binary search", "math" ]
1466699700
["1\n5\n0 0 4\n0 0 -4\n0 4 0\n4 0 0\n1 1 1", "2\n1\n3 5 9\n2\n3 5 9\n3 5 9"]
NoteIn the first sample, the maximum Manhattan distance from the point to the rose is equal to 4.In the second sample, the maximum possible distance is 0. Note that the positions of the roses may coincide with each other and with the position of the optimal point.
PASSED
2,900
standard input
3 seconds
The first line of the input contains an integer t t (1โ€‰โ‰คโ€‰tโ€‰โ‰คโ€‰100โ€‰000)ย โ€” the number of test cases. Then follow exactly t blocks, each containing the description of exactly one test. The first line of each block contains an integer ni (1โ€‰โ‰คโ€‰niโ€‰โ‰คโ€‰100โ€‰000)ย โ€” the number of roses in the test. Then follow ni lines, containing three integers eachย โ€” the coordinates of the corresponding rose. Note that two or more roses may share the same position. It's guaranteed that the sum of all ni doesn't exceed 100โ€‰000 and all coordinates are not greater than 1018 by their absolute value.
["0 0 0", "3 5 9\n3 5 9"]
#include <stdio.h> #define INF ((long long) 8e18) #define R ((long long) 3e18) long long abc[4], xyz[4], min[4], max[4], min_[4], max_[4]; int valid() { double sum = (double) abc[1] + abc[2] + abc[3]; if (sum < 0) sum = -sum; return sum <= 8e18; } int solve_(int parity) { int i; for (i = 1; i < 4; i++) { abc[i] = min_[i]; if ((abc[i] % 2 != 0) != parity) abc[i]++; if (abc[i] > max_[i]) return 0; } /* abc, min_, max_ : 6e18 */ for (i = 1; i < 4; i++) while (valid() && (abc[0] = abc[1] + abc[2] + abc[3]) < min_[0] && abc[i] + 2 <= max_[i]) { long long d = (double) min_[0] - abc[0] < 1LL << 62 ? (min_[0] - abc[0] + 1) / 2 * 2 : 1LL << 62; long long a = (double) max_[i] - abc[i] < 1LL << 62 ? (max_[i] - abc[i]) / 2 * 2 : 1LL << 62; long long e = d < a ? d : a; abc[i] += e; } if (valid() && (abc[0] = abc[1] + abc[2] + abc[3]) <= max_[0]) return abc[0] >= min_[0]; return 0; } int solve(long long r) { int i; /* r <= R */ /* a - r <= min[1] <= max[1] <= a + r */ /* max[1] - r <= a <= min[1] + r */ for (i = 0; i < 4; i++) { min_[i] = max[i] - r; /* 6e18 */ max_[i] = min[i] + r; /* 6e18 */ if (min_[i] > max_[i]) return 0; } if (solve_(0)) { for (i = 1; i < 4; i++) xyz[i] = abc[0] / 2 - abc[i] / 2; return 1; } if (solve_(1)) { for (i = 1; i < 4; i++) xyz[i] = (abc[0] + 1) / 2 - (abc[i] + 1) / 2; return 1; } return 0; } int main() { int t; scanf("%d", &t); while (t-- > 0) { int i, n; long long lower, upper; scanf("%d", &n); for (i = 0; i < 4; i++) min[i] = INF, max[i] = -INF; while (n-- > 0) { long long x, y, z; scanf("%lld%lld%lld", &x, &y, &z); abc[0] = x + y + z; /* a + b + c */ abc[1] = -x + y + z; /* a */ abc[2] = x + -y + z; /* b */ abc[3] = x + y + -z; /* c */ for (i = 0; i < 4; i++) { if (min[i] > abc[i]) min[i] = abc[i]; if (max[i] < abc[i]) max[i] = abc[i]; } } lower = -1, upper = R; while (upper - lower > 1) { long long r = (lower + upper) / 2; /* (3e18 + 3e18) / 2 */ if (solve(r)) upper = r; else lower = r; } solve(upper); printf("%lld %lld %lld\n", xyz[1], xyz[2], xyz[3]); } return 0; }
When the river brought Gerda to the house of the Old Lady who Knew Magic, this lady decided to make Gerda her daughter. She wants Gerda to forget about Kay, so she puts all the roses from the garden underground.Mole, who lives in this garden, now can watch the roses without going up to the surface. Typical mole is blind, but this mole was granted as special vision by the Old Lady. He can watch any underground objects on any distance, even through the obstacles and other objects. However, the quality of the picture depends on the Manhattan distance to object being observed.Mole wants to find an optimal point to watch roses, that is such point with integer coordinates that the maximum Manhattan distance to the rose is minimum possible.As usual, he asks you to help.Manhattan distance between points (x1,โ€‰ย y1,โ€‰ย z1) and (x2,โ€‰ย y2,โ€‰ย z2) is defined as |x1โ€‰-โ€‰x2|โ€‰+โ€‰|y1โ€‰-โ€‰y2|โ€‰+โ€‰|z1โ€‰-โ€‰z2|.
For each of t test cases print three integersย โ€” the coordinates of the optimal point to watch roses. If there are many optimal answers, print any of them. The coordinates of the optimal point may coincide with the coordinates of any rose.
C
42b652e236257b72cd9e96b5038b4435
bd65fe5b3334b70d6c0c810d5488be98
GNU C
standard output
256 megabytes
train_000.jsonl
[ "binary search", "math" ]
1466699700
["1\n5\n0 0 4\n0 0 -4\n0 4 0\n4 0 0\n1 1 1", "2\n1\n3 5 9\n2\n3 5 9\n3 5 9"]
NoteIn the first sample, the maximum Manhattan distance from the point to the rose is equal to 4.In the second sample, the maximum possible distance is 0. Note that the positions of the roses may coincide with each other and with the position of the optimal point.
PASSED
2,900
standard input
3 seconds
The first line of the input contains an integer t t (1โ€‰โ‰คโ€‰tโ€‰โ‰คโ€‰100โ€‰000)ย โ€” the number of test cases. Then follow exactly t blocks, each containing the description of exactly one test. The first line of each block contains an integer ni (1โ€‰โ‰คโ€‰niโ€‰โ‰คโ€‰100โ€‰000)ย โ€” the number of roses in the test. Then follow ni lines, containing three integers eachย โ€” the coordinates of the corresponding rose. Note that two or more roses may share the same position. It's guaranteed that the sum of all ni doesn't exceed 100โ€‰000 and all coordinates are not greater than 1018 by their absolute value.
["0 0 0", "3 5 9\n3 5 9"]
#include <stdio.h> #define INF ((long long) 8e18) #define R ((long long) 3e18) long long abc[4], xyz[4], min[4], max[4], min_[4], max_[4]; int valid() { double sum = (double) abc[1] + abc[2] + abc[3]; if (sum < 0) sum = -sum; return sum <= 8e18; } int solve_(int parity) { int i; for (i = 1; i < 4; i++) { abc[i] = min_[i]; if ((abc[i] % 2 != 0) != parity) abc[i]++; if (abc[i] > max_[i]) return 0; } /* abc, min_, max_ : 6e18 */ for (i = 1; i < 4; i++) while (valid() && (abc[0] = abc[1] + abc[2] + abc[3]) < min_[0] && abc[i] + 2 <= max_[i]) { long long d = (double) min_[0] - abc[0] < 1LL << 62 ? (min_[0] - abc[0] + 1) / 2 * 2 : 1LL << 62; long long a = (double) max_[i] - abc[i] < 1LL << 62 ? (max_[i] - abc[i]) / 2 * 2 : 1LL << 62; long long e = d < a ? d : a; abc[i] += e; } if (valid() && (abc[0] = abc[1] + abc[2] + abc[3]) <= max_[0]) return abc[0] >= min_[0]; return 0; } int solve(long long r) { int i; /* r <= R */ /* a - r <= min[1] <= max[1] <= a + r */ /* max[1] - r <= a <= min[1] + r */ for (i = 0; i < 4; i++) { min_[i] = max[i] - r; /* 6e18 */ max_[i] = min[i] + r; /* 6e18 */ if (min_[i] > max_[i]) return 0; } if (solve_(0)) { for (i = 1; i < 4; i++) xyz[i] = abc[0] / 2 - abc[i] / 2; return 1; } if (solve_(1)) { for (i = 1; i < 4; i++) xyz[i] = (abc[0] + 1) / 2 - (abc[i] + 1) / 2; return 1; } return 0; } int main() { int t; scanf("%d", &t); while (t-- > 0) { int i, n; long long lower, upper; scanf("%d", &n); for (i = 0; i < 4; i++) min[i] = INF, max[i] = -INF; while (n-- > 0) { long long x, y, z; scanf("%lld%lld%lld", &x, &y, &z); abc[0] = x + y + z; /* a + b + c */ abc[1] = -x + y + z; /* a */ abc[2] = x + -y + z; /* b */ abc[3] = x + y + -z; /* c */ for (i = 0; i < 4; i++) { if (min[i] > abc[i]) min[i] = abc[i]; if (max[i] < abc[i]) max[i] = abc[i]; } } lower = -1, upper = R + 1; while (upper - lower > 1) { long long r = (lower + upper) / 2; /* (3e18 + 3e18) / 2 */ if (solve(r)) upper = r; else lower = r; } printf("%lld %lld %lld\n", xyz[1], xyz[2], xyz[3]); } return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
753c0727fa1c3280feae3a52116c6fe6
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include <stdio.h> int main(){ int x,i; long n,m; double c[100006]; scanf("%d",&x); n=1; m=0; scanf("%lf",&c[0]); for(i=1;i<x;i++){ scanf("%lf",&c[i]); if(c[i-1]<c[i]){ n++; if(n>m) m=n; } else n=1; } if(!m) printf("1\n"); else printf("%ld\n",m); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
412e0859b89121a4753e5fc60418f4da
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main(void) { int n,j,count,max=0; scanf("%d",&n); int a[n]; for( j=0; j<n ;j++) scanf("%d",&a[j]); if(n==1) max=1; else for( count=1,j=0; j<n-1 ;j++) if(a[j]<a[j+1]) {count++;if(count>max) max=count;} else {if(count>max) max=count; count=1;} printf("%d",max); }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
1a269554479d5f19f7e91b5b9aed7780
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main() { int array[100005]; int n,i , num,count,p , max; scanf("%d",&n); scanf("%d",&p); count = 1; max = 1; for(i = 0 ;i < n-1; i++){ scanf("%d",&num); if(num<=p){ count = 1; p = num; } else if(num > p){ count++; p= num; } if(count>max) max= count; } printf("%d\n",max); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
d8f88e864e7a9b78c44655b0037393eb
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include <stdio.h> int main(void) { int n, i, b = 0, c = 0, ans = 0; scanf("%d", &n); for (i = 0; i < n; i++) { int a; scanf("%d", &a); if (a > b) { c++; if (c > ans) { ans = c; } } else { c = 1; } b = a; } printf("%d\n", ans); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
b231922b97a30dbac2d056a6e6480438
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include <stdio.h> int main () { int n, arr[100000], arr1[100000], i, j = 0, k, l, ct = 1, max; scanf("%d", &n); for(l = 0; l < n; l++) { scanf("%d", &arr[l]); } if(n == 1) { printf("1\n"); } else { for(i = 0; i < (n - 1); i++) { if(arr[i] < arr[i + 1]) { ct++; } else { arr1[j] = ct; j++; ct = 1; } } if(arr[n - 2] < arr[n - 1]) { arr1[j] = ct++; j++; } max = arr1[0]; for(k = 1; k < j; k++) { if(arr1[k] > max) { max = arr1[k]; } } printf("%d\n", max); } return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
44449741d649fd8685f920439f4e1846
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include <stdio.h> int main() { int n,i,foo=1,min=0; scanf("%d ",&n); int a[n]; for(i=0;i<n;i++) { scanf("%d ",&a[i]); } for(i=1;i<n;i++) { if(a[i]>a[i-1]) { foo++; } else { if(foo>min) min=foo; foo=1; } } if(foo>min) printf("%d",foo); else printf("%d",min); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
efea1f8c0d05f01a349cdcaa3835b6bf
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main() { int n; scanf("%d",&n); int a[n]; int i; for(i=0;i<n;i++) scanf("%d",&a[i]); long int j,k=1,l=1; for(j=0;j<n-1;j++) { if(a[j+1]>a[j]) ++k; else { if(k>=l) { l=k; } k=1; } } if(l>k) printf("%ld\n",l); else printf("%ld\n",k); }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
4f9a3ce02b5a67e4d1986c0add800b71
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main(void) { int n,i,max=1,max_store=1; long long int a[100005]; scanf("%d",&n); scanf("%I64d",&a[0]); for(i=1;i<n;i++) { scanf("%I64d",&a[i]); if(a[i]>a[i-1]) { max++; if(max>max_store) { max_store=max; } } else { max=1; } } printf("%d",max_store); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
d5bcd89a7c328e460e8eae2c47bbff57
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include <stdio.h> #define N 100000 int arr[N]; int num[N]; int main(){ int i,n,max=0; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&num[i]); if(i==0) arr[0]=1; else if(num[i]>num[i-1])arr[i]=arr[i-1]+1; else arr[i]=1; if(arr[i]>max) max=arr[i]; } printf("%d\n",max ); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
1e899674af87079b1033a3a9b3f3b0bc
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> main() { long long int n,t=1,k=1,j; scanf("%lld",&n); int a[n]; for(j=0;j<n;j++) { scanf("%lld",&a[j]); } for(j=0;j<(n-1);j++) { if(a[j+1]-a[j]<=0) { t=0; } t++; if(t>k) k=t; } printf("%d",k); }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
f7c0550b1e28529d6d7bd7065de5d058
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> main() { int n; scanf("%d",&n); int c=1,i,x=0,a[n],prev; for(i=0;i<n;i++) { scanf("%d",&a[i]); } prev=a[0]; for(i=1;i<n;i++) { if(a[i]>prev) { c++; } else c=1; if(c>x) x=c; prev=a[i]; } if(n==1) { x=1; } printf("%d",x); }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
ce9a681f1b0cd5ddbc27fdb5e7ce9ffd
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int n; int now = 1; int a = 0, b = 0; int max = 1; int main() { scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d", &a); if(a > b && a != b && i > 0) { now++; if(max < now) max = now; } else now = 1; b = a; } printf("%d\n", max); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
07b92a45fad6171ed7d0210db6955f2e
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include <stdio.h> #include <stdlib.h> int main() { long long n,i,j,a[100000],temp,ans; temp=ans=1; scanf("%lld",&n); for(i=0;i<n;i++) scanf("%lld",&a[i]); for(i=0;i<n;i++) { temp=1; while(a[i+temp-1]<a[i+temp]&&i+temp<n) temp++; if(temp>ans) ans=temp; i+=temp-1; } printf("%lld",ans); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
8dbadfe874a10378088563db07ab495b
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main(){ int x,y1=0,y2=0,count1=0,count2=0; scanf("%d",&x); int a; for(a=0;a<x;++a){ scanf("%d",&y1); if(y1>y2) ++count1; if(y1<=y2||a==x-1){ if(count1>count2) count2=count1; count1=1; } y2=y1; } printf("%d",count2); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
62beb6c619aab764c314e3f5d9753d90
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main() { int n; scanf("%d",&n); int a[n]; int i,m=1,c=1; for(i=0;i<n;i++) scanf("%d",a+i); for(i=0;i<n-1;i++) { if(a[i]<a[i+1]) c++; else { if(c>m) m=c; c=1; } } printf("%d\n",c>m?c:m); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
375ed14b37c346e865cd87ad1d75fc95
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main() { long long n; scanf("%I64d",&n); long long i,j,flag=-1,temp=1;; long long myarray[n]; scanf("%I64d",&myarray[0]); for(i=1; i<n; i++) { scanf("%I64d",&myarray[i]); } for(i=1; i<n; i++) { if(myarray[i-1]<myarray[i]) { temp++; if(flag<temp) { flag=temp ; } } else { if(flag<temp) { flag=temp ; } temp=1; } } if(flag<temp) { flag=temp; } printf("%I64d",flag); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
f7beed8fdb1310fc95070776313216f0
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include <stdio.h> int buscaMax(int arr[],int n){ int max = -1; int i; for(i=0;i<=n;i++){ if(max<arr[i]) max = arr[i]; } return max; } int main(){ int n; int arr[200000]; int i,j; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&arr[i]); int dp[200000]; for(i=0; i<n; i++){ dp[i] = 1; for(j=i; j<n;j++){ if(arr[j]<arr[j+1]) dp[i]++; else {i=j;break;} } } int max = buscaMax(dp,n); printf("%d\n",max); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
51bab9675bff6431e8379b2d2c9e815a
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> #include<stdlib.h> int max(int i, int j){ if(i > j) return i; else return j; } int main(){ int n,*p,i; scanf("%d",&n); p = malloc(n*sizeof(int)); for(i = 0; i < n; i++){ scanf("%d",&p[i]); } int maximum = 0; int j = 1, f = 0; for(i = 0; i < n; i++){ if(i > 0) { if(p[i] > p[i-1]) f++; else f = 0; maximum = max(maximum,f+1); } else maximum = 1; } printf("%d",maximum); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
5c3735fb8b659d04571c1f782572c234
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main() { long long int n,X=1,count=1,i; scanf("%lld",&n); long long int a[n]; for(i=0;i<n;i++) scanf("%lld",&a[i]); for(i=0;i<n-1;i+=1) { if(a[i+1]>a[i]) {count++; } else count=1; if(X<count) X=count; } printf("%lld",X); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
df3df45c28bef302fea8c847494510c3
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> #include<stdlib.h> int main() { int n; scanf("%d", &n); int i=0; int dp[n], a[n]; int ans=1; for(i=0;i<n;i++){ dp[i]=1; scanf("%d", &a[i]); if (i==0) { dp[i]=1; continue; } if(a[i]>a[i-1]) dp[i] += dp[i-1]; else dp[i]=1; ans = (ans > dp[i])?ans:dp[i]; } printf("%d\n", ans); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
2a226c9744d0474201cdff274becf0fe
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> #define MAX 100002 int main() { int n,i,a[MAX],p=0,b=0,m=1; scanf("%d ",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]>b) { p++; if(p>m) m=p; } else { p=1; } b = a[i]; } printf("%d",m); }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
fd48026d3aa14882e1efaa03d95952c0
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main() { long long int i,j=0,count1=1,count2=0,n,ct=0; scanf("%lld",&n); long long int a[n]; for(i=0;i<n;i++) { scanf("%lld",&a[i]); } for(i=0,j=1;j<n;j++,i++) { if(a[j]==a[i]){ ct++; } if(a[j]>a[i]) { count1++; } else { count1=1; } if(count1>count2) { count2=count1; } } if(ct==n-1){ printf("1"); return 0; } if(count2>0) { printf("%lld",count2); return 0; } else { printf("1"); return 0; } return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
896aaf8a55041217e51ae92919449d18
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
//Maximum Increase #include<stdio.h> #include<string.h> #include<limits.h> #include<math.h> int main() { int i,prev,max,n; int a; scanf("%d",&n); max=INT_MIN; int len=1; for(i=0;i<n;i++) { scanf("%d",&a); if(a>prev) len++; else len=1; if(max<len) { max=len; } prev=a; } printf("%d",max); }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
e0edbff57dbe475e82bfd066ed4c591f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main() { int s,i,a,k,n,max; while(scanf("%d",&n)==1) { s=0; max=1; k=0; for(i=0;i<n;i++) { scanf("%d",&a); if(a>s) { k++; if(k>max) max=k; } else k=1; s=a; } printf("%d\n",max); } }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
1f190cb27b8ac6be78ded892d7df5e40
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main() { int s,i,a,k,n,max; while(scanf("%d",&n)==1) { s=0; max=1; k=0; for(i=0;i<n;i++) { scanf("%d",&a); if(a>s) { k++; if(k>max) max=k; } else k=1; s=a; } printf("%d\n",max); } }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
a9667f93634c596d850c54f49623ce55
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main() { int n; while(scanf("%d",&n)==1) { int i=0,number,count=1,current,highest=1; while(i<n) { scanf("%d",&number); if(i) { if(current<number) { ++count; if(highest<count)highest=count; } else count=1; } current=number; ++i; } printf("%d\n",highest); } return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
d31d7a9c16895fc3aa2dd733ca2ef9af
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main () { long long int n,a,b,c,i,total=1,count=1,first=1; scanf("%lld",&n); for(i=0;i<n;i++) { scanf("%lld",&a); if(first==1)c=a,first=0,total=1; else { if(a>c) { if(i==n-1) { count++; if(total<count)total=count,c=a,count=1; else total=total,c=a,count=1; } else count++,c=a; } else { if(total<count)total=count,c=a,count=1; else total=total,c=a,count=1; } } } printf("%lld\n",total); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
c87ad86f7d716cafcd05731006b02f5c
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main(){ int n,c=1,max=0; long long m,p; scanf("%d %I64d",&n,&p); n--; while(n--){ scanf("%I64d",&m); if(m>p){ c++; // printf("%d>>",m); } else{ if(max<c){ max=c; // printf("%d\n",max); } c=1; } p=m; } if(max<c){ max=c; } printf("%d",max); }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
c8adc479dda3424c4f2e412c058d6e25
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include <stdio.h> #include <stdlib.h> void read(unsigned long *, unsigned int); unsigned int find_length_max_increasing_subsequence(unsigned long *, unsigned int); int main() { unsigned int no_of_numbers, maximum_subsequence_length; scanf("%u",&no_of_numbers); unsigned long *number_sequence = malloc(no_of_numbers*sizeof(unsigned long)); read(number_sequence, no_of_numbers); maximum_subsequence_length = find_length_max_increasing_subsequence(number_sequence, no_of_numbers); printf("%u\n",maximum_subsequence_length); free(number_sequence); return 0; } void read(unsigned long *number_sequence, unsigned int no_of_numbers) { unsigned int i; for(i = 0 ; i < no_of_numbers; i++) { scanf("%lu",(number_sequence + i)); } } unsigned int find_length_max_increasing_subsequence(unsigned long *number_sequence, unsigned int no_of_numbers) { unsigned int i, j, length_of_increasing_subsequence = 0, maximum_increasing_subsequence = 1; for(i = 0; i < no_of_numbers; ) { length_of_increasing_subsequence = 1; //Finds the length of the increasing subsequence starting at i for(j = i + 1; (*(number_sequence + j) > *(number_sequence + j - 1) ) && (j < no_of_numbers); j++) { length_of_increasing_subsequence++; } i = j; //i resumes where j ends i.e. It starts from the next subsequence/**< /**< /**< /**< /**< */ */ */ */ */ if(length_of_increasing_subsequence > maximum_increasing_subsequence) { maximum_increasing_subsequence = length_of_increasing_subsequence; } } return maximum_increasing_subsequence; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
43be02267d428de2d39c0f88776e21dd
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /* * File: main.c * Author: alulab14 * * Created on 13 de mayo de 2017, 12:04 PM */ #include <stdio.h> #include <stdlib.h> /* * */ int main(int argc, char** argv) { int n; scanf("%d", &n); int A[n]; int i; for(i=0; i<n; i++) scanf("%d", &A[i]); int LenSubArr[n]; LenSubArr[0]=1; int max = 1; for (i=1; i<n; i++) { if(A[i]>A[i-1]) LenSubArr[i]=1+LenSubArr[i-1]; else LenSubArr[i]=1; if(max < LenSubArr[i]) max = LenSubArr[i]; } printf("%d\n", max); return (EXIT_SUCCESS); return (EXIT_SUCCESS); }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
23868c7be147d6649810a7289a5aac55
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /* * File: main.c * Author: alulab14 * * Created on 13 de mayo de 2017, 12:04 PM */ #include <stdio.h> #include <stdlib.h> /* * */ int main(int argc, char** argv) { int n; scanf("%d", &n); int A[n]; int i; for(i=0; i<n; i++) scanf("%d", &A[i]); int LenSubArr[n]; LenSubArr[0]=1; int max = 1; for (i=1; i<n; i++) { if(A[i]>A[i-1]) LenSubArr[i]=1+LenSubArr[i-1]; else LenSubArr[i]=1; if(max < LenSubArr[i]) max = LenSubArr[i]; } printf("%d\n", max); return (EXIT_SUCCESS); return (EXIT_SUCCESS); }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
52d9d43efecfb1075058beb4ef66fd36
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
//http://codeforces.com/problemset/problem/702/A #include<stdio.h> #include<math.h> #include<string.h> #define False 0 #define True 1 // int small(char ch) // int capital(char ch); // int prime(int number); // void bubble_sort(int arr[], int n); //void upper(char *ptr); //void lower(char *ptr); // void sort(char *ptr, int n); // void RemoveDuplicates(char * arr, char * new_str, int arr_size); // int Contains(char * arr, char elem, int arr_size); // int Times_of_shapes(char * str, int len); int main(void) { int number, sum=1, sub=1, i; scanf("%d", &number); long long arr[number]; for(i=0;i<number;i++) { scanf("%lld", &arr[i]); } for(i=0;i<number-1;i++) { sum=1; while(arr[i]<arr[i+1]&&i<number-1) { sum++; i++; } if(sum>sub) { sub=sum; sum=1; } } printf("%d\n", sub); return 0; } // int Times_of_shapes(char * str, int len) // { // int j, i, times=0, result=0; // str[len]='\0'; // char temp[len][len+1]; // for(i=0;i<=len;i++) // { // temp[0][i]=str[i]; // } // for(i=1;i<len;i++) // { // temp[i][0]=temp[i-1][len-1]; // for(j=1;j<len;j++) // { // temp[i][j]=temp[i-1][j-1]; // } // temp[i][len]='\0'; // } // for(i=0;i<len;i++) // { // times=0; // for(j=i+1;j<len;j++) // { // if(strcmp(temp[i], temp[j])==False) // { // times++; // } // } // if(times==False) // { // result++; // } // } // return result; // } // int Contains(char * arr, char elem, int arr_size) // { // int index = 0; // for(index = 0; index < arr_size; index++) // { // if(arr[index] == elem) // { // return True; // } // } // return False; // } // void RemoveDuplicates(char * arr, char * new_str, int arr_size) // { // int index = 0, new_index = 0; // //clear temp string // for(index = 0; index < arr_size; index++) // { // new_str[index] = 0; // } // for(index = 0; index < arr_size; index++) // { // if(Contains(new_str, arr[index], arr_size) == False) // { // new_str[new_index] = arr[index]; // new_index++; // } // if(index==arr_size-1) // { // new_str[new_index]='\0'; // } // } // } // void sort(char *ptr, int n) // { // int i, j, temp; // for(i=0;i<n-1;i++) // { // for(j=0;j<n-i-1;j++) // { // if(ptr[j]>ptr[j+1]) // { // temp=ptr[j]; // ptr[j]=ptr[j+1]; // ptr[j+1]=temp; // } // } // } // } /* void upper(char *ptr) { int i=0; while(ptr[i]!='\0') { if(ptr[i]>='a'&&ptr[i]<='z') ptr[i]-=32; i++; } }*/ /* void lower(char *ptr) { int i=0; while(ptr[i]!='\0') { if(ptr[i]>='A'&&ptr[i]<='Z') ptr[i]+=32; i++; } }*/ // void bubble_sort(int ptr[], int n) // { // int i, j, temp; // for(i=0;i<n-1;i++) // { // for(j=0;j<n-i-1;j++) // { // if(ptr[j]>ptr[j+1]) // { // temp=ptr[j]; // ptr[j]=ptr[j+1]; // ptr[j+1]=temp; // } // } // } // } // int capital(char ch) // { // int flag=0; // if(ch>=65&&ch<=90) // flag=1; // return flag; // } // int small(char ch) // { // int flag=0; // if(ch>='a'&&ch<='z') // flag=1; // return flag; // } // int prime(int number) // { // int flag=1, i; // for(i=2;i<=number/2;i++) // { // if(number%i==0) // { // flag=0; // break; // } // } // if(number<=1) // flag=1; // return flag; // }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
15b63f8fa01f723a242b386bd9e443f5
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> #include<string.h> int main() { int ara[100000]; int n,i,x=1,a=1; scanf("%d",&n); scanf("%d",&ara[0]); for(i=1;i<n;i++){ scanf("%d",&ara[i]); if(ara[i]>ara[i-1]){ x=x+1; } else{ x=1; } if(x>a) a=x; } printf("%d\n",a); return 0; }
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Print the maximum length of an increasing subarray of the given array.
C
4553b327d7b9f090641590d6492c2c41
c179ac3990bd7592eefcc01b7f02c654
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation", "greedy" ]
1469804400
["5\n1 7 2 11 15", "6\n100 100 100 100 100 100", "3\n1 2 3"]
null
PASSED
800
standard input
1 second
The first line contains single positive integer n (1โ€‰โ‰คโ€‰nโ€‰โ‰คโ€‰105) โ€” the number of integers. The second line contains n positive integers a1,โ€‰a2,โ€‰...,โ€‰an (1โ€‰โ‰คโ€‰aiโ€‰โ‰คโ€‰109).
["3", "1", "3"]
#include<stdio.h> int main() { long long n,k,j,i,m; scanf("%lld",&n); long long a[n]; for(i=0; i<n; i++) { scanf("%lld",&a[i]); } k = 1; m = 0; for(i=0,j=i+1; i<n-1,j<n; i++,j++) { if(a[j]>a[i]) { k++; } else { if(k > m) { m = k; } k = 1; } } if(k > m) { printf("%lld\n",k); } else { printf("%lld\n",m); } return 0; }
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. Masculine adjectives end with -lios, and feminine adjectives end with -liala. Masculine nouns end with -etr, and feminime nouns end with -etra. Masculine verbs end with -initis, and feminime verbs end with -inites. Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. All words in the statement should have the same gender.After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language.
If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes).
C
0c9550a09f84de6bed529d007ccb4ae8
4fa4ce70e6163139c6d707bf014d74c1
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1315494000
["petr", "etis atis animatis etis atis amatis", "nataliala kataliala vetra feinites"]
null
PASSED
1,600
standard input
5 seconds
The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language.
["YES", "NO", "YES"]
#include <stdio.h> #include <string.h> char s[200000]; char t[200000]; int type[200000]; int gender[200000]; int no; int ends(char *t,char *u) { int l=strlen(t); int m=strlen(u); int i,j; if(m>l) return 0; for(j=0,i=l-m;i<l;i++,j++) if(t[i]!=u[j]) return 0; return 1; } int ismale(char *t) { if(ends(t,"lios")) return 1; if(ends(t,"etr")) return 1; if(ends(t,"initis")) return 1; return 0; } int isfemale(char *t) { if(ends(t,"liala")) return 1; if(ends(t,"etra")) return 1; if(ends(t,"inites")) return 1; return 0; } int isadjective(char *t) { return ends(t,"lios") || ends(t,"liala"); } int issub(char *t) { return ends(t,"etr") || ends(t,"etra"); } int isverb(char *t) { return ends(t,"initis") || ends(t,"inites"); } int gettype(char *t) { if(isadjective(t)) return 0; if(issub(t)) return 1; if(isverb(t)) return 2; return -1; } int getgender(char *t) { if(ismale(t)) return 0; if(isfemale(t)) return 1; return -1; } int main() { int p=0,q,l,i; int count[3],gc[2]; gets(s); no=0; for(i=0;i<3;i++) count[i]=0; gc[0]=gc[1]=0; while(sscanf(s+p,"%s%n",t,&q)==1) { p+=q; type[no]=gettype(t); gender[no]=getgender(t); if(type[no]<0) goto fail; if(gender[no]<0) goto fail; count[type[no]]++; gc[gender[no]]++; no++; } if(gc[0] && gc[1]) goto fail; if(count[1]>1) goto fail; if(no>1 && count[1]<1) goto fail; for(i=0;i<no-1;i++) if(type[i]>type[i+1]) goto fail; puts("YES"); goto done; fail: puts("NO"); done: return 0; }
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. Masculine adjectives end with -lios, and feminine adjectives end with -liala. Masculine nouns end with -etr, and feminime nouns end with -etra. Masculine verbs end with -initis, and feminime verbs end with -inites. Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. All words in the statement should have the same gender.After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language.
If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes).
C
0c9550a09f84de6bed529d007ccb4ae8
985269844e29db9b97f6f8297dee2efa
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1315494000
["petr", "etis atis animatis etis atis amatis", "nataliala kataliala vetra feinites"]
null
PASSED
1,600
standard input
5 seconds
The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language.
["YES", "NO", "YES"]
#include <stdio.h> #include <string.h> int main() { char s[100005]; char c[100005]; char t[6][6] = {"lios", "liala", "etr", "etra", "initis", "inites"}; int x = 0, y = 0, z = 0, f = 0, i, j; int a[6] = {4, 5, 3, 4, 6, 6}; fgets(s, 100005, stdin); s[strlen(s) - 1] = '\0'; for (i = 0; i < strlen(s); i++) { int p = 0, q = 0; for (j = i; j < strlen(s); j++) { if (s[j] == ' ' || s[j] == '\0') break; c[p++] = s[j]; } c[p] = '\0'; i = j; for (j = 0; j < 6; j++) { if (p < a[j]) continue; if (strncmp(&c[p - a[j]], t[j], a[j]) == 0) break; } if (j == 6) { puts("NO"); return 0; } if (s[i] == '\0' && x + y + z == 0) { puts("YES"); return 0; } switch (j) { case 0 : if (f == 2 || y > 0 || z > 0) { q = 1; } else { x++; f = 1; } break; case 1 : if (f == 1 || y > 0 || z > 0) { q = 1; } else { x++; f = 2; } break; case 2 : if (f == 2 || y > 0 || z > 0) { q = 1; } else { y++; f = 1; } break; case 3 : if (f == 1 || y > 0 || z > 0) { q = 1; } else { y++; f = 2; } break; case 4 : if (f == 2 || y == 0) { q = 1; } else { z++; f = 1; } break; case 5 : if (f == 1 || y == 0) { q = 1; } else { z++; f = 2; } break; } if (q == 1) { puts("NO"); return 0; } } if (y == 0) { puts("NO"); } else { puts("YES"); } return 0; }
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. Masculine adjectives end with -lios, and feminine adjectives end with -liala. Masculine nouns end with -etr, and feminime nouns end with -etra. Masculine verbs end with -initis, and feminime verbs end with -inites. Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. All words in the statement should have the same gender.After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language.
If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes).
C
0c9550a09f84de6bed529d007ccb4ae8
53a19ebf4935af4d0599748e696fe8e9
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1315494000
["petr", "etis atis animatis etis atis amatis", "nataliala kataliala vetra feinites"]
null
PASSED
1,600
standard input
5 seconds
The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language.
["YES", "NO", "YES"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define MASCULINE 1 #define FEMININE 2 int check(char* input, char* s1, char *s2) { if (!strstr(input, s1) && !strstr(input, s2)) return 0; if (strstr(input, s1) != NULL) { if (strcmp(input + strlen(input) - strlen(s1), s1) == 0) return MASCULINE; } if (strstr(input, s2) != NULL) { if (strcmp(input + strlen(input) - strlen(s2), s2) == 0) return FEMININE; } return 0; } int main() { int count, state, gender = 0; char input[100001]; char ma[] = "lios", fa[] = "liala", mn[] = "etr", fn[] = "etra", mv[] = "initis", fv[] = "inites"; gets(input); if (strchr(input, ' ') == NULL && (check(input, ma, fa) || check(input, mn, fn) || check(input, mv, fv))) { puts("YES"); return 0; } state = 1; char* pch = strtok (input, " "); while (pch != NULL) { switch (state) { case 1: if (check(pch, ma, fa)) { if (gender == 0) { gender = check(pch, ma, fa); } else if (check(pch, ma, fa) != gender){ state = 3; } } else if (check(pch, mn, fn)){ if (gender != 0) { if (gender == check(pch, mn, fn)){ state = 2; } else state = 3; } else { state = 2; gender = check(pch, mn, fn); } } else state = 3; break; case 2: if (check(pch, mv, fv)) { if (gender == check(pch, mv, fv)){ state = 2; } else state = 3; } else state = 3; break; case 3: puts("NO"); return 0; break; } pch = strtok (NULL, " "); } if (state == 2) { puts("YES"); } else puts("NO"); return 0; }
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. Masculine adjectives end with -lios, and feminine adjectives end with -liala. Masculine nouns end with -etr, and feminime nouns end with -etra. Masculine verbs end with -initis, and feminime verbs end with -inites. Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. All words in the statement should have the same gender.After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language.
If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes).
C
0c9550a09f84de6bed529d007ccb4ae8
d43fd127cd29d2fd12e285f2af3ef5e8
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1315494000
["petr", "etis atis animatis etis atis amatis", "nataliala kataliala vetra feinites"]
null
PASSED
1,600
standard input
5 seconds
The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language.
["YES", "NO", "YES"]
#include <stdio.h> #include <string.h> // ๋‚จ์„ฑ / ์—ฌ์„ฑ // ํ˜•์šฉ์‚ฌ lios / liala // ๋ช…์‚ฌ etr / etra // ๋™์‚ฌ initis / inites // ??ํ˜•์šฉ์‚ฌ + 1๋ช…์‚ฌ + ??๋™์‚ฌ (๋™์‚ฌ๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ ์žˆ์œผ๋ฉด ์•ˆ๋œ๋‹ค.) // ํ•ญ์ƒ ๊ฐ™์€ gender๋ฅผ ๊ฐ€์ง // 1. ๋‹จ์–ด์ธ์ง€ ๋ฌธ์žฅ์ธ์ง€ ํŒ๋‹จํ•œ๋‹ค. // 2. ์–ด๋ฏธ๊ฐ€ ์ „๋ถ€ Petya์–ธ์–ด์— ๋งž๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. // 3. ๋ฌธ์žฅ์ด๋ผ๋ฉด ๋ช…์‚ฌ๊ฐ€ ์ •ํ™•ํžˆ 1๊ฐœ์ธ์ง€ ํ™•์ธํ•œ๋‹ค. // 4. ํ˜•์šฉ์‚ฌ์™€ ๋™์‚ฌ๊ฐ€ ์ œ๋Œ€๋กœ๋œ ์œ„์น˜์— ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. // 5. ๋ชจ๋“  ์–ด๋ฏธ์˜ gender๊ฐ€ ๋งž๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. int main(void){ char str[100000]; int chk_len; int male = 0, female = 0; int adj = 0; int noun = 0; int verb = 0; int OK = 1; while( scanf("%s", str) != EOF ) { chk_len = strlen(str); if(chk_len >= 4 && !strcmp(str+chk_len-4, "lios") ) { if( noun || verb ){ OK = 0; } adj++, male++; } else if( chk_len >= 5 && !strcmp(str+chk_len-5, "liala") ) { if( noun || verb ){ OK = 0; } adj++, female++; } else if( chk_len >= 3 && !strcmp(str+chk_len-3, "etr") ) { if( verb ){ OK = 0; } noun++, male++; } else if( chk_len >= 4 && !strcmp(str+chk_len-4, "etra") ) { if( verb ){ OK = 0; } noun++, female++; } else if( chk_len >= 6 && !strcmp(str+chk_len-6, "initis") ) { verb++, male++; } else if( chk_len >= 6 && !strcmp(str+chk_len-6, "inites") ) { verb++, female++; } else{ OK = 0; } } if( !OK ){ printf("NO"); } else if( adj+noun+verb == 1 ){ printf("YES"); } else { if( noun != 1 || male && female ){ OK = 0; } if( OK ){ printf("YES"); } else{ printf("NO"); } } return 0; }
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. Masculine adjectives end with -lios, and feminine adjectives end with -liala. Masculine nouns end with -etr, and feminime nouns end with -etra. Masculine verbs end with -initis, and feminime verbs end with -inites. Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. All words in the statement should have the same gender.After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language.
If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes).
C
0c9550a09f84de6bed529d007ccb4ae8
bd9fba1dd852e3ad8c69dc106bf4b182
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1315494000
["petr", "etis atis animatis etis atis amatis", "nataliala kataliala vetra feinites"]
null
PASSED
1,600
standard input
5 seconds
The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language.
["YES", "NO", "YES"]
#include <stdio.h> #include <string.h> // ๋‚จ์„ฑ / ์—ฌ์„ฑ // ํ˜•์šฉ์‚ฌ lios / liala // ๋ช…์‚ฌ etr / etra // ๋™์‚ฌ initis / inites // ??ํ˜•์šฉ์‚ฌ + 1๋ช…์‚ฌ + ??๋™์‚ฌ (๋™์‚ฌ๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ ์žˆ์œผ๋ฉด ์•ˆ๋œ๋‹ค.) // ํ•ญ์ƒ ๊ฐ™์€ gender๋ฅผ ๊ฐ€์ง // 1. ๋‹จ์–ด์ธ์ง€ ๋ฌธ์žฅ์ธ์ง€ ํŒ๋‹จํ•œ๋‹ค. // 2. ์–ด๋ฏธ๊ฐ€ ์ „๋ถ€ Petya์–ธ์–ด์— ๋งž๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. // 3. ๋ฌธ์žฅ์ด๋ผ๋ฉด ๋ช…์‚ฌ๊ฐ€ ์ •ํ™•ํžˆ 1๊ฐœ์ธ์ง€ ํ™•์ธํ•œ๋‹ค. // 4. ํ˜•์šฉ์‚ฌ์™€ ๋™์‚ฌ๊ฐ€ ์ œ๋Œ€๋กœ๋œ ์œ„์น˜์— ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. // 5. ๋ชจ๋“  ์–ด๋ฏธ์˜ gender๊ฐ€ ๋งž๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. int main(void){ char str[100000]; int chk_len; int male = 0, female = 0; int adj = 0; int noun = 0; int verb = 0; int OK = 1; while( scanf("%s", str) != EOF ) //๋ฌธ์žฅ์ด ๋๋‚  ๋•Œ ๊นŒ์ง€ ๊ณ„์† ๋‹จ์–ด๋ฅผ ํ•œ๊ฐœ์”ฉ ๋ฐ›์•„์˜ด { chk_len = strlen(str); //๋‹จ์–ด์˜ ๊ธธ์ด if(chk_len >= 4 && !strcmp(str+chk_len-4, "lios") ) // ๋‚จ์„ฑ ํ˜•์šฉ์‚ฌ { if( noun || verb ){ // ์ด๋ฏธ ๋ช…์‚ฌ๋‚˜ ๋™์‚ฌ๊ฐ€ ์กด์žฌ printf("NO"); return 0; } adj++, male++; } else if( chk_len >= 5 && !strcmp(str+chk_len-5, "liala") ) // ์—ฌ์„ฑ ํ˜•์šฉ์‚ฌ { if( noun || verb ){ // ์ด๋ฏธ ๋ช…์‚ฌ๋‚˜ ๋™์‚ฌ๊ฐ€ ์กด์žฌ printf("NO"); return 0; } adj++, female++; } else if( chk_len >= 3 && !strcmp(str+chk_len-3, "etr") ) // ๋‚จ์„ฑ ๋ช…์‚ฌ { if( verb ){ // ์ด๋ฏธ ๋™์‚ฌ๊ฐ€ ์กด์žฌ printf("NO"); return 0; } noun++, male++; } else if( chk_len >= 4 && !strcmp(str+chk_len-4, "etra") ) // ์—ฌ์„ฑ ๋ช…์‚ฌ { if( verb ){ // ์ด๋ฏธ ๋™์‚ฌ๊ฐ€ ์กด์žฌ printf("NO"); return 0; } noun++, female++; } else if( chk_len >= 6 && !strcmp(str+chk_len-6, "initis") ) // ๋‚จ์„ฑ ๋™์‚ฌ { verb++, male++; } else if( chk_len >= 6 && !strcmp(str+chk_len-6, "inites") ) // ์—ฌ์„ฑ ๋™์‚ฌ { verb++, female++; } else{ printf("NO"); return 0; } //Petya์–ด๊ฐ€ ์•„๋‹˜ } if( adj+noun+verb == 1 ){ //๋‹จ์–ด๋ฉด printf("YES"); } else { if( noun != 1 || male && female ){ //๋ฌธ์žฅ์ธ๋ฐ ๋ช…์‚ฌ๊ฐ€ 1๊ฐœ๊ฐ€ ์•„๋‹ˆ๊ฑฐ๋‚˜ ํ˜ผ์„ฑ ๋ฌธ์žฅ์ผ๋•Œ printf("NO"); return 0; } printf("YES"); } return 0; }
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. Masculine adjectives end with -lios, and feminine adjectives end with -liala. Masculine nouns end with -etr, and feminime nouns end with -etra. Masculine verbs end with -initis, and feminime verbs end with -inites. Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. All words in the statement should have the same gender.After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language.
If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes).
C
0c9550a09f84de6bed529d007ccb4ae8
d01d2088a9583e7ae9bae6d263c55763
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1315494000
["petr", "etis atis animatis etis atis amatis", "nataliala kataliala vetra feinites"]
null
PASSED
1,600
standard input
5 seconds
The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language.
["YES", "NO", "YES"]
#include <stdio.h> #include <string.h> char str[200005]={0}; int main() { long flag=0; long t=1; long s=0; long l; long temp=0; for(;;) { temp=0; if(scanf("%s",str)==EOF) break; l=strlen(str); if(l>=4) if(str[l-1]=='s'&&str[l-2]=='o'&&str[l-3]=='i'&&str[l-4]=='l') flag|=1,temp=1; if(l>=5) if(str[l-1]=='a'&&str[l-2]=='l'&&str[l-3]=='a'&&str[l-4]=='i'&&str[l-5]=='l') flag|=2,temp=2; if(l>=3) if(str[l-1]=='r'&&str[l-2]=='t'&&str[l-3]=='e') flag|=1,temp=3; if(l>=4) if(str[l-1]=='a'&&str[l-2]=='r'&&str[l-3]=='t'&&str[l-4]=='e') flag|=2,temp=4; if(l>=6) if(str[l-1]=='s'&&str[l-2]=='i'&&str[l-3]=='t'&&str[l-4]=='i'&&str[l-5]=='n'&&str[l-6]=='i') flag|=1,temp=5; if(l>=6) if(str[l-1]=='s'&&str[l-2]=='e'&&str[l-3]=='t'&&str[l-4]=='i'&&str[l-5]=='n'&&str[l-6]=='i') flag|=2,temp=6; if(temp==0) goto loop; s++; if(temp<=2&&t!=1) goto loop2; if(temp>=5&&t!=3) goto loop2; if(temp==3||temp==4) { if(t!=1) goto loop2; t=3; } } if(t!=3&&s!=1||flag==3) { loop: printf("NO\n"); return 0; loop2: if(s!=1||scanf("%s",str)!=EOF) { printf("NO\n"); return 0; } else { printf("YES\n"); return 0; } } else printf("YES\n"); return 0; }