prob_desc_description
stringlengths
63
3.8k
prob_desc_output_spec
stringlengths
17
1.47k
βŒ€
lang_cluster
stringclasses
2 values
src_uid
stringlengths
32
32
code_uid
stringlengths
32
32
lang
stringclasses
7 values
prob_desc_output_to
stringclasses
3 values
prob_desc_memory_limit
stringclasses
19 values
file_name
stringclasses
111 values
tags
listlengths
0
11
prob_desc_created_at
stringlengths
10
10
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_notes
stringlengths
4
3k
βŒ€
exec_outcome
stringclasses
1 value
difficulty
int64
-1
3.5k
βŒ€
prob_desc_input_from
stringclasses
3 values
prob_desc_time_limit
stringclasses
27 values
prob_desc_input_spec
stringlengths
28
2.42k
βŒ€
prob_desc_sample_outputs
stringlengths
2
796
source_code
stringlengths
42
65.5k
hidden_unit_tests
stringclasses
1 value
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
C
a4563e6aea9126e20e7a33df664e3171
20925897b0138ad8f6a89689b3a74afc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "dfs and similar", "trees", "graphs" ]
1520177700
["3\n1 1", "5\n1 2 2 2", "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4"]
NoteIn first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.
PASSED
1,500
standard input
1 second
First line of input contains single integer number n (2 ≀ n ≀ 100 000) Β β€” number of inflorescences. Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 ≀ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
["1", "3", "4"]
#define e(n) for(i=1;i<=n;i++) n,p[1<<17],d[1<<17],s[1<<17],a,i; main(){ scanf("%d", &n); e(n-1)scanf("%d",&p[i+1]); e(n)s[d[i]=d[p[i]]+1]^=1; e(n)a+=s[i]; printf("%d",a); }
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.The current state of the wall can be respresented by a sequence $$$a$$$ of $$$n$$$ integers, with $$$a_i$$$ being the height of the $$$i$$$-th part of the wall.Vova can only use $$$2 \times 1$$$ bricks to put in the wall (he has infinite supply of them, however).Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some $$$i$$$ the current height of part $$$i$$$ is the same as for part $$$i + 1$$$, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part $$$1$$$ of the wall or to the right of part $$$n$$$ of it).Note that Vova can't put bricks vertically.Vova is a perfectionist, so he considers the wall completed when: all parts of the wall has the same height; the wall has no empty spaces inside it. Can Vova complete the wall using any amount of bricks (possibly zero)?
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero). Print "NO" otherwise.
C
f73b832bbbfe688e378f3d693cfa23b8
6dcbdb369a9146568e4bf0cda936781b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation" ]
1545143700
["5\n2 1 1 2 5", "3\n4 5 3", "2\n10 10"]
NoteIn the first example Vova can put a brick on parts 2 and 3 to make the wall $$$[2, 2, 2, 2, 5]$$$ and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it $$$[5, 5, 5, 5, 5]$$$.In the second example Vova can put no bricks in the wall.In the third example the wall is already complete.
PASSED
2,200
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β€” the number of parts in the wall. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) β€” the initial heights of the parts of the wall.
["YES", "NO", "YES"]
#include <stdio.h> #define N 200000 int main() { static int aa[N], ll[N], rr[N], stack[N]; int n, i, cnt; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &aa[i]); cnt = 0; for (i = 0; i < n; i++) { while (cnt && aa[stack[cnt - 1]] <= aa[i]) cnt--; ll[i] = cnt == 0 ? -1 : stack[cnt - 1]; stack[cnt++] = i; } cnt = 0; for (i = n - 1; i >= 0; i--) { while (cnt && aa[stack[cnt - 1]] <= aa[i]) cnt--; rr[i] = cnt == 0 ? n : stack[cnt - 1]; stack[cnt++] = i; } for (i = 0; i < n; i++) if ((ll[i] >= 0 || rr[i] < n) && (rr[i] - ll[i] - 1) % 2 != 0) { printf("NO\n"); return 0; } printf("YES\n"); return 0; }
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.The current state of the wall can be respresented by a sequence $$$a$$$ of $$$n$$$ integers, with $$$a_i$$$ being the height of the $$$i$$$-th part of the wall.Vova can only use $$$2 \times 1$$$ bricks to put in the wall (he has infinite supply of them, however).Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some $$$i$$$ the current height of part $$$i$$$ is the same as for part $$$i + 1$$$, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part $$$1$$$ of the wall or to the right of part $$$n$$$ of it).Note that Vova can't put bricks vertically.Vova is a perfectionist, so he considers the wall completed when: all parts of the wall has the same height; the wall has no empty spaces inside it. Can Vova complete the wall using any amount of bricks (possibly zero)?
Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero). Print "NO" otherwise.
C
f73b832bbbfe688e378f3d693cfa23b8
99cd0cd00a27180d0691009d619702e5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation" ]
1545143700
["5\n2 1 1 2 5", "3\n4 5 3", "2\n10 10"]
NoteIn the first example Vova can put a brick on parts 2 and 3 to make the wall $$$[2, 2, 2, 2, 5]$$$ and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it $$$[5, 5, 5, 5, 5]$$$.In the second example Vova can put no bricks in the wall.In the third example the wall is already complete.
PASSED
2,200
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) β€” the number of parts in the wall. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) β€” the initial heights of the parts of the wall.
["YES", "NO", "YES"]
#include<stdio.h> #include<stdlib.h> struct node { int h; int flag; struct node *next; }; int main() { int n; struct node *list = NULL; scanf("%d", &n); int *a = (int *)malloc(sizeof(int) * n); for (int i = 0; i < n; ++i) { scanf("%d", a + i); while (list != NULL && a[i] > list->h) { if (list->flag) { printf("NO\n"); return 0; } struct node *p = list; list = list->next; free(p); } if (list == NULL || a[i] < list->h) { struct node *p = (struct node *)malloc(sizeof(struct node)); p->h = a[i], p->flag = 1, p->next = list; list = p; } else list->flag ^= 1; } while(list != NULL){ if (list->flag && list->next != NULL) { printf("NO\n"); return 0; } list = list->next; } printf("YES\n"); return 0; }
This is an easier version of the problem E with smaller constraints.Twilight Sparkle has received a new task from Princess Celestia. This time she asked to decipher the ancient scroll containing important knowledge of pony origin.To hide the crucial information from evil eyes, pony elders cast a spell on the scroll. That spell adds exactly one letter in any place to each word it is cast on. To make the path to the knowledge more tangled elders chose some of words in the scroll and cast a spell on them.Twilight Sparkle knows that the elders admired the order in all things so the scroll original scroll contained words in lexicographically non-decreasing order. She is asked to delete one letter from some of the words of the scroll (to undo the spell) to get some version of the original scroll. Unfortunately, there may be more than one way to recover the ancient scroll. To not let the important knowledge slip by Twilight has to look through all variants of the original scroll and find the required one. To estimate the maximum time Twilight may spend on the work she needs to know the number of variants she has to look through. She asks you to find that number! Since that number can be very big, Twilight asks you to find it modulo $$$10^9+7$$$.It may occur that princess Celestia has sent a wrong scroll so the answer may not exist.A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds: $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$; in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.
Print one integer: the number of ways to get a version of the original from the scroll modulo $$$10^9+7$$$.
C
b27f6ae6fbad129758bba893f20b6df9
af4744a60eb8353e3fa28e7bd7979e0d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "dp", "hashing", "string suffix structures", "implementation", "strings" ]
1596810900
["3\nabcd\nzaza\nataka", "4\ndfs\nbfs\nsms\nmms", "3\nabc\nbcd\na", "6\nlapochka\nkartyshka\nbigbabytape\nmorgenshtern\nssshhhiiittt\nqueen"]
NoteNotice that the elders could have written an empty word (but they surely cast a spell on it so it holds a length $$$1$$$ now).
PASSED
2,800
standard input
1.5 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$): the number of words in the scroll. The $$$i$$$-th of the next $$$n$$$ lines contains a string consisting of lowercase English letters: the $$$i$$$-th word in the scroll. The length of each word is more or equal than $$$1$$$. The sum of lengths of words does not exceed $$$20000$$$.
["4", "8", "0", "2028"]
#include <stdio.h> #include <string.h> #define N 1000000 #define MD 1000000007 int main() { static char aa[N + 1]; static int dp[N + 1]; int k, n, i, ans; scanf("%d%s", &k, aa), n = strlen(aa); for (i = 0; i <= n; i++) dp[i] = 1; while (--k) { static char bb[N + 1], ok1[N], ok2[N]; static int dq[N + 1]; int m, j, j_, sum1, sum2, ok; scanf("%s", bb), m = strlen(bb); j_ = m; memset(dq, 0, (m + 1) * sizeof *dq); for (j = 0; j <= m; j++) if (aa[j] != bb[j]) { j_ = j; if (aa[j] < bb[j]) { int x; x = 0; for (i = j_ + 1; i <= n; i++) x = (x + dp[i]) % MD; for (j = j_ + 1; j <= m; j++) dq[j] = (dq[j] + x) % MD; } break; } ok2[n - 1] = 1; for (i = n - 2; i >= 0; i--) ok2[i] = i + 1 < m && (aa[i + 1] < bb[i + 1] || aa[i + 1] == bb[i + 1] && ok2[i + 1]); ok1[n - 1] = 1; for (i = n - 2; i >= 0; i--) ok1[i] = i < m && (aa[i + 1] < bb[i] || aa[i + 1] == bb[i] && ok1[i + 1]); sum1 = sum2 = 0; for (i = 0, j = 0; j <= m; j++) { if (j <= n && j <= j_) sum2 = (sum2 + dp[j]) % MD; if (j > 0 && aa[j] != bb[j - 1]) while (i <= n && i < j) { if (i <= j_) { sum2 = (sum2 - dp[i]) % MD; if (i == n || ok1[i]) sum1 = (sum1 + dp[i]) % MD; } i++; } dq[j] = ((long long) dq[j] + sum1 + (j >= n || ok2[j] ? sum2 : 0)) % MD; } sum1 = sum2 = 0, ok = 0; for (i = n, j = n; j >= 0; j--) { if (j + 1 >= m || aa[j] != bb[j + 1]) { ok = j + 1 >= m && j == n || j + 1 < m && aa[j] < bb[j + 1]; while (i > j) { if (i == n || ok2[i]) sum1 = (sum1 - dp[i]) % MD; sum2 = (sum2 + dp[i]) % MD; i--; } } if (j <= j_) dq[j] = ((long long) dq[j] + sum1 + (ok ? sum2 : 0)) % MD; if (j == n || ok2[j]) sum1 = (sum1 + dp[j]) % MD; } strcpy(aa, bb); memcpy(dp, dq, (m + 1) * sizeof *dq); n = m; } ans = 0; for (i = 0; i <= n; i++) ans = (ans + dp[i]) % MD; if (ans < 0) ans += MD; printf("%d\n", ans); return 0; }
Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a zebra, if it starts with a bad day, ends with a bad day, and good and bad days are alternating in it. Let us denote bad days as 0 and good days as 1. Then, for example, sequences of days 0, 010, 01010 are zebras, while sequences 1, 0110, 0101 are not.Oleg tells you the story of days he lived in chronological order in form of string consisting of 0 and 1. Now you are interested if it is possible to divide Oleg's life history into several subsequences, each of which is a zebra, and the way it can be done. Each day must belong to exactly one of the subsequences. For each of the subsequences, days forming it must be ordered chronologically. Note that subsequence does not have to be a group of consecutive days.
If there is a way to divide history into zebra subsequences, in the first line of output you should print an integer k (1 ≀ k ≀ |s|), the resulting number of subsequences. In the i-th of following k lines first print the integer li (1 ≀ li ≀ |s|), which is the length of the i-th subsequence, and then li indices of days forming the subsequence. Indices must follow in ascending order. Days are numbered starting from 1. Each index from 1 to n must belong to exactly one subsequence. If there is no way to divide day history into zebra subsequences, print -1. Subsequences may be printed in any order. If there are several solutions, you may print any of them. You do not have to minimize nor maximize the value of k.
C
37b34461876af7f2e845417268b55ffa
23bd42d429e4f55f363133767f5b7e88
GNU C
standard output
512 megabytes
train_001.jsonl
[ "greedy" ]
1520583000
["0010100", "111"]
null
PASSED
1,600
standard input
1 second
In the only line of input data there is a non-empty string s consisting of characters 0 and 1, which describes the history of Oleg's life. Its length (denoted as |s|) does not exceed 200 000 characters.
["3\n3 1 3 4\n3 2 5 6\n1 7", "-1"]
//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);} typedef struct{ int single; int score; }smem; int sortfnc(const void *a,const void *b){ if(((smem*)a)->single > ((smem*)b)->single){return 1;} if(((smem*)a)->single < ((smem*)b)->single){return -1;} if(((smem*)a)->score > ((smem*)b)->score){return 1;} if(((smem*)a)->score < ((smem*)b)->score){return -1;} return 0; } int main(void){ int pt=0,fl[262144]={0},mid=-inf,nn,i,j,n,m,k,a[262144],b,c[262144]={0},w,r=0,l,t,id,bw; double d; char s[262144]; smem dt[262144]; scanf("%s",s); l=strlen(s); if(s[0]=='1'){printf("-1\n");return 0;} if(s[l-1]=='1'){printf("-1\n");return 0;} id=1;bw=0;a[0]=1; mid=max(mid,id); for(i=1;i<l;i++){ nn=s[i]-'0'; if(bw==nn){ if(nn==1){id--;} else{id++;} } a[i]=id; if(id<=0){printf("-1\n");return 0;} bw=nn; mid=max(mid,id); } if(mid!=a[l-1]){printf("-1\n");return 0;} for(i=0;i<l;i++){ dt[i].single=a[i]; dt[i].score=i; fl[a[i]]=s[i]-'0'; c[a[i]]++; } for(i=1;i<=mid;i++){ if(fl[i]){printf("-1\n");return 0;} } qsort(dt,l,sizeof(smem),sortfnc); printf("%d\n",mid); for(i=1;i<=mid;i++){ printf("%d",c[i]); for(j=0;j<c[i];j++){printf(" %d",1+dt[pt].score);pt++;} printf("\n"); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
1641c2b01b67eb006fa785f947f80e5a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> int main() { int t; scanf("%d", &t); while (t--) { int n, k0, k1, k2, cnt; scanf("%d", &n); k0 = k1 = k2 = 0; while (n--) { int a; scanf("%d", &a); if (a % 3 == 0) k0++; else if (a % 3 == 1) k1++; else k2++; } cnt = k1 < k2 ? k1 : k2; printf("%d\n", k0 + cnt + (k1 + k2 - cnt * 2) / 3); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
a1f8999827b7bcdb01ff78387e365b42
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { int t, n, x, i; scanf("%d", &t); while(t--) { scanf("%d", &n); int p=0, q=0, r=0; for(i=0; i<n; i++) { scanf("%d", &x); if(x%3==0) { r++; } else if(x%3==1) { p++; } else { q++; } } if(p<=q) { printf("%d\n", r+p+((q-p)/3)); } else { printf("%d\n", r+q+((p-q)/3)); } } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
391d165466cd5f84751ae00054e27d8c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
ο»Ώ#include <stdio.h> int main() { unsigned long int x = 0; int t, n; scanf("%d", &t); int i, j; int three = 0, two = 0, one = 0; for (i = 0; i < t; i++) { scanf("%d", &n); for (j = 0; j < n; j++) { scanf("%d", &x); if (x % 3 == 0) three++; else if (x % 3 == 1) one++; else if (x % 3 == 2) two++; } if (two >= one) printf("%d\n", three + one + (two - one) / 3); else if (two < one) printf("%d\n", three + two + (one - two) / 3); three = 0; two = 0; one = 0; } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
4e9b7d0a59e7d19492b819fdcff92465
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> #include <stdlib.h> int f[3]; int main(){ int q,n,a,i,j,nr,r,min; fscanf(stdin, "%d", &q); for(i=0;i<q;i++){ fscanf(stdin, "%d", &n); nr=0; f[0]=0; f[1]=0; f[2]=0; for(j=0;j<n;j++){ fscanf(stdin, "%d", &a); r=a%3; f[r]++; } nr=f[0]; min=f[1]; if(f[2]<min) min=f[2]; nr+=min; f[1]-=min; f[2]-=min; r=f[1]/3; nr+=r; r=f[2]/3; nr+=r; fprintf(stdout,"%d\n",nr); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
21e31e1007f7cdaaccc7273686be6853
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main(){ long long int t,n,i,c=0,h=0,j=0; scanf("%lld",&t); while(t--) { scanf("%lld",&n); long long int kt, a[n]; for(i=0;i<n;i++) { scanf("%lld",&a[i]); a[i]=a[i]%3; if(a[i]==0) { c++; } if(a[i]==1) j++; if(a[i]==2) h++; } if(j>h){ kt=j-h; c=c+j-kt+kt/3; } else if(h>j){ kt=h-j; c=c+h-kt+kt/3; } else c=c+h; printf("%lld\n",c); c=0; h=0; j=0; } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
dc3fb680eea2eb4b9e8bb6ef98f18376
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> int main(){ int n,t,b[3],x,res; scanf("%d",&t); while(t--){ scanf("%d",&n); b[0]=0;b[1]=0;b[2]=0;res=0; while(n--){ scanf("%d",&x); b[x%3]++; } res+=b[0]; if(b[1]>b[2]){ res=res+b[2]+(b[1]-b[2])/3; } else{ res=res+b[1]+(b[2]-b[1])/3; } printf("%d\n",res); } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
fb2cf24ac5eab9052adadb24c191de79
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> #include <stdlib.h> #include <string.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { int t,n,i,j,result=0, max, min, cnt1=0, cnt2=0; long int nb; scanf("%d",&t); for(i=0;i<t;i++){ scanf("%d",&n); for(j=0;j<n;j++){ scanf("%d",&nb); if(nb%3==0){ result++; } else if(nb%3==1){ cnt1++; } else if(nb%3==2){ cnt2++; } } if(cnt1>cnt2){ max=cnt1; min=cnt2; } else{ max=cnt2; min=cnt1; } result=result+min+(max-min)/3; printf("%d \n",result); result=0; cnt1=0; cnt2=0; } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
7097c30db0dbcff4e29c9dacfdfa8b65
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> int main(void) { int x; scanf("%d",&x); // x is number of inputs while(x) { int y,i,count0=0,count1=0,count2=0,hm; // y is number of elements in input scanf("%d",&y); int a[y]; for(i=0;i<y;i++) { scanf("%d",&a[i]); if(a[i]%3==0) count0++; else if(a[i]%3==1) count1++; else count2++; } if( count1>count2) hm=count2; else hm=count1; count1-=hm; count2-=hm; printf("%d\n",count1/3+count2/3+count0+hm); x--; // for break the loop } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
b4e5b049c041f662c08f700d2799ef4f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { int u,n,i; scanf("%d",&u); while(u>0) { int c=0,c1=0,c2=0; scanf("%d",&n); int a[n]; for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]%3==0) { c++; } if(a[i]%3==1) { c1++; } if(a[i]%3==2) { c2++; } } if(c1<c2) { c=c+c1; c2=c2-c1; c=c+(c2/3); } else { c=c+c2; c1=c1-c2; c=c+(c1/3); } printf("%d\n",c); u--; } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
86a0c05d4981ded972bd8221072f2fd8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> int min(int a, int b) { return (a < b)? a : b; } int main() { int t, n; scanf("%d", &t); while(t--){ scanf("%d", &n); int remainder[3] = {0}; int x; int ans = 0; for(int i = 0; i < n; i++){ scanf("%d", &x); remainder[x%3]++; } int mn = min(remainder[1], remainder[2]); ans += remainder[0]; ans += mn; remainder[1] -= mn; remainder[2] -= mn; ans += (remainder[1] + remainder[2]) / 3; printf("%d\n", ans); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
68d6d5aa79f51f68bfd49dbd50785d3b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> int main(void) { int i,t,n,a[10000]; scanf("%d",&t); while(t--){ scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); int b=0,c=0,d=0; for(i=0;i<n;i++){ if(a[i]%3==1) c++; if(a[i]%3==2) d++; if(a[i]%3==0) b++; } if(c>d){ c=c-d; c=c/3; } else{ d=d-c; d=d/3; } printf("%d\n",c+d+b); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
ee8a2dfb2fd94dadf4dddc787ce1944e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> #include <stdlib.h> int main() { int n; scanf("%d",&n); while(n--){ int t; scanf("%d",&t); int a[t]; int i; for(i=0;i<t;i++){ scanf("%d",&a[i]); } int count=0; int count1=0; int count2=0; int count12=0; for(i=0;i<t;i++){ if(a[i]%3==0){ count ++; } if(a[i]%3==1){ count1 ++; } if(a[i]%3==2){ count2 ++; } } if(count1>=count2){ count += count2; count12 = count1-count2; count += count12/3; } else if(count1<count2){ count += count1; count12 = count2-count1; count += count12/3; } printf("%d\n",count); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
584bc02e56f3bcf5971e2cd3c908ecaa
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { int t,a[100],n,cnt=0,r1=0,r2=0,p,q; scanf("%d",&t); while(t>0) {int cnt=0,r1=0,r2=0; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]%3==0) cnt++; else { if(a[i]%3==1) { ++r1; } else { ++r2; } } } if(r1>r2) { p=r1-r2; cnt+=r2; } else { p=r2-r1; cnt+=r1; } q=p/3; cnt+=q; printf("%d ",cnt); t--; } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
d28c7077fed6921eac58b0ad72f3a57a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> int main(void) { int t = 0; scanf("%d", &t); while (t--) { int n = 0; int r = 0; scanf("%d", &n); int arr[n]; for (int i = 0, tmp; i < n; i++) { scanf("%d", &tmp); arr[i] = tmp % 3; } int j = 0; int k = 0; for (int i = 0; i < n; i++) { if (arr[i] == 0) { r++; } else if (arr[i] == 1) { j++; } else { k++; } } if (j >= k) { r += k + ((j - k) / 3); } else { r += j + ((k - j) / 3); } printf("%d\n", r); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
8ce60c5d03a9ff2850ba90857b4d9cab
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { int t,n,i,j,on,tw,thr; long long int a[102],p; scanf("%d",&t); for(i=0;i<t;i++) { on=0,tw=0,thr=0; scanf("%d",&n); for(j=0;j<n;j++) { scanf("%lld",&a[j]); p=a[j]; if(p%3==0) thr++; else if(p%3==1) on++; else { tw++; } } if(tw>on) { tw=tw-on; tw=(int)(tw/3); thr=thr+on+tw; } else { on=on-tw; on=(int)(on/3); thr=thr+tw+on; } if(i>0) printf("\n"); printf("%d",thr); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
a3da6fe1f05218a51f2795bf56fad87d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> #define ll long long int n, a, t, ans, mod1, mod2; int min(int a, int b){ return (a>b)?b:a; } int main(){ scanf("%d", &t); while(t--){ scanf("%d", &n); ans = mod1 = mod2 = 0; for(int i = 1; i <= n; ++i){ scanf("%d", &a); if(a%3 == 1) mod1++; else if(a%3 == 2) mod2++; else ans++; } int x = min(mod1, mod2); ans += x; mod1 -= x; mod2 -= x; ans += mod1/3; ans += mod2/3; printf("%d\n", ans); } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
d881634b49c1acfea900ce86c49c14ed
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { long long int n,i,n1,c1=0,c2=0,c3=0,c,j; scanf("%I64d",&n); for(i=0;i<n;i++){ scanf("%I64d",&n1); long long int a[n1]; for(j=0;j<n1;j++){ scanf("%I64d",&a[j]); } for(j=0;j<n1;j++){ if(a[j]%3==0){ c1++; } else if(a[j]%3==1){ c2++; } else if(a[j]%3==2){ c3++; } } if(c2<=c3){ c3=c3-c2; c3=c3/3; c=c1+c2+c3; printf("%I64d\n",c); } else{ c2=c2-c3; c2=c2/3; c=c1+c2+c3; printf("%I64d\n",c); } c1=0; c2=0; c3=0; c=0; } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
d6675ca8613d4797cde92d1f06b1b172
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> #include<stdint.h> #include<inttypes.h> typedef int64_t i64; typedef int32_t i32; static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}} static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;} #define MIN(a,b) ((a)<(b)?(a):(b)) void run (void) { i32 q = read_int(); while (q--) { i32 n = read_int(); i32 cnt[3] = {0, 0, 0}; for (i32 i = 0; i < n; ++i) { cnt[read_int() % 3]++; } i32 ans = cnt[0]; i32 v = MIN (cnt[1], cnt[2]); ans += v; cnt[1] -= v; cnt[2] -= v; ans += cnt[1] / 3 + cnt[2] / 3; print_int (ans); puts (""); } } int main (void) { run (); return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
56e7296ac4fc93363aa690ecf184a512
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> int main() { int t; scanf("%d", &t); while(t--) { int n, a; scanf("%d", &n); int cnt[3] = {0}; for(int i = 0; i < n; ++i) { scanf("%d", &a); ++cnt[a % 3]; } int min = cnt[1]; if(min > cnt[2]) { min = cnt[2]; } cnt[0] += min; cnt[1] -= min; cnt[2] -= min; printf("%d\n", cnt[0] + cnt[1] / 3 + cnt[2] / 3); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
d6490c52198a7d367a7357ba4bfd2928
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> #define Min(a,b) a<b ? a : b int main() { int q; scanf("%d", &q); while(q--) { int n, k0=0, k1=0, k2=0, cnt; scanf("%d", &n); while (n--) { int a; scanf("%d", &a); if (a % 3 == 0) k0++; else if (a % 3 == 1) k1++; else k2++; } cnt = Min(k1,k2); printf("%d\n", k0 + cnt + (k1+k2-cnt*2)/3); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
a7abb16eb769a2e2a78fbf3f4e4a01dc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main(){ int t; scanf("%d",&t); int count[3]; while(t--){ int n; scanf("%d",&n); int i; count[0]=0; count[1]=0; count[2]=0; for(i=0;i<n;i++){ int a; scanf("%d",&a); count[a%3]++; } int answer=0; answer+=count[0]; //2配1 if(count[2]==count[1]){ answer+=count[2]; }else if(count[2]>count[1]){ answer+=count[1]; //2ζœ‰ε‰©δ½™ answer+=(count[2]-count[1])/3; }else{ answer+=count[2]; //1ζœ‰ε‰©δ½™ answer+=(count[1]-count[2])/3; } printf("%d\n",answer); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
99b44cfbcdd391e41fe6ee95b6f5c83d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int t,n,array[105]; scanf("%d",&t); for(int i=0 ; i<t ;i++) { int a=0,b=0,c=0; scanf("%d",&n); for(int i=0 ; i<n ;i++) { scanf("%d",&array[i]); if(array[i]%3 == 0) a++; else if(array[i]%3 == 1) b++; else c++; } int max=0; if(b>c) max=a+c+(b-c)/3; else max=a+b+(c-b)/3; printf("%d\n",max); } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
a44ce1d390204685df107f64dd376995
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { int t, i, j; scanf("%d", &t); for(i = 0; i < t; i++) { int n, count1 = 0, count2 = 0, count = 0; scanf("%d", &n); int a[n]; for(j = 0; j < n; j++) { scanf("%d", &a[j]); if(a[j] % 3 == 0) { count++; } else if (a[j]% 3 == 1) { count1++; } else { count2++; } } while(count1 > 0 || count2 > 0) { if(count1 > 0 && count2 > 0) { count++; count1--; count2--; } else if (count1 > 2 && count2 ==0) { count1 = count1 - 3; count++; } else if (count2 > 1 && count1 == 0) { count2 = count2 - 2; count1++; } else { break; } } printf("%d\n", count); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
4e4faa14e90cf3a370c7893000e1d6d8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> #include<math.h> int main(){ int m,n,i,j,d; while(~scanf("%d",&m)){ while(m--){ int k=0; d=0; j=0; scanf("%d",&n); while(n--){ scanf("%d",&i); if(i%3==1) j++; if(i%3==2) k++; if(i%3==0) d++; } if(j>k) i=k; else i=j; int s=i; s+=(j-i)/3+(k-i)/3+d; printf("%d\n",s); } } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
900fb55137e9ff354fc14812ef26bcf1
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> #include<string.h> int cnt[3]; int ans; void solve() { ans += cnt[0]; int min = cnt[1] < cnt[2] ? cnt[1] : cnt[2]; ans += min; cnt[1] -= min; cnt[2] -= min; if(cnt[1] || cnt[2]) { if(cnt[1]) { ans += cnt[1] / 3; } if(cnt[2]) { ans += cnt[2] / 3; } } } int main() { int t; scanf("%d", &t); while(t--) { memset(cnt, 0, sizeof(cnt)); int n; scanf("%d", &n); int x; for(int i = 0; i < n; i++) { scanf("%d", &x); cnt[x%3]++; } ans = 0; solve(); printf("%d\n", ans); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
fb87b99d583809c8a50e24d52eec45df
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { int t,i,j,n,a[101],count,p,q; scanf("%d",&t); for(i=1; i<=t; i++) { scanf("%d",&n); for(j=0; j<n; j++) { scanf("%d",&a[j]); } count=p=q=0; for(j=0; j<n; j++) { if(a[j]%3==0) count=count+1; else { if(a[j]%3==1) p++; else q++; } } if(q != 0 && p>=q) count=count+q; else if(q!=0 && p<q) count=count+p; if(p>q) count=count+(p-q)/3; if(q>p) count=count+(q-p)/3; printf("%d\n",count); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
7c4fbc63363651e6b1780e7aac81e747
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { int t,n,i,b[3],s; scanf("%d",&t); while(t--){ scanf("%d",&n); for(i=0;i<3;i++) b[i]=0; long long int a; for(i=0;i<n;i++){ scanf("%lld",&a); b[a%3]++; } s=b[0]; if(b[1]>=b[2]){ s=s+b[2]; b[1]=b[1]-b[2]; s=s+b[1]/3; } else{ s=s+b[1]; b[2]=b[2]-b[1]; s=s+b[2]/3; } printf("%d\n",s); } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
f6ae020a97fcd7a34258152ec5b6f488
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> #include <stdlib.h> int main() { int i,j,t,n,num,ans; int data1,data2,data3,max,min,rest; scanf("%d",&t); for(i=0;i<t;i++) { data1=0; data2=0; data3=0; ans=0; scanf("%d",&n); for(j=0;j<n;j++) { scanf("%d",&num); if(num%3==0) data3++; if(num%3==1) data2++; if(num%3==2) data1++; } if(data1>data2) { max=data1; min=data2; } else { max=data2; min=data1; } rest=max-min; ans+=data3+min+rest/3; printf("%d\n",ans); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
4d0fe7e99497b30ee9a275e34eaf616f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { int num; scanf("%d",&num); int total[num]; int a,b,d,e,i,n,ans; for(a=0; a<num; a++){ scanf("%d",&n); int ar[n]; for(b=0; b<n; b++){ scanf("%d",&ar[b]); } int c0,c1,c2; c0=0; c1=0; c2=0; for(b=0; b<n; b++){ i=ar[b]%3; if(i == 0) c0++; if(i == 1) c1++; if(i==2) c2++; } //printf("%d %d %d",c0,c1,c2); if(c1>c2){ ans=c0+c2+(c1-c2)/3; } if(c2>c1){ ans=c0+c1+(c2-c1)/3; } if(c1==c2){ ans=c0+c1; } total[a] =ans; } for(i=0; i<num; i++){ printf("%d\n",total[i]); } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
f68045dab7e7aa9baeca09fd1e17e9c7
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> #define rep(i,a,b) for (int i=a; i<b; i++) typedef long long ll; void scan(ll *arr, int length) { rep (i,0,length) scanf("%I64d",(arr+i)); scanf("\n"); } int min(int x, int y) { return (x<=y) ? x:y; } int maxmerge(ll *arr, int length) { int residue[]={0,0,0},aux; rep (i,0,length) residue[arr[i]%3]++; aux=min(residue[1],residue[2]); return residue[0]+aux+(residue[1]-aux)/3+(residue[2]-aux)/3; } int main() { int queries,len; scanf("%d\n",&queries); for (int i=0; i<queries; i++) { scanf("%d\n",&len); ll array[len]; scan(array,len); printf("%d\n",maxmerge(array,len)); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
dd214da11ab4f3d2a9eb146340934fcc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { int n,i,t,count,j,k,l; scanf("%d", &t); while(t--) { j=0; k=0; count=0; scanf(" %d", &n); for(i=0;i<n;i++) { scanf(" %d", &l); if(!(l%3)) count++; else if(l%3==1) j++; else k++; } if(j>k) printf("%d\n", count+k+(j-k)/3); else printf("%d\n", count+j+(k-j)/3); } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
31dd776c2738129a0d9eb78ab18ef21f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> int main(int argc, char** argv){ int q; scanf("%d", &q); for(int i = 0; i < q; i++){ int p; int nula = 0; int jedna = 0; int dva = 0; scanf("%d", &p); int digits[p]; for(int j = 0; j < p; j++){ int temp = 0; scanf("%d", &temp); if(temp%3==0){ nula++; }else if(temp%3==1){ jedna++; }else{ dva++; } } if(jedna > dva){ printf("%d\n", nula+dva+(jedna-dva)/3); }else{printf("%d\n", nula + jedna + (dva-jedna)/3); } } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
98460dd8d8d6b103c111ab91e3ae64b7
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> #include<stdlib.h> main() { int q; scanf("%d",&q); while(q--) { int n,i; scanf("%d",&n); long int a[150],count=0,one=0,two=0; for(i=0;i<n;++i) { scanf("%ld",&a[i]); if(a[i]%3==0) { count++; } else { int n=a[i]%3; if(n==1) { one++; } else { two++; } } } if(one<two) { count+=one; two=two-one; two=two*2; count+=(two/6); } else if(two<one) { count+=two; one=one-two; count+=(one/3); } else { count+=one; } printf("%ld\n",count); } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
14e0a57b6fbaf11edfdf963f37a32c12
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { long long int t,n,a[101],i,m,z,c,d; scanf("%lld",&t); for(m=1;m<=t;m++) { z=0; c=0; d=0; scanf("%lld",&n); for(i=1;i<=n;i++) {scanf("%lld",&a[i]); a[i]=a[i]%3; if(a[i]==0) {z++;} if(a[i]==1) {c++;} if(a[i]==2) {d++;} } if(c>d) {z=z+d+(c-d)/3;} else {if(c<d) {z=z+c+(d-c)/3;} if(c==d) {z=z+c;} } printf("%lld\n",z); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
878a52c281eccb4da2eac6beed32cecc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { int n,i,j,sum=0,k1=0,k2=0,k3=0,y=0,x=0,count=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&x); for(j=0;j<x;j++) { scanf("%d",&y); if(y%3==0) { k1++; } else if(y%3==1) { k2++; } else if(y%3==2) { k3++; } } if(k3>k2) { count=k2; } else { count=k3; } k2=k2-count; k3=k3-count; sum=count+(k2/3)+(k3/3)+k1; printf("%d\n",sum); sum=0; k1=0; k2=0; k3=0; count=0; } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
60cdc8dc0f9d4f0af9b6c0c7fc8f905e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> int main() { int t; scanf("%d",&t); while(t--) { int n,cnt=0; scanf("%d",&n); int sup[3]={0}; for(int i=0;i<n;i++) { int a; scanf("%d",&a); sup[a%3]++; } cnt+=sup[0]; if(sup[1]>sup[2]) { cnt+=sup[2]; sup[1]-=sup[2]; cnt+=sup[1]/3; } else { cnt+=sup[1]; sup[2]-=sup[1]; cnt+=(sup[2]*2)/6; //the gcd of 2 and 3 } printf("%d\n",cnt); } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
9c8577c23a10662e2383224a5b1d89e8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> int main() { int t,n; scanf("%d",&t); for (int u=1;u<=t;u++) { scanf("%d",&n); int a[n],count=0,c1=0,c2=0; //,sum[n*n]; //int pre[n*n]; for (int i=0;i<n;i++) { scanf("%d",&a[i]); } for (int i=0;i<n;i++) { if(a[i]%3==0) { count++; } else if(a[i]%3==1) { c1++; } else { c2++; } } if (c1>c2) { count+=c2; c1=c1-c2; count+=c1/3; } else { count+=c1; c2=c2-c1; count+=c2/3; } printf("%d\n",count); } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
c2ecc4b5c19581e76dd34c451748ec1a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include<stdio.h> #include<string.h> int main() { int t; scanf("%d",&t); while(t--) { int n,i,c=0,d=0,e=0; scanf("%d",&n); int a[n]; for(i=0;i<n;i++) { scanf("%d",&a[i]); a[i]%=3; if(a[i]==0) c++; if(a[i]==1) d++; if(a[i]==2) e++; } if(d<=e) { c+=d; e-=d; c+=e/3; } else { c+=e; d-=e; c+=d/3; } printf("%d\n",c); } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$.In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $$$[2, 1, 4]$$$ you can obtain the following arrays: $$$[3, 4]$$$, $$$[1, 6]$$$ and $$$[2, 5]$$$.Your task is to find the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.You have to answer $$$t$$$ independent queries.
For each query print one integer in a single line β€” the maximum possible number of elements divisible by $$$3$$$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
C
e59cddb6c941b1d7556ee9c020701007
78f110cfdd4dd455e4f21e869ef2802a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1560090900
["2\n5\n3 1 2 3 1\n7\n1 1 1 1 1 2 2"]
NoteIn the first query of the example you can apply the following sequence of operations to obtain $$$3$$$ elements divisible by $$$3$$$: $$$[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$$$.In the second query you can obtain $$$3$$$ elements divisible by $$$3$$$ with the following sequence of operations: $$$[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$$$.
PASSED
1,100
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) β€” the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).
["3\n3"]
#include <stdio.h> int main() { int q; scanf("%d", &q); for(int i = 0; i < q; i++) { int n; scanf("%d", &n); long long int array[n],count1 = 0,count2 = 0,ans = 0; for(int j = 0; j < n; j++) scanf("%lld", &array[j]); for(int j = 0; j < n; j++) { if(array[j] % 3 == 0) ans++; else if( array[j] % 3 == 2) count2++; else count1++; } if(count1 < count2) { ans += count1; ans += ( (count2 - count1) * 2 ) / 6; } else if(count1 > count2) { ans += count2; ans += ( (count1 - count2) / 3 ); } else ans += count1; printf("%lld\n",ans); } return 0; }
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
C
1c2fc9449989d14d9eb02a390f36b7a6
3a337cec3f87716aa125b2aa62427224
GNU C
standard output
256 megabytes
train_001.jsonl
[ "binary search", "math" ]
1492356900
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
PASSED
1,800
standard input
2 seconds
The first line contains two integers, n and p (1 ≀ n ≀ 100 000, 1 ≀ p ≀ 109)Β β€” the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≀ ai, bi ≀ 100 000)Β β€” the power of the device and the amount of power stored in the device in the beginning.
["2.0000000000", "-1", "0.5000000000"]
#include<stdio.h> #include<stdlib.h> #include<string.h> #define N 250000 int x[N][2]; int main(){ int a,b,c; scanf("%d%d",&a,&b); for(int w=0;w<a;w++){ scanf("%d%d",&x[w][0],&x[w][1]); } double lb = 0; double ub = 1e10; while((ub-lb)>= 1e-5){ double mid = (lb + ub)/2.0; double temp = mid; for(int w=0;w<a;w++){ double calc = x[w][1] / ((double)x[w][0]); if(calc >= mid) continue; double calc1 = mid * x[w][0]; double calc2 = calc1 - x[w][1]; if((temp - (calc2 / ((double)b))) < 0.0){ temp = temp - (calc2 / ((double)b)); ub = mid; break; } temp = temp - ((calc2 / ((double)b))); } if(temp >= 0.0){ lb = mid; } } if(ub == 1e10){ printf("-1"); return 0; } printf("%lf",ub); }
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
C
1c2fc9449989d14d9eb02a390f36b7a6
09a29f8d54ea3cab86737fd07a38d165
GNU C
standard output
256 megabytes
train_001.jsonl
[ "binary search", "math" ]
1492356900
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
PASSED
1,800
standard input
2 seconds
The first line contains two integers, n and p (1 ≀ n ≀ 100 000, 1 ≀ p ≀ 109)Β β€” the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≀ ai, bi ≀ 100 000)Β β€” the power of the device and the amount of power stored in the device in the beginning.
["2.0000000000", "-1", "0.5000000000"]
/* Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2). Problem C, by Abreto <m@abreto.net>. */ #include <stdio.h> #include <float.h> #define N (100001) #define EPS (1e-6) typedef long long int ll; int n = 0, p = 0; int a[N] = {0}; int b[N] = {0}; ll suma = 0; double dmax(double a, double b) { return (a>b)?a:b; } int check(double t) { int i = 0; double prest = p; for(i = 0;i < n;++i) { double dp = (double)(a[i]) - ((double)(b[i]))/t; if( dp < (1e-8) ) continue; prest -= dp; if( prest < -(1e-8) ) return 0; } return 1; } double solve(void) { double l = 0.0, r = 1e18; /* the answer lies in [l,r) */ while( (r-l) > EPS || ((r-l)/dmax(1,r)) > EPS ) { double mid = (l+r)/2; if( check(mid) ) l = mid; else r = mid; } return l; } int main(void) { int i = 0; scanf("%d %d", &n, &p); for(i = 0;i < n;++i) { scanf("%d %d", a+i, b+i); suma += (ll)(a[i]); } if( p >= suma ) printf("-1\n"); else printf("%.9lf\n", solve()); return 0; }
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
C
1c2fc9449989d14d9eb02a390f36b7a6
141040b96648436397b529e36477bafe
GNU C
standard output
256 megabytes
train_001.jsonl
[ "binary search", "math" ]
1492356900
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
PASSED
1,800
standard input
2 seconds
The first line contains two integers, n and p (1 ≀ n ≀ 100 000, 1 ≀ p ≀ 109)Β β€” the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≀ ai, bi ≀ 100 000)Β β€” the power of the device and the amount of power stored in the device in the beginning.
["2.0000000000", "-1", "0.5000000000"]
/* Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2). Problem C, by Abreto <m@abreto.net>. */ #include <stdio.h> #include <float.h> #define N (100001) #define EPS (1e-6) typedef long long int ll; int n = 0, p = 0; int a[N] = {0}; int b[N] = {0}; ll suma = 0; double dmax(double a, double b) { return (a>b)?a:b; } int check(double t) { int i = 0; double prest = p; for(i = 0;i < n;++i) { double dp = (double)(a[i]) - ((double)(b[i]))/t; if( dp < (1e-8) ) continue; prest -= dp; if( prest < -(1e-8) ) return 0; } return 1; } double solve(void) { double l = 0.0, r = DBL_MAX; /* the answer lies in [l,r) */ while( (r-l) > EPS || ((r-l)/dmax(1,r)) > EPS ) { double mid = (l+r)/2; if( check(mid) ) l = mid; else r = mid; } return l; } int main(void) { int i = 0; scanf("%d %d", &n, &p); for(i = 0;i < n;++i) { scanf("%d %d", a+i, b+i); suma += (ll)(a[i]); } if( p >= suma ) printf("-1\n"); else printf("%.9lf\n", solve()); return 0; }
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
C
1c2fc9449989d14d9eb02a390f36b7a6
8f5b899cde76d2183fae4a609635668d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "binary search", "math" ]
1492356900
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
PASSED
1,800
standard input
2 seconds
The first line contains two integers, n and p (1 ≀ n ≀ 100 000, 1 ≀ p ≀ 109)Β β€” the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≀ ai, bi ≀ 100 000)Β β€” the power of the device and the amount of power stored in the device in the beginning.
["2.0000000000", "-1", "0.5000000000"]
/* Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2). Problem C, by Abreto <m@abreto.net>. */ #include <stdio.h> #include <float.h> #define N (100001) #define EPS (1e-6) typedef long long int ll; int n = 0, p = 0; int a[N] = {0}; int b[N] = {0}; ll suma = 0; double dmax(double a, double b) { return (a>b)?a:b; } int check(double t) { int i = 0; double prest = p; for(i = 0;i < n;++i) { double dp = (double)(a[i]) - ((double)(b[i]))/t; if( dp < (1e-8) ) continue; prest -= dp; if( prest < -(1e-8) ) return 0; } return 1; } double solve(void) { int i = 0; double l = 0.0, r = 1e18; /* the answer lies in [l,r) */ for(i = 0;i < 100;++i) { double mid = (l+r)/2; if( check(mid) ) l = mid; else r = mid; } return l; } int main(void) { int i = 0; scanf("%d %d", &n, &p); for(i = 0;i < n;++i) { scanf("%d %d", a+i, b+i); suma += (ll)(a[i]); } if( p >= suma ) printf("-1\n"); else printf("%.9lf\n", solve()); return 0; }
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
C
1c2fc9449989d14d9eb02a390f36b7a6
a51e83ec2017655b00767a22db7c3fcd
GNU C
standard output
256 megabytes
train_001.jsonl
[ "binary search", "math" ]
1492356900
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
PASSED
1,800
standard input
2 seconds
The first line contains two integers, n and p (1 ≀ n ≀ 100 000, 1 ≀ p ≀ 109)Β β€” the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≀ ai, bi ≀ 100 000)Β β€” the power of the device and the amount of power stored in the device in the beginning.
["2.0000000000", "-1", "0.5000000000"]
#include <stdio.h> #include <stdlib.h> #define N 100000 struct P { long long a, b; } pp[N]; int compare(const void *a, const void *b) { struct P *pa = (struct P *) a; struct P *pb = (struct P *) b; long long x = pa->b * pb->a; long long y = pb->b * pa->a; return x == y ? 0 : (x < y ? -1 : 1); } int main() { long long sum, sum1, sum2, p; int n, i; scanf("%d%lld", &n, &p); sum = 0; for (i = 0; i < n; i++) { scanf("%lld%lld", &pp[i].a, &pp[i].b); sum += pp[i].a; } if (p >= sum) printf("-1\n"); else { qsort(pp, n, sizeof *pp, compare); sum1 = sum2 = 0; for (i = 0; i < n; i++) { long long x, y; x = (long long) sum2 * pp[i].a; y = (long long) (sum1 - p) * pp[i].b; if (x <= y) break; sum1 += pp[i].a; sum2 += pp[i].b; } printf("%.12lf\n", (double) sum2 / (sum1 - p)); } return 0; }
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
C
1c2fc9449989d14d9eb02a390f36b7a6
a680bdca2b937c29ed4e1c9475dea3d3
GNU C
standard output
256 megabytes
train_001.jsonl
[ "binary search", "math" ]
1492356900
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
PASSED
1,800
standard input
2 seconds
The first line contains two integers, n and p (1 ≀ n ≀ 100 000, 1 ≀ p ≀ 109)Β β€” the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≀ ai, bi ≀ 100 000)Β β€” the power of the device and the amount of power stored in the device in the beginning.
["2.0000000000", "-1", "0.5000000000"]
//Date:21-04-17 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> #include<float.h> #include<math.h> #include<inttypes.h> #include<assert.h> #include<ctype.h> #include<limits.h> #include<time.h> #define ll long long #define For(i,n) for(i=0;i<n;i++) #define rep(i ,a ,b) for(i=(a);i<=(b);i++) #define mset(a ,value) memset(a ,value ,sizeof(a)) #define s(a) scanf("%d" ,&a); #define ls(a) scanf("%ld" ,&a) #define reg(i) register int i #define EPS 0.0000000001 #define infinite INT_MAX #define MAX 100001 #define NIL -1 int min(int a,int b){ return (a<b?a:b); } int max(int a,int b){ return (a>b?a:b); } int a[MAX] ,b[MAX]; main(){ int n ,p ,i; scanf("%d%d" ,&n ,&p); ll sum=0; For(i ,n){ scanf("%d%d" ,a+i ,b+i); sum+=a[i]; } if(p>=sum){ printf("-1"); return 0; } double lo=0.0 ,hi=DBL_MAX ,t ,time ,q; bool f=0; while(hi-lo>0.00000001){ t = (lo+hi)/2.0; time=0.0; For(i ,n){ q = t*a[i]-b[i]; if(q>0.0000000001) time+=q/(double)p; } if(time-t>0.0000000001) hi=t-EPS; else lo=t+EPS; } printf("%lf" ,lo-EPS); return 0; }
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
C
1c2fc9449989d14d9eb02a390f36b7a6
a6106c9837806cf59bc802b110ae8b25
GNU C
standard output
256 megabytes
train_001.jsonl
[ "binary search", "math" ]
1492356900
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
PASSED
1,800
standard input
2 seconds
The first line contains two integers, n and p (1 ≀ n ≀ 100 000, 1 ≀ p ≀ 109)Β β€” the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≀ ai, bi ≀ 100 000)Β β€” the power of the device and the amount of power stored in the device in the beginning.
["2.0000000000", "-1", "0.5000000000"]
//Date:21-04-17 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> #include<float.h> #include<math.h> #include<inttypes.h> #include<assert.h> #include<ctype.h> #include<limits.h> #include<time.h> #define ll long long #define For(i,n) for(i=0;i<n;i++) #define rep(i ,a ,b) for(i=(a);i<=(b);i++) #define mset(a ,value) memset(a ,value ,sizeof(a)) #define s(a) scanf("%d" ,&a); #define ls(a) scanf("%ld" ,&a) #define reg(i) register int i #define EPS 0.0000000001 #define infinite INT_MAX #define MAX 100001 #define NIL -1 int min(int a,int b){ return (a<b?a:b); } int max(int a,int b){ return (a>b?a:b); } int a[MAX] ,b[MAX]; main(){ int n ,p ,i; scanf("%d%d" ,&n ,&p); ll sum=0; For(i ,n){ scanf("%d%d" ,a+i ,b+i); sum+=a[i]; } if(p>=sum){ printf("-1"); return 0; } double lo=0.0 ,hi=DBL_MAX ,t ,time ,q; bool f=0; while(hi-lo>0.0000001){ t = (lo+hi)/2.0; time=0.0; For(i ,n){ q = t*a[i]-b[i]; if(q>0.0000000001) time+=q/(double)p; } if(time-t>0.0000000001) hi=t-EPS; else lo=t+EPS; } printf("%lf" ,lo-EPS); return 0; }
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
C
1c2fc9449989d14d9eb02a390f36b7a6
0a2c10522d110c4e83fb0beb703af260
GNU C
standard output
256 megabytes
train_001.jsonl
[ "binary search", "math" ]
1492356900
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
PASSED
1,800
standard input
2 seconds
The first line contains two integers, n and p (1 ≀ n ≀ 100 000, 1 ≀ p ≀ 109)Β β€” the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≀ ai, bi ≀ 100 000)Β β€” the power of the device and the amount of power stored in the device in the beginning.
["2.0000000000", "-1", "0.5000000000"]
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> struct d { int a; int b; double time; long long int cavail; long long int creq; } dev[100010]; void maxheapify(struct d A[], int i, int n) { int l,r,largest; struct d temp; l = i*2+1; r = l+1; if (l<= n-1 && A[l].time > A[i].time) largest=l; else largest=i; if (r<= n-1 && A[r].time > A[largest].time) largest=r; if (largest != i) { temp = A[i]; A[i] = A[largest]; A[largest] = temp; maxheapify(A,largest,n); } } void buildmaxheap(struct d A[],int n) { int i; for (i=n/2; i>=0; i--) maxheapify(A,i,n); } void heapsort(struct d A[], int n) { int i; struct d temp; buildmaxheap(A,n); for (i=n-1; i>0; i--) { temp = A[i]; A[i] = A[0]; A[0] = temp; n=n-1; maxheapify(A,0,n); } } static int cmpint(const void *p1, const void *p2) { if ( ((struct d *)p1)->time - ((struct d *)p2)->time > 0) return 1; else return -1; } int main() { int n,p,i; long long int preq=0, cumreq[100010],creq=0,cavail=0,pavail=0,diff; double min=0, max,time,ptime; scanf("%d%d", &n, &p); for (i=0; i<n; i++) { scanf("%d%d", &dev[i].a, &dev[i].b); dev[i].time= ((double) dev[i].b) / (double) dev[i].a; preq=preq+dev[i].a; pavail=pavail+dev[i].b; } if (p>=preq) printf("-1\n"); else { heapsort(dev, n); /* dev[0].cavail=0; dev[0].creq=0; */ preq=0; for (i=0; i<n; i++) { // dev[i].cavail=dev[i].cavail+dev[i].b; // dev[i].creq=dev[i].creq+dev[i].a; cavail=cavail+dev[i].b; creq=creq+dev[i].a; diff = creq - p; if (diff > 0) { time = ((double) cavail)/diff; if (time < dev[i].time) { time=ptime; break; } } ptime=time; } printf("%.8f\n",time); } return 0; }
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
C
1c2fc9449989d14d9eb02a390f36b7a6
2ad44761fd1709d7c091e47b9c172d9e
GNU C
standard output
256 megabytes
train_001.jsonl
[ "binary search", "math" ]
1492356900
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
PASSED
1,800
standard input
2 seconds
The first line contains two integers, n and p (1 ≀ n ≀ 100 000, 1 ≀ p ≀ 109)Β β€” the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≀ ai, bi ≀ 100 000)Β β€” the power of the device and the amount of power stored in the device in the beginning.
["2.0000000000", "-1", "0.5000000000"]
#include<stdio.h> #include<stdlib.h> #define eps 0.0000000001 int dec[100009]={}, beg[100009]={}; int main() { int n,power,i; long long cnt=0; double left=0.0, right=1000000000000.0, totaltime, time; scanf("%d %d",&n,&power); for(i=1; i<=n; i++){ scanf("%d %d",&dec[i],&beg[i]); cnt += dec[i]; } if(power >= cnt) printf("-1\n"); else{ while( right - left > 0.0000001){ time = 0.0; totaltime = (right+left)/2.0; for(i=1; i<=n; i++){ if((-beg[i] + (totaltime*dec[i]))>0.0000000001) time += (-beg[i] + (totaltime*dec[i]))/((double)power); } if(time - totaltime > 0.0000000001) right = totaltime - eps; else left = totaltime + eps; } printf("%lf\n",right + eps); } return 0; }
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
C
1c2fc9449989d14d9eb02a390f36b7a6
c3a5b68e24abb86e138eece6ef70fd0c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "binary search", "math" ]
1492356900
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
PASSED
1,800
standard input
2 seconds
The first line contains two integers, n and p (1 ≀ n ≀ 100 000, 1 ≀ p ≀ 109)Β β€” the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≀ ai, bi ≀ 100 000)Β β€” the power of the device and the amount of power stored in the device in the beginning.
["2.0000000000", "-1", "0.5000000000"]
# include <stdio.h> # include <stdlib.h> struct store{ double a; double b; }; int compare(const void* i, const void* j){ struct store x = *((struct store*) i); struct store y = *((struct store*) j); if(x.a==y.a && x.b == y.b) return 1; if((x.b) / (x.a) <= (y.b) / (y.a)) return 1; else return -1; } int main(void){ int N; double P; scanf("%d %lf", &N, &P); struct store records[100000]; for(int i=0; i<N; i++){ scanf("%lf %lf", &(records[i].a), &(records[i].b)); } //qsort(records, N, sizeof(struct store), compare); double sa=-P; double sb=0.0; for(int i=0; i<N; i++){ sa += records[i].a; sb += records[i].b; } if(sa <= 0){ printf("-1\n"); return 0; } int remain = N; int deleted[100000] = {0}; while(1){ int found = 0; for(int i=0; i<N; i++){ if(remain <= 1){ break; } if(deleted[i]) continue; double a = records[i].a, b = records[i].b; if((sa - a) <= 0.0) continue; if(((sb - b) / (sa - a)) < b / a ){ remain -= 1; found = 1; deleted[i] = 1; sb -= b; sa -= a; } } if(!found) break; } /* for(int i=0; i<N; i++){ double a = records[i].a, b = records[i].b; if((sa - a) <= 0.0) continue; if(((sb - b) / (sa - a)) < b / a ){ sb -= b; sa -= a; }else{ break; } } */ printf("%lf\n", sb/sa); return 0; }
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
C
1c2fc9449989d14d9eb02a390f36b7a6
a0e58bd340551257fddd4085837aaab0
GNU C
standard output
256 megabytes
train_001.jsonl
[ "binary search", "math" ]
1492356900
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
PASSED
1,800
standard input
2 seconds
The first line contains two integers, n and p (1 ≀ n ≀ 100 000, 1 ≀ p ≀ 109)Β β€” the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≀ ai, bi ≀ 100 000)Β β€” the power of the device and the amount of power stored in the device in the beginning.
["2.0000000000", "-1", "0.5000000000"]
# include <stdio.h> # include <stdlib.h> struct store{ int index; double a; double b; }; int compare(const void* i, const void* j){ struct store x = *((struct store*) i); struct store y = *((struct store*) j); double r = (x.b) / (x.a) - (y.b) / (y.a); if(r < 0) return 1; else if(r == 0){ if(x.index > y.index) return -1; else return 1; } else return -1; } int main(void){ int N; double P; scanf("%d %lf", &N, &P); struct store records[100000]; for(int i=0; i<N; i++){ scanf("%lf %lf", &(records[i].a), &(records[i].b)); records[i].index = i; } qsort(records, N, sizeof(struct store), compare); double sa=-P; double sb=0.0; for(int i=0; i<N; i++){ sa += records[i].a; sb += records[i].b; } if(sa <= 0){ printf("-1\n"); return 0; } for(int i=0; i<N; i++){ double a = records[i].a, b = records[i].b; if((sa - a) <= 0.0) continue; if(((sb - b) / (sa - a)) < b / a ){ sb -= b; sa -= a; }else{ break; } } printf("%lf\n", sb/sa); return 0; }
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .
C
1c2fc9449989d14d9eb02a390f36b7a6
7820a1d22bc76172e8564237dbf1e319
GNU C
standard output
256 megabytes
train_001.jsonl
[ "binary search", "math" ]
1492356900
["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"]
NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
PASSED
1,800
standard input
2 seconds
The first line contains two integers, n and p (1 ≀ n ≀ 100 000, 1 ≀ p ≀ 109)Β β€” the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≀ ai, bi ≀ 100 000)Β β€” the power of the device and the amount of power stored in the device in the beginning.
["2.0000000000", "-1", "0.5000000000"]
# include <stdio.h> # include <stdlib.h> struct store{ int index; double a; double b; double r; }; int compare(const void* i, const void* j){ struct store x = *((struct store*) i); struct store y = *((struct store*) j); double r = x.r - y.r; if(r < 0) return 1; else if(r == 0){ if(x.index > y.index) return -1; else return 1; } else return -1; } int main(void){ int N; double P; scanf("%d %lf", &N, &P); struct store records[100000]; for(int i=0; i<N; i++){ scanf("%lf %lf", &(records[i].a), &(records[i].b)); records[i].index = i; records[i].r = records[i].b / records[i].a; } qsort(records, N, sizeof(struct store), compare); double sa=-P; double sb=0.0; for(int i=0; i<N; i++){ sa += records[i].a; sb += records[i].b; } if(sa <= 0){ printf("-1\n"); return 0; } for(int i=0; i<N; i++){ double a = records[i].a, b = records[i].b, r = records[i].r; if((sa - a) <= 0.0) continue; if(((sb - b) / (sa - a)) < r ){ sb -= b; sa -= a; }else{ break; } } printf("%lf\n", sb/sa); return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
cab28e89c3784c1b551821c3ab535795
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int t,n,a[100005],i,arr[100005],l,r; scanf("%d",&t); while(t--) { scanf("%d",&n); l=0,r=-1; for(i=0;i<n;i++) { scanf("%d",&a[i]); } arr[++r]=a[0]; for(i=1;i<n-1;i++) { if((a[i]<a[i-1] && a[i]<a[i+1]) || (a[i]>a[i-1] && a[i]>a[i+1])) { arr[++r]=a[i]; } } arr[++r]=a[n-1]; printf("%d\n",r-l+1); for(i=l;i<=r;i++) { printf("%d ",arr[i]); } printf("\n"); } }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
404fd10cb9b17aa235f7ed79597ae254
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int tc; scanf("%d",&tc); while(tc--){ int n,i,gt=0,sm=0,j,sum=0; scanf("%d",&n); int a[n],b[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); b[0]=a[0]; for(i=1,j=1;i<n;i++){ if(a[i]>a[i-1]){ sm=0; if(gt==1) b[j-1]=a[i]; else{ b[j++]=a[i]; gt=1; } } else if(a[i]<a[i-1]){ gt=0; if(sm==1) b[j-1]=a[i]; else{ b[j++]=a[i]; sm=1; } } } printf("%d\n",j); for(i=0;i<j;i++) printf("%d ",b[i]); printf("\n"); } }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
ec39b723c34bcce00336ae40cf7754a8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include<stdio.h> int main() { int t; scanf("%d", &t); int n; int i; int p[100005]; int k; int s[100005]; for (; t > 0; t--) { scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &p[i]); s[0] = p[0]; s[1] = p[1]; k = 2; for (i = 2; i < n; i++) { if (p[0] > p[1]) { if (k % 2 > 0) { if (s[k - 1] > p[i]) { s[k] = p[i]; k++; } else s[k - 1] = p[i]; } else { if (s[k - 1] < p[i]) { s[k] = p[i]; k++; } else s[k - 1] = p[i]; } } else { if (k % 2 > 0) { if (s[k - 1] < p[i]) { s[k] = p[i]; k++; } else s[k - 1] = p[i]; } else { if (s[k - 1] > p[i]) { s[k] = p[i]; k++; } else s[k - 1] = p[i]; } } } printf("%d\n", k); for (i = 0; i < k - 1; i++) printf("%d ", s[i]); printf("%d\n", s[k - 1]); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
48f6e731caec111b8c3b2c7fecbfcfc1
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> #include <stdlib.h> int main() { long long int t; scanf("%lld", &t); do { long long int n; scanf("%lld", &n); long long int s[n]; long long int i; long long int visit[n]; for ( i = 0; i < n; ++i ) { scanf("%lld", &s[i]); visit[i] = 0; } long long int cnt = 2; visit[0] = 1; visit[n-1] = 1; for ( i = 1; i < n-1; ++i ) { cnt += 1; if ( s[i-1] <= s[i] && s[i] <= s[i+1] ) { cnt -= 1; } else if ( s[i-1] >= s[i] && s[i] >= s[i+1] ) { cnt -= 1; } else { visit[i] = 1; } } printf("%lld\n", cnt); for ( i = 0; i < n; ++i ) { if ( visit[i] == 1 ) { printf("%lld ", s[i] ); } } printf("\n"); --t; } while ( t != 0 ); //system("pause"); }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
900f31b93af7f94c195e3044ceb45241
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int isprime(long long p) { int i; double max=sqrt(p); for(i=2;i<=max;i++) if(p%i==0)break; if(i>max && p!=1)return 1; return 0; } long long gcd(long long a,long long b) { long long i; for(i=a<b?a:b;i>0;i--) if((a%i==0)&&(b%i==0))break; return i; } int comp(const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int issame(int *a,int *b,int l) //checks if two arrays of same length are same after sorting them ** { qsort(a,l,sizeof(int),comp); qsort(b,l,sizeof(int),comp); int i; for(i=0; i<l; i++) if(a[i]!=b[i]) break; if(i==l)return 1; return 0; } void swap(int *a, int *b) {int x= *a; *a= *b; *b=x; } int arrmax(int *a, int l) { int i; int max= a[0]; for(i=1;i<l;i++) if(a[i]>max)max=a[i]; return max; } int arrmin(int *a, int l) { int i; int min= a[0]; for(i=1;i<l;i++) if(a[i]<min)min=a[i]; return min; } long long fact(int a) {long long p=1; while(a>0) p*=a--; return p; } int min(int a, int b) {if(a>b) return b; return a;} int max(int a, int b) {if(a<b) return b; return a;} void sieve( int*a, int n) { n--; long long i,j; for(i=2;i<=n;i++) a[i]=0; for(i=2;i<=n;i++) if(!a[i]) for(j=i*i;j<=n;j+=i) if(!a[j])a[j]++; } int main(void) { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int p[n+1],i, a[n],c=1; int m; for(i=0;i<n;i++) scanf("%d",p+i); a[0]=p[0]; p[n]=0; m=p[1]>p[0]; for(i=2;i<=n;i++) { if(((p[i]>p[i-1])!=m ) || i==n) { m=p[i]>p[i-1]; a[c++]=p[i-1]; } } printf("%d\n",c); for(i=0;i<c;i++) printf("%d ",a[i]); printf("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
aa3840433b3c30e7fa3634ec079f41ac
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include<stdio.h> int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int a[n+1],ans[n+1],g=0,k=0; for(int i=0;i<n;i++) scanf("%d",&a[i]); if(a[1]>a[0]) g=1; else g=0; ans[k++]=a[0]; for(int i=1;i<n-1;i++) { if(g&&a[i+1]>a[i]) { continue; } else if(g) { g=0; ans[k++]=a[i]; } if(!g&&a[i+1]<a[i]) { continue; } else if(!g) { g=1; ans[k++]=a[i]; } } ans[k++]=a[n-1]; printf("%d\n",k); for(int i=0;i<k;i++) printf("%d ",ans[i]); printf("\n"); } }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
5614ce2ec63d19ec5ceeda69a4e1da63
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include<stdio.h> int set_pos(int n) { if(n<0) return -1*n; else return n; } int main() { int t,n,a[100005],i,j,k,sub[100005],d1,d2; scanf("%d",&t); while(t--) { k=1; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); sub[0]=a[0]; for(i=1;i<n-1;i++) { if(a[i-1]<a[i]&&a[i]<a[i+1]||a[i-1]>a[i]&&a[i]>a[i+1]) continue; else { sub[k]=a[i]; k++; } } sub[k]=a[n-1]; printf("%d\n",k+1); for(i=0;i<=k;i++) printf("%d ",sub[i]); printf("\n"); } }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
5d7bcd9ee57e5a4e999c86f5df771fe2
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> int main() { //code int t; scanf("%d",&t); for(int i=0;i<t;i++) { int n; scanf("%d",&n); int a[n],r[n],count=0,j=1; long long int d[n-1]; for(int i=0;i<n;i++) { scanf("%d",&a[i]); } for(int i=0;i<n-1;i++) { d[i]=a[i+1]-a[i]; } for(int i=0;i<n-2;i++) { long long int m=d[i]*d[i+1]; // printf("%lld ",m); if(m<0) { r[j]=a[i+1]; // r[i+1]=a[i+2]; count++; j++; } } r[0]=a[0]; r[j]=a[n-1]; printf("%d\n",count+2); for(int i=0;i<=j;i++) { printf("%d ",r[i]); } //long long int k=-7196488208; printf("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
1e7487a4778ba18aaf944daf0c6d396a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> #include <stdlib.h> #define N 200009 int a[N]={0},b[N]={0}; int main() { int t,i; scanf("%d",&t); for(i=1;i<=t;i++){ int sum=0; int n; scanf("%d",&n); sum=n; int j; for(j=1;j<=n;j++){ int n1; scanf("%d",&n1); a[j]=n1; } for(j=2;j<=n-1;j++){ if(a[j]>=a[j-1]&&a[j+1]>=a[j]){ a[j]=a[j-1]; b[j]=1; sum--; } else if(a[j]<=a[j-1]&&a[j+1]<=a[j]){ a[j]=a[j-1]; b[j]=1; sum--; } else b[j]=0; } b[n]=0; printf("%d\n",sum); printf("%d",a[1]); for(j=2;j<=n;j++){ if(b[j]==0) printf(" %d",a[j]); } printf("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
8d27558a3cc579cbaaa5956ace602d22
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include<stdio.h> #include<stdlib.h> int main() { int t,x,i,j,k,p,q,n; scanf("%d",&t); while(t--) { scanf("%d",&x); int n[x],a[x],b[x]; j=0; for(i=0;i<x;i++) { scanf("%d",&n[i]); if(i<=1) a[j++]=n[i]; else { p=abs(n[i]-a[j-2]); q=abs(n[i]-a[j-1])+abs(a[j-2]-a[j-1]); if(p>=q) a[j-1]=n[i]; else a[j++]=n[i]; } } printf("%d\n",j); for(i=0;i<j;i++) printf("%d ",a[i]); printf("\n"); } }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
3beb40ac57856113c5c39c578cd9de05
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> int main() { // variable in description int T; int N; int X; int* P; // variable to support int* use; // variable to judge int i; int j; int k; scanf("%d",&T); for(i=0;i<T;i++) { scanf("%d",&N); P = (int*)malloc(sizeof(int)*N); use = (int*)malloc(sizeof(int)*N); for(j=0;j<N;j++) { scanf("%d",P+j); } k = 0; for(j=0;j<N;j++) { if( (j==0) || (j==N-1) ) { *(use+j) = 1; k++; } else if( ( *(P+j-1) < *(P+j) ) && ( *(P+j) < *(P+j+1) ) ) { *(use+j) = 0; } else if( ( *(P+j-1) > *(P+j) ) && ( *(P+j) > *(P+j+1) ) ) { *(use+j) = 0; } else { *(use+j) = 1; k++; } } printf("%d\n",k); for(j=0;j<N;j++) { if(*(use+j)) { printf("%d ",*(P+j)); } } printf("\n"); free(P); free(use); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
5ba7610cbd8815818fd8485d5385b368
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include<stdio.h> int main() { int n, i, t, k; scanf("%d", &t); while(t--) { scanf("%d", &n); int a[n+1], b[n+1], y=0, r=1; for(i=0; i<n; i++) { scanf("%d", &a[i]); if(i==0) { b[i]=a[i]; } else { if(a[i]>a[i-1]) { if(y==1){ r++; } b[r]=a[i]; y=2; } else { if(y==2){ r++; } b[r]=a[i]; y=1; } } } printf("%d\n", r+1); for(k=0; k<=r; k++) { printf("%d ", b[k]); } printf("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
c409f2307abfa49d5ea4ae7969054eff
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> int main() { int t, n, p[100000], out[100000], len, i; scanf("%d", &t); while (t--) { scanf("%d", &n); for (i=0; i<n; i++) scanf("%d", &p[i]); out[0] = p[0]; len = 1; for (i=1; i<n-1; i++) if ((p[i-1] < p[i] && p[i+1] < p[i]) || (p[i-1] > p[i] && p[i+1] > p[i])) out[len++] = p[i]; printf("%d\n", len+1); for (i=0; i<len; i++) printf("%d ", out[i]); printf("%d\n", p[n-1]); } }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
c94d595c9d159ec866b9f8e494517eca
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include<stdio.h> int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t = 1; scanf("%d", &t); while(t--) { int n, id, x, xp, rlt[100010]; char sg; scanf("%d", &n); scanf("%d", &rlt[0]); scanf("%d", &rlt[1]); if(rlt[0] < rlt[1]) sg = 1; else sg = 0; id = 1; xp = rlt[1]; for(int i= 2; i<n; i++) { scanf("%d", &x); if(x > xp && sg) rlt[id] = x; else if(x < xp && !sg) rlt[id] = x; else rlt[++id] = x, sg ^= 1; xp = x; } id++; printf("%d\n", id); for(int i=0; i<id; i++) printf("%d ",rlt[i]); printf("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
29cc4ec438b60357f75f830d6798340c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> int main() { int t,n; scanf("%d",&t); for(int i=0;i<t;i++) { scanf("%d",&n); int ANS[100000]={},cnt=0,dir=0,pdir=0,pa,a; for(int o=0;o<n;o++) { scanf("%d",&a); if(o) { dir=a-pa; if(dir>0) { if(pdir<0) ANS[cnt++]=pa; pdir=1; } else if(dir<0) { if(pdir>0) ANS[cnt++]=pa; pdir=-1; } } else { ANS[cnt++]=a; } pa=a; } ANS[cnt++]=pa; printf("%d\n",cnt); for(int o=0;o<cnt;o++) printf("%d ",ANS[o]); puts(""); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
b2339d0bb1626c33306432956c2222ab
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> int main (void) { int t; scanf("%d",&t); while (t--) { int n,p=0; scanf("%d",&n); int A[n]; int B[n]; for (int i=0;i<n;i++) scanf("%d",&A[i]); B[p++]=A[0]; for (int i=1;i<n-1;i++) if ((A[i]>A[i+1] && A[i]>A[i-1]) || (A[i]<A[i+1] && A[i]<A[i-1])) B[p++]=A[i]; B[p++]=A[n-1]; printf("%d\n",p); for (int i=0;i<p;i++) printf("%d ",B[i]); printf("\n"); } }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
658ee67c189dab207a52b84c21c00b5c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int comparefunc (const void * a, const void * b) { return (*(int*)a)-(*(int*)b); } int main() { int i,j,m,n,t,k; scanf("%d", &t); for(i=0;i<t;i++){ scanf("%d", &n); //k=0; int a[n],b[n],len=2; for(j=0;j<n;j++)scanf("%d", &a[j]); b[0]=a[0]; b[n-1]=a[n-1]; for(j=1;j<n-1;j++){ if(a[j]<a[j-1]&&a[j]<a[j+1]){ len++; b[j]=a[j]; } else if(a[j]>a[j-1]&&a[j]>a[j+1]){ len++; b[j]=a[j]; } else b[j]=0; } printf("%d\n", len); for(j=0;j<n;j++){ if(b[j]!=0)printf("%d ",b[j]); } printf("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
6e2e099c76b207c3d1832aa7961a6d0a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> int main(void) { int t = 0; scanf("%d", &t); while (t--) { int n = 0; scanf("%d", &n); int arr[n]; int res[n]; int tmp = 0; int r = 0; for (int i = 0; i < n; i++) { scanf("%d", arr + i); } res[r++] = arr[0]; for (int i = 1; i < (n - 1); i++) { if ((arr[i - 1] < arr[i]) != (arr[i] < arr[i + 1])) { res[r++] = arr[i]; } } res[r++] = arr[n - 1]; printf("%d\n", r); for (int i = 0; i < r; i++) { printf("%d ", res[i]); } printf("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
e049504ed7cb49cd8808cb5b2cce64d3
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> typedef float fl; typedef char ch; typedef long long ll; #define rep(i,a,n) for(i=a;i<n;i++) #define rev(i,n,a) for(i=n;i>=a;i--) #define repr(i,a,b) for(i=a;i<b;i++) #define s(n) scanf("%d",&n); #define s2(n,m) scanf("%d%d",&n,&m); #define s3(n,m,o) scanf("%d%d%d",&n,&m,&o); #define p(n) printf("%d",n); #define p2(n,m) printf("%d%d",n,m); #define sc(n) scanf("%c",&n); #define sf(n) scanf("%f",&n); #define sl(n) scanf("%lld",&n); #define pc(n) printf("%c",n); #define pf(n) printf("%f",n); #define pl(n) printf("%lld",n); #define br break; #define co continue; #define yes printf("Yes"); #define no printf("No"); #define yess printf("YES"); #define noo printf("NO"); #define ss(a) scanf("%s",&a); #define ps(a) printf("%%s",a); #define nl printf("\n"); int main() { int t; s(t) while(t--) { int n,x=1,i,k=0; s(n) int a[n],b[n]; rep(i,0,n) s(a[i]) b[k]=a[0]; k++; while(1) { if(x>=n-1) br if(a[x]>a[x-1]) { for(i=x+1;i<n;i++) { if(a[i]<a[i-1]) { b[k]=a[i-1]; k++; break; } } x=i; } if(x>=n-1) br if(a[x]<a[x-1]) { for(i=x+1;i<n;i++) { if(a[i]>a[i-1]) { b[k]=a[i-1]; k++; break; } } x=i; } } b[k]=a[n-1]; k++; p(k) nl rep(i,0,k) printf("%d ",b[i]); nl } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
49cc3f6b1fd442ad4126c2b59bac41bc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int tc; scanf("%d",&tc); while(tc--){ int n,i,gt=0,sm=0,j,sum=0; scanf("%d",&n); int a[n],b[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); b[0]=a[0]; for(i=1,j=1;i<n;i++){ if(a[i]>a[i-1]){ sm=0; if(gt==1) b[j-1]=a[i]; else{ b[j++]=a[i]; gt=1; } } else if(a[i]<a[i-1]){ gt=0; if(sm==1) b[j-1]=a[i]; else{ b[j++]=a[i]; sm=1; } } } printf("%d\n",j); for(i=0;i<j;i++) printf("%d ",b[i]); printf("\n"); } }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
5130c746282328852c005b2e828b20dd
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> int main (void) { int t; scanf("%d",&t); while (t--) { int n,p=0; scanf("%d",&n); int A[n]; int B[n]; for (int i=0;i<n;i++) scanf("%d",&A[i]); B[p++]=A[0]; for (int i=1;i<n-1;i++) if ((A[i]>A[i+1] && A[i]>A[i-1]) || (A[i]<A[i+1] && A[i]<A[i-1])) B[p++]=A[i]; B[p++]=A[n-1]; printf("%d\n",p); for (int i=0;i<p;i++) printf("%d ",B[i]); printf("\n"); } }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
3aa6a5bb6a2a82688de0748d3bca843d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include<stdio.h> int main(){int t,i,n,j,a[100000],b[100000],c; scanf("%d",&t); for(i=0;i<t;i++) { scanf("%d",&n); for(j=0;j<n;j++) { scanf("%d",&a[j]); } b[0]=a[0]; c=1; for(j=1;j<n-1;j++) { if(a[j]>a[j-1]&&a[j]>a[j+1]) { b[c]=a[j]; c++; } else if(a[j]<a[j-1]&&a[j]<a[j+1]) { b[c]=a[j]; c++; } } b[c]=a[n-1]; c++; printf("%d\n",c); for(j=0;j<c;j++) { printf("%d ",b[j]); } printf("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
3de17b5ebed585fa2ac56160845450cc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> int main() { long long int t,m,n,a[200002],i,s,k,l,x,b[200001]; scanf("%lld",&t); for(m=1;m<=t;m++) { s=0; l=1; k=0; scanf("%lld",&n); for(i=1;i<=n;i++) {scanf("%lld",&a[i]); b[i]=0; } i=1; b[1]=a[1]; while(i<n) { x=i; while(a[i]<a[i+1]&&i<n) {i++; k++; } if(k!=0) {s=s+a[i]-a[x]; l++; b[l]=a[i]; } if(i==n) {break;} x=i; while(a[i]>a[i+1]&&i<n) {i++;} s=s+a[x]-a[i]; l++; b[l]=a[i]; } printf("%lld\n",l); for(i=1;i<=l;i++) {printf("%lld ",b[i]);} printf("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
d812675de321a44bf4c32497ec236ac5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> int main() { int k,t; scanf ("%d",&t); for (k=0;k<t;k++) { int i,n,count=0; scanf ("%d",&n); int arr[n]; for (i=0;i<n;i++) scanf ("%d",&arr[i]); int raa[n]; raa[0]=arr[0]; for (i=1;i<n-1;i++) { if (((arr[i+1]-arr[i]>0)&&(arr[i]-arr[i-1]>0))||((arr[i+1]-arr[i]<0)&&(arr[i]-arr[i-1]<0))) raa[i]=0; else raa[i]=arr[i]; } raa[n-1]=arr[n-1]; for (i=0;i<n;i++) { if (raa[i]!=0) { count++; if (raa[i]<0) raa[i]=-raa[i]; } } printf ("%d\n",count); for (i=0;i<n;i++) { if (raa[i]!=0) printf ("%d ",raa[i]); } printf ("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
dd4f3354ca910290e12114564c932ed6
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> void main() { int test; scanf("%d",&test); while(test--) { int n,i,c=-1,d=0; scanf("%d",&n); int arr[n],brr[n]; for(i=0;i<n;i++) { scanf("%d",&arr[i]); brr[i]=0; if(d==0 && i>0) { if(arr[i-1] < arr[i]) {c=0; d=1; brr[0]=arr[i-1];} else if(arr[i-1] > arr[i]) {c=1; d=1; brr[0]=arr[i-1];} } } for(i=1;i<n;i++) { if(c==0) { if(arr[i-1] <= arr[i]) continue; else{d++; c=1; brr[d-1]=arr[i-1];} } else if(c==1) { if(arr[i-1] >= arr[i]) continue; else{d++; c=0; brr[d-1]=arr[i-1];} } } d++; brr[d-1]=arr[n-1]; printf("%d\n",d); for(i=0;i<d;i++) printf("%d ",brr[i]); printf("\n"); } }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
d12fc0621585f902e6910887c3e9db66
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include<stdio.h> int n,x; int check(int x){ if(x>0) return 1; else return 0; } int main() { long long int t,a[1000001],b[10000001],c[101]; scanf("%lld",&t); while(t--){ x=0; scanf("%lld",&n); scanf("%lld",&a[0]); b[0]=a[0]; for(int i=1;i<n;i++) { scanf("%lld",&a[i]); b[i]=a[i]-a[i-1]; } long long int f=1; c[x++]=a[0]; for(int i=2;i<n;i++){ if(check(b[i])==check(b[i-1])) continue; else f++,c[x++]=a[i-1]; } if(c[x-1]!=a[n-1]) f++,c[x++]=a[n-1]; printf("%lld\n",f); for(int i=0;i<x;i++) printf("%lld ",c[i]); printf("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
a9071715a52e9d4757c2a1980286299d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include<stdio.h> int main() { int t; scanf("%d\n",&t); while(t--) { int n,i,j,b,c,e,f,g=0,h; scanf("%d\n",&n); int a[n],d[n]; for(i=0;i<n;i++) { scanf("%d ",&a[i]); d[i]=0; } for(i=1;i<n-1;i++) { b=abs(a[i]-a[i-1]); c=abs(a[i+1]-a[i]); e=b+c; f=abs(a[i+1]-a[i-1]); if(e<=f) { g++; d[i]=1; } } printf("%d\n",n-g); for(i=0;i<n;i++) { if(d[i]==0) { printf("%d ",a[i]); } } printf("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
0a738dc3ed0ecf980135596c56aaa5f7
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> int main(){ int t, n, i, flag = 0, j; int a[100001]; int b[100000]; scanf("%d", &t); while(t--){ flag = 0; j = 0; scanf("%d", &n); for(i = 0; i <= n; i++){ if(i < n) scanf("%d", &a[i]); if(i != 0){ if(a[i] > a[i - 1]){ if(flag == -1){ b[j++] = a[i - 1]; } flag = 1; } else{ if(flag == 1){ b[j++] = a[i - 1]; } flag = -1; } } else{ b[j++] = a[0]; } if(i == n - 1){ if(flag == 1){ a[n] = a[n - 1] - 1; } else if(flag == -1){ a[n] = a[n - 1] + 1; } } } printf("%d\n", j); for(i = 0; i < j; i++){ printf("%d ", b[i]); } printf("\n"); } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
79d618420e755b302be3e588529551a9
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include<stdio.h> int main(){ int T, n,p[100000],i,j,flag,f,s[100000],k; scanf("%d", &T); while (T--) { scanf("%d", &n); for (i = 0,j=0,f=0;i < n;i++) { scanf("%d", &p[i]); if (i) { flag = p[i] > p[i - 1] ? 1 : -1; if (flag==f) { s[j-1] = p[i]; } else { s[j] = p[i]; j++; } f = flag; } else { s[j] = p[i]; j++; } } printf("%d\n",j); for (k = 0;k < j;k++) { printf("%d",s[k]); if (k != j - 1) { printf(" "); } else { printf("\n"); } } } return 0; }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
bccb1542dc0d67fb6bafdc14b7fe6c40
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 222222 typedef long long ll; ll tc, n, inp[N], prev, past, cnt; int main(){ scanf("%lld", &tc); while (tc--){ scanf("%lld%lld", &n, &inp[1]); cnt=n; for (int i=2; i<=n; i++) scanf("%lld", &inp[i]); prev=inp[1]; for (ll i=2; i<n; i++){ past=inp[i+1]; //printf("prev=%lld past=%lld i=%lld\n", prev, past, i); if (llabs(past-prev)>=(llabs(inp[i]-past)+llabs(inp[i]-prev))) inp[i]=0, cnt--; else prev=inp[i]; } printf("%d\n", cnt); for (ll i=1; i<=n; i++) if (inp[i]) printf("%d ", inp[i]); printf("\n"); } }
Given a permutation $$$p$$$ of length $$$n$$$, find its subsequence $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$ of length at least $$$2$$$ such that: $$$|s_1-s_2|+|s_2-s_3|+\ldots+|s_{k-1}-s_k|$$$ is as big as possible over all subsequences of $$$p$$$ with length at least $$$2$$$. Among all such subsequences, choose the one whose length, $$$k$$$, is as small as possible. If multiple subsequences satisfy these conditions, you are allowed to find any of them.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some (possibly, zero or all) elements.A permutation of length $$$n$$$ is an array of length $$$n$$$ in which every element from $$$1$$$ to $$$n$$$ occurs exactly once.
For each test case, the first line should contain the length of the found subsequence, $$$k$$$. The second line should contain $$$s_1$$$, $$$s_2$$$, $$$\ldots$$$, $$$s_k$$$Β β€” its elements. If multiple subsequences satisfy these conditions, you are allowed to find any of them.
C
857de33d75daee460206079fa2c15814
1e8ac43b14d58df97b296d4e18757589
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "two pointers", "greedy" ]
1592060700
["2\n3\n3 2 1\n4\n1 3 4 2"]
NoteIn the first test case, there are $$$4$$$ subsequences of length at least $$$2$$$: $$$[3,2]$$$ which gives us $$$|3-2|=1$$$. $$$[3,1]$$$ which gives us $$$|3-1|=2$$$. $$$[2,1]$$$ which gives us $$$|2-1|=1$$$. $$$[3,2,1]$$$ which gives us $$$|3-2|+|2-1|=2$$$. So the answer is either $$$[3,1]$$$ or $$$[3,2,1]$$$. Since we want the subsequence to be as short as possible, the answer is $$$[3,1]$$$.
PASSED
1,300
standard input
1 second
The first line contains an integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$)Β β€” the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^5$$$)Β β€” the length of the permutation $$$p$$$. The second line of each test case contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_{n}$$$ ($$$1 \le p_i \le n$$$, $$$p_i$$$ are distinct)Β β€” the elements of the permutation $$$p$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.
["2\n3 1 \n3\n1 4 2"]
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int t,i; scanf("%d",&t); for(i=0;i<t;i++) { int n; scanf("%d",&n); int p[n],j,a[n],k=2; for(j=0;j<n;j++) { scanf("%d",(p+j)); } for(j=1;j<n-1;j++) { if(((p[j]>p[j-1])&&(p[j]>p[j+1]))||((p[j]<p[j-1])&&(p[j]<p[j+1]))) { k++; a[j]=-1; } else a[j]=0; } printf("%d\n",k); for(j=0;j<n;j++) { if(j==0||(j==n-1)||(a[j]==-1)) printf("%d ",*(p+j)); } printf("\n"); } return 0; }
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
C
ce6b65ca755d2d860fb76688b3d775db
427cdc77186aed0558bac42dc34bb0a9
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1433595600
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
PASSED
1,900
standard input
1 second
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
["2", "4", "3", "4"]
#include <stdio.h> char feature[100][101]; int field[100][100]; int main(void) { int i, j, k, l; int n, m; int ans; scanf("%d %d", &n, &m); for (i = 0; i < n; i++) scanf("%s", feature[i]); for (i = 0; i < n; i++) for (j = 0; j < m; j++) feature[i][j] = feature[i][j] == 'B' ? -1 : 1; ans = 0; for (i = n - 1; i >= 0; i--) for (j = m - 1; j >= 0; j--) { int d = feature[i][j] - field[i][j]; ans += !!d; for (k = 0; k <= i; k++) for (l = 0; l <= j; l++) field[k][l] += d; } printf("%d\n", ans); return 0; }
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
C
ce6b65ca755d2d860fb76688b3d775db
54a5855c3d5a887c1c49301c73f49178
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1433595600
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
PASSED
1,900
standard input
1 second
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
["2", "4", "3", "4"]
#include <stdio.h> #define MAXN 102 #define min(__a, __b) ((__a) < (__b) ? (__a) : (__b)) char f[MAXN][MAXN]; int a[MAXN][MAXN] = {{0}}; int ans = 0; int i, j; void add(int n, int m, int delta) { for (i = 0; i < n; ++i) for (j = 0; j < m; ++j) a[i][j] += delta; } void solve(int n, int m) { if (!m || !n) return; int i, j, t = min(n, m); for (i = 0; i < t; ++i) for (j = 0; j <= i; ++j) { if (a[n - j - 1][m - i - 1] != f[n - j - 1][m - i - 1]) { ++ans; add(n - j, m - i, f[n - j - 1][m - i - 1] - a[n - j - 1][m - i - 1]); } if (a[n - i - 1][m - j - 1] != f[n - i - 1][m - j - 1]) { ++ans; add(n - i, m - j, f[n - i - 1][m - j - 1] - a[n - i - 1][m - j - 1]); } } if (t == n) solve(n, m - n); else solve(n - m, m); } int main() { int n, m, i, j; scanf("%d%d\n", &n, &m); for (i = 0; i < n; ++i) for (j = 0; j <= m; ++j) f[i][j] = getchar() == 'W' ? 1 : -1; solve(n, m); printf("%d\n", ans); return 0; }
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
C
ce6b65ca755d2d860fb76688b3d775db
6bd1a1d5f1f23ee76733ccebbf3b8512
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1433595600
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
PASSED
1,900
standard input
1 second
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
["2", "4", "3", "4"]
/*Haar Features*/ #include<stdio.h> char feature[105][105]; int arr[105][105]; int main() { int count, i, j, k, l, m, n, val; scanf("%d %d", &n, &m); for (i = 0; i < n; i++) scanf("%s", feature[i]); for (i = 0; i < n; i++) for (j = 0; j < m; j++) arr[i][j] = 0; count = 0; for (i = n - 1; i >= 0; i--) { for (j = m - 1; j >= 0; j--) { if (((feature[i][j] == 'W') && (arr[i][j] != 1)) || ((feature[i][j] == 'B') && (arr[i][j] != -1))) { count++; val = ((feature[i][j] == 'W') ? 1 : -1) - arr[i][j]; for (k = 0; k <= i; k++) for (l = 0; l <= j; l++) arr[k][l] += val; } } } printf("%d\n", count); return 0; }
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
C
ce6b65ca755d2d860fb76688b3d775db
cdf29e9e8defc4f3e4c39d92532d0117
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1433595600
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
PASSED
1,900
standard input
1 second
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
["2", "4", "3", "4"]
#include<stdio.h> int main() { int n,m; char input[100][101]; scanf("%d%d",&n,&m); int i,j; for(i=0;i<n;i++) scanf("%s",input[i]); int trans[100][100]={0}; int c=0; for(i=n-1;i>=0;i--) for(j=m-1;j>=0;j--) { int tmp; if(input[i][j]=='W') tmp=1-trans[i][j]; else tmp=-1-trans[i][j]; if(tmp==0) continue; int x,y; for(x=0;x<=i;x++) for(y=0;y<=j;y++) trans[x][y]+=tmp; c++; } printf("%d\n",c); return 0; }
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
C
ce6b65ca755d2d860fb76688b3d775db
f28aa90ac05002f8da4dbc2918dd92f1
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1433595600
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
PASSED
1,900
standard input
1 second
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
["2", "4", "3", "4"]
# include <stdio.h> int r=0,c,m,n; int value[100][101]; char colour[100][101]; void detect_annomaly() { for(r=m-1;r>=0;r--) for(c=n-1;c>=0;c--) { if(colour[r][c]=='W' && value[r][c]!=1) return; if(colour[r][c]=='B' && value[r][c]!=-1) return; } r=-1; } void change_value() { int i,j; int add=value[r][c]; if(colour[r][c]=='W') add--; if(colour[r][c]=='B') add++; for(i=0;i<=r;i++) for(j=0;j<=c;j++) value[i][j]-=add; } int main() { int i,j,out=0;; scanf("%d %d",&m,&n); for(i=0;i<m;i++) scanf("%s",colour[i]); for(i=0;i<m;i++) for(j=0;j<n;j++) value[i][j]=0; detect_annomaly(); while(r!=-1) { change_value(); detect_annomaly(); out++; } printf("%d\n",out); return 0; }
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
C
ce6b65ca755d2d860fb76688b3d775db
c78cdea82c843883be9973f4b46a3e1e
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1433595600
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
PASSED
1,900
standard input
1 second
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
["2", "4", "3", "4"]
#include <stdio.h> int tab[100][100]; int sol[100][100]; int swap[100][100]; int visited[100][100]; void solve2(int n, int m) { if (sol[n][m] != tab[n][m]) { int d = sol[n][m] - tab[n][m]; swap[n][m] = 1; int i, j; for (i = 0; i <= n; i++) { for (j = 0; j <= m; j++) { sol[i][j] -= d; } } } } struct coord { int i, j; }; struct coord fifo[10000]; int first = 0; int last = 0; void add(int i, int j) { if (visited[i][j]) return; visited[i][j] = 1; fifo[last].i = i; fifo[last].j = j; last++; } int solve(int n, int m) { add(n - 1, m - 1); while (first < last) { struct coord *el = &fifo[first++]; //printf("%d %d\n", el->i, el->j); solve2(el->i, el->j); if (el->i > 0) { add(el->i - 1, el->j); } if (el->j > 0) { add(el->i, el->j - 1); } } int count = 0; int i, j; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { count += swap[i][j]; } } return count; } int main() { int n, m; scanf("%d %d", &n, &m); int i, j; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { char c; do { scanf("%c", &c); } while (c < 'A'); tab[i][j] = 2 * (c == 'W') - 1; } } for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { sol[i][j] = tab[n - 1][m - 1]; } } swap[n-1][m-1] = 1; printf("%d\n", solve(n, m)); /* for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { printf("%d", swap[i][j]); } printf("\n"); }*/ return 0; }
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
C
ce6b65ca755d2d860fb76688b3d775db
b64b88bf8493ec2041ea2c93a5e44388
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1433595600
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
PASSED
1,900
standard input
1 second
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
["2", "4", "3", "4"]
#include<stdio.h> #include<stdlib.h> int main() { int n,m,i,j,x,y,count=1,initial[100][100]={0},diff,final[100][100]; /////// int u,v; ///////// char final2[100][101]; scanf("%d %d",&n,&m); for(i=0;i<n;i++) { scanf(" %s",&final2[i][0]); for(j=0;j<m;j++) if(final2[i][j]=='B') final[i][j]=-1; else if(final2[i][j]='W') final[i][j]=1; } for(i=0;i<n;i++) for(j=0;j<m;j++) initial[i][j]=final[n-1][m-1]; for(i=n-1;i>=0;i--) for(j=m-1;j>=0;j--) { if(initial[i][j]==final[i][j]); else { /* /////////////////// printf("\n"); for(u=0;u<n;u++) {for(v=0;v<m;v++) printf("%d\t",initial[u][v]); printf("\n");} ////////////////*/ diff=final[i][j]-initial[i][j]; for(x=0;x<=i;x++) for(y=0;y<=j;y++) initial[x][y]+=diff; count++; } } printf("%d\n",count); return 0; }
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
C
ce6b65ca755d2d860fb76688b3d775db
f669a2ab9b1dc7643d05643ed263a966
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1433595600
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
PASSED
1,900
standard input
1 second
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
["2", "4", "3", "4"]
#include<stdio.h> char grid[102][102]; int valuegrid[102][102], a[102][102] = {0}; int main() { int i, j, diff, n, m, ans = 0, x, y; scanf("%d%d", &n, &m); for(i = 0; i < n; i++){ scanf("%s", grid[i]); } for(i = 0 ; i < n; i++){ for(j = 0; j < m; j++){ if(grid[i][j] == 'W'){ valuegrid[i][j] = 1; } else { valuegrid[i][j] = -1; } } } for(i = n; i >= 0; i--){ for(j = m; j >= 0; j--){ if(valuegrid[i][j] != a[i][j]){ ans++; diff = valuegrid[i][j] - a[i][j]; for(x = i; x >= 0; x--){ for(y = j; y >= 0; y--){ a[x][y] = a[x][y] + diff; } } } } } printf("%d\n", ans); return 0; }
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image.A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white.To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells.Some examples of the most popular Haar features are given below. Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles.A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image.You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value.You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample.
Print a single number β€” the minimum number of operations that you need to make to calculate the value of the feature.
C
ce6b65ca755d2d860fb76688b3d775db
b65ffa5d0bc2b79abfeb9aafb8bd9f6e
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1433595600
["6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "3 3\nWBW\nBWW\nWWW", "3 6\nWWBBWW\nWWBBWW\nWWBBWW", "4 4\nBBBB\nBBBB\nBBBB\nBBBW"]
NoteThe first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient  - 2 and variable value. Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 =  - 1, as required.
PASSED
1,900
standard input
1 second
The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100) β€” the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black.
["2", "4", "3", "4"]
#include<stdio.h> int main() { int n, m, i, j, num, M[100][100], x; char s[100][101]; scanf("%d %d", &n, &m); for(i = 0; i < n; i++) { scanf("%s", s[i]); for(j = 0; j < m; j++) { M[i][j] = 0; } } num = 0; x = 0; for(j = m - 1; j >= 0; j--) { M[n - 1][j] += x; if(s[n - 1][j] == 'W' && M[n - 1][j] != 1) { x += 1 - M[n - 1][j]; M[n - 1][j] = 1; num++; } else if(s[n - 1][j] == 'B' && M[n - 1][j] != -1){ x += -1 - M[n - 1][j]; M[n - 1][j] = -1; num++; } } for(i = n - 2; i >= 0; i--) { x = 0; for(j = m - 1; j >= 0; j--) { M[i][j] += M[i + 1][j] + x; if(s[i][j] == 'W' && M[i][j] != 1) { x += 1 - M[i][j]; M[i][j] = 1; num++; } else if(s[i][j] == 'B' && M[i][j] != -1){ x += -1 - M[i][j]; M[i][j] = -1; num++; } } } printf("%d", num); return 0; }
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an.While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to b1, b2, ..., bn. Stepan said that he swapped only cubes which where on the positions between l and r, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions l and r, inclusive, in some way).Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
C
1951bf085050c7e32fcf713132b30605
18579c6c56bfd873a2dfb5ab2ac3c575
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "implementation", "*special" ]
1491406500
["5 2 4\n3 4 2 3 1\n3 2 3 4 1", "3 1 2\n1 2 3\n3 1 2", "4 2 4\n1 1 1 1\n1 1 1 1"]
NoteIn the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]).In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother.In the third example for any values l and r there is a situation when Stepan said the truth.
PASSED
1,500
standard input
2 seconds
The first line contains three integers n, l, r (1 ≀ n ≀ 105, 1 ≀ l ≀ r ≀ n) β€” the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≀ ai ≀ n) β€” the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ..., bn (1 ≀ bi ≀ n) β€” the sequence of integers written on cubes after Stepan rearranged their order. It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.
["TRUTH", "LIE", "TRUTH"]
#include<stdio.h> #include<stdlib.h> int main (){ int n=0,l=0,r=0; scanf("%d %d %d",&n,&l,&r); int a[n+1]; int b[n+1]; int dp1[100001]; int dp2[100001]; int i; for(int i=0;i<=100000;i++) { dp1[i]=0; dp2[i]=0; } for( i=1;i<=n;i++) { scanf("%d",&a[i]); if(i>=l && i<=r) dp1[a[i]]++; } for(i=1;i<=n;i++) { scanf("%d",&b[i]); if(i>=l && i<=r) dp2[b[i]]++; else { if(a[i]!=b[i]) { printf("LIE"); return 0; } } } for(i=1;i<=100000;i++) { if(dp1[i]!=dp2[i]) { printf("LIE"); return 0; } } printf("TRUTH"); return 0; }
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an.While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to b1, b2, ..., bn. Stepan said that he swapped only cubes which where on the positions between l and r, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions l and r, inclusive, in some way).Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
C
1951bf085050c7e32fcf713132b30605
63e240ac5347dc82697b3b0b82cd9416
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "implementation", "*special" ]
1491406500
["5 2 4\n3 4 2 3 1\n3 2 3 4 1", "3 1 2\n1 2 3\n3 1 2", "4 2 4\n1 1 1 1\n1 1 1 1"]
NoteIn the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]).In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother.In the third example for any values l and r there is a situation when Stepan said the truth.
PASSED
1,500
standard input
2 seconds
The first line contains three integers n, l, r (1 ≀ n ≀ 105, 1 ≀ l ≀ r ≀ n) β€” the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≀ ai ≀ n) β€” the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ..., bn (1 ≀ bi ≀ n) β€” the sequence of integers written on cubes after Stepan rearranged their order. It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.
["TRUTH", "LIE", "TRUTH"]
#include <stdio.h> #include <stdlib.h> int A[100005], B[100005], C[100005]; void merge(int A[],int I,int F,int aux[]) { int piv=(I+F)/2; int p=I,q=piv+1; int r=I; while(p<=piv && q<=F) { if(A[p]<=A[q]) aux[r++]=A[p++]; else aux[r++]=A[q++]; } if(p<=piv) for(int i=p;i<=piv;i++) aux[r++]=A[i]; if(q<=F) for(int i=q;i<=F;i++) aux[r++]=A[i]; for(int i=I;i<=F;i++) A[i]=aux[i]; } void merge_sort(int A[],int I,int F,int aux[]) { if(I<F) { int piv=(I+F)/2; merge_sort(A,I,piv,aux); merge_sort(A,piv+1,F,aux); merge(A,I,F,aux); } } int main() { //freopen("a.in","r",stdin); int N, l, r; scanf("%d%d%d",&N,&l,&r); for( int i = 1; i <= N; i++ ) scanf("%d",&A[i]); for( int i = 1; i <= N; i++ ) scanf("%d",&B[i]); //sort(A+l,A+r+1); //sort(B+l,B+r+1); merge_sort( A, l, r, C ); merge_sort( B, l, r, C ); for( int i = 1; i <= N; i++ ) if( A[i] != B[i] ){ printf("LIE"); return 0; } printf("TRUTH"); return 0; }
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an.While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to b1, b2, ..., bn. Stepan said that he swapped only cubes which where on the positions between l and r, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions l and r, inclusive, in some way).Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
C
1951bf085050c7e32fcf713132b30605
fe893591251665650eab031a0fe96ff6
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "implementation", "*special" ]
1491406500
["5 2 4\n3 4 2 3 1\n3 2 3 4 1", "3 1 2\n1 2 3\n3 1 2", "4 2 4\n1 1 1 1\n1 1 1 1"]
NoteIn the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]).In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother.In the third example for any values l and r there is a situation when Stepan said the truth.
PASSED
1,500
standard input
2 seconds
The first line contains three integers n, l, r (1 ≀ n ≀ 105, 1 ≀ l ≀ r ≀ n) β€” the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≀ ai ≀ n) β€” the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ..., bn (1 ≀ bi ≀ n) β€” the sequence of integers written on cubes after Stepan rearranged their order. It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.
["TRUTH", "LIE", "TRUTH"]
#include <stdio.h> #define ri(x) scanf("%d", &x) #define rii(x,y) scanf("%d%d", &x, &y) #define FOR(i,S,E) for(int i=S; i<E; i++) #define pb push_back #define fst first #define snd second #define mp make_pair int a[100005]; int main () { int n,l,r; rii(n,l); ri(r); l--; r--; FOR(i,0,n) { ri(a[i]); } FOR(i,0,n) { int inp; ri(inp); if ((i < l || r < i) && inp != a[i]) { printf("LIE\n"); return 0; } } printf("TRUTH\n"); }
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an.While Vasya was walking, his little brother Stepan played with Vasya's cubes and changed their order, so now the sequence of numbers written on the cubes became equal to b1, b2, ..., bn. Stepan said that he swapped only cubes which where on the positions between l and r, inclusive, and did not remove or add any other cubes (i. e. he said that he reordered cubes between positions l and r, inclusive, in some way).Your task is to determine if it is possible that Stepan said the truth, or it is guaranteed that Stepan deceived his brother.
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
C
1951bf085050c7e32fcf713132b30605
e14c43e1ccd718617373cb6956f7b4da
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "implementation", "*special" ]
1491406500
["5 2 4\n3 4 2 3 1\n3 2 3 4 1", "3 1 2\n1 2 3\n3 1 2", "4 2 4\n1 1 1 1\n1 1 1 1"]
NoteIn the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and 4 (after that the sequence of integers on cubes became equal to [3, 2, 3, 4, 1]).In the second example it is not possible that Stepan said truth because he said that he swapped cubes only between positions 1 and 2, but we can see that it is guaranteed that he changed the position of the cube which was on the position 3 at first. So it is guaranteed that Stepan deceived his brother.In the third example for any values l and r there is a situation when Stepan said the truth.
PASSED
1,500
standard input
2 seconds
The first line contains three integers n, l, r (1 ≀ n ≀ 105, 1 ≀ l ≀ r ≀ n) β€” the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≀ ai ≀ n) β€” the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ..., bn (1 ≀ bi ≀ n) β€” the sequence of integers written on cubes after Stepan rearranged their order. It is guaranteed that Stepan did not remove or add other cubes, he only rearranged Vasya's cubes.
["TRUTH", "LIE", "TRUTH"]
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/ #include<stdio.h> #include<stdlib.h> #define opt std::ios_base::sync_with_stdio(false) #define I int #define li int32_t #define lli long long #define ulli unsigned long long #define pn printf("\n") #define nl cout<<'\n' #define sf(N) scanf("%lld",&N) #define pf(N) printf("%lld",N) #define sl cout<<' ' #define ps printf(" ") #define rep(i,a,b) for(i=a;i<b;i++) #define repr(i,a,b) for(i=a;i>b;i--) #define elif else if #define mset(a,b) memset(a,b,sizeof(a)) #define pb push_back #define pob pop_back #define itr iterator #define sz() size() #define szof sizeof #define lb lower_bound #define ub upper_bound #define mp make_pair #define vlli vector<lli> #define plli pair<lli,lli> #define vplli vector<plli > #define Frst first #define Sec second #define Dup erase(unique(V.begin(),V.end()),V.end()) #define TC int test; cin>>test; test++; while(--test) #define Inf 1000000000000000 #define mod 1000000007 lli Power(lli a,lli b) { lli result=1; while(b) { if(b%2) { result=(result*a)%mod; } b=b>>1; a=(a*a)%mod; } return result; } int main() { /*#ifndef ONLINE_JUDGE freopen("double_squares.txt","r",stdin); freopen("double_squares_out.txt","w",stdout); #endif // ONLINE_JUDGE*/ long int N,i; scanf("%ld",&N); long int L,R; scanf("%ld %ld",&L,&R); long int V[N]; long int V1[N]; rep(i,0,N) { scanf("%ld",&V[i]); } rep(i,0,N) { scanf("%ld",&V1[i]); } rep(i,0,L-1) { if(V[i]!=V1[i]) { printf("LIE"); exit(0); } } rep(i,R,N) { if(V[i]!=V1[i]) { printf("LIE"); exit(0); } } long int Count[N+1]; rep(i,0,N+1) { Count[i]=0; } int Count1[N+1]; rep(i,0,N+1) { Count1[i]=0; } rep(i,L-1,R) { Count[V[i]]++; Count1[V1[i]]++; } rep(i,1,N+1) { if(Count[i]!=Count1[i]) { printf("LIE"); exit(0); } } printf("TRUTH"); return 0; }