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
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≀ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
On the first line print an integer x β€” the number of boys playing for the first team. On the second line print x integers β€” the individual numbers of boys playing for the first team. On the third line print an integer y β€” the number of boys playing for the second team, on the fourth line print y integers β€” the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≀ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
C
0937a7e2f912fc094cc4275fd47cd457
662a6ae945dc4867bfb3b97e984be918
GNU C
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy", "math" ]
1328886000
["3\n1 2 1", "5\n2 3 3 1 1"]
NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≀ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≀ 2) is fulfilled.
PASSED
1,500
standard input
1 second
The first line contains the only integer n (2 ≀ n ≀ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≀ ai ≀ 104), the i-th number represents the i-th boy's playing skills.
["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"]
#include <stdio.h> #include <stdlib.h> struct pos{ int indice; int valor; }; typedef struct pos pos; void quicksort(pos v[],int primero,int ultimo); int main() { int n,i,cont=0,equipo1,equipo2,p,u; scanf("%d",&n); while (n>100000 || n<2) { scanf("%d",&n); } pos v[n]; equipo1=n/2; if (n%2!=0) { equipo2=equipo1+1; }else{ equipo2=equipo1; } for (i=0;i<n;i++) { scanf("%d",&v[i].valor); while (v[i].valor<1 || v[i].valor>10000) { scanf("%d",&v[i].valor); } v[i].indice=i+1; } p=0; quicksort(v,0,n-1); u=0; printf("%d\n",equipo2); while(cont!=equipo2) { printf("%d ",v[u].indice); u+=2; cont++; } cont=0; p=1; printf("\n%d\n",equipo1); while(cont!=equipo1) { printf("%d ",v[p].indice); p+=2; cont++; } return 0; } void quicksort(pos v[],int primero,int ultimo) { int i,j,central,pivote; pos tmp; central=(primero+ultimo)/2; pivote=v[central].valor; i=primero; j=ultimo; do{ while(v[i].valor<pivote)i++; while(pivote<v[j].valor)j--; if(i<=j) { tmp= v[i]; v[i]=v[j]; v[j]=tmp; i++; j--; } }while(i<=j); if(primero<j) { quicksort(v,primero,j); } if(i<ultimo) { quicksort(v,i,ultimo); } }
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≀ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists.
On the first line print an integer x β€” the number of boys playing for the first team. On the second line print x integers β€” the individual numbers of boys playing for the first team. On the third line print an integer y β€” the number of boys playing for the second team, on the fourth line print y integers β€” the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≀ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order.
C
0937a7e2f912fc094cc4275fd47cd457
e133c54b3a890b62e8f2df04df17f0d4
GNU C
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy", "math" ]
1328886000
["3\n1 2 1", "5\n2 3 3 1 1"]
NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≀ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≀ 2) is fulfilled.
PASSED
1,500
standard input
1 second
The first line contains the only integer n (2 ≀ n ≀ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≀ ai ≀ 104), the i-th number represents the i-th boy's playing skills.
["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"]
#include <stdio.h> struct play{ int skill; int position; }; typedef struct play player; typedef int (*compfn)(const void*, const void*); int compare(player *, player *); int main(){ int n, x=0, y=0; int i, j; scanf("%d", &n); player players[n]; for(i=0; i<n; i++){ scanf("%d", &players[i].skill); players[i].position=i+1; } qsort((void *)&players, n, sizeof(player),(compfn)compare); if(n%2==0){ x = n/2; y = n/2; }else{ x= (n/2)+1; y= n/2; } printf("%d\n", x); for(i=0; i<n; i+=2){ printf("%d ", players[i].position); } printf("\n%d\n", y); for(i=1; i<n; i+=2){ printf("%d ", players[i].position); } return 0; } int compare(player *elem1, player *elem2) { if ( elem1->skill < elem2->skill) return -1; else if (elem1->skill > elem2->skill) return 1; else return 0; }
This is the hard version of the problem. You can find the easy version in the Div. 2 contest. Both versions only differ in the number of times you can ask your friend to taste coffee.This is an interactive problem.You're considering moving to another city, where one of your friends already lives. There are $$$n$$$ cafΓ©s in this city, where $$$n$$$ is a power of two. The $$$i$$$-th cafΓ© produces a single variety of coffee $$$a_i$$$. As you're a coffee-lover, before deciding to move or not, you want to know the number $$$d$$$ of distinct varieties of coffees produced in this city.You don't know the values $$$a_1, \ldots, a_n$$$. Fortunately, your friend has a memory of size $$$k$$$, where $$$k$$$ is a power of two.Once per day, you can ask him to taste a cup of coffee produced by the cafΓ© $$$c$$$, and he will tell you if he tasted a similar coffee during the last $$$k$$$ days.You can also ask him to take a medication that will reset his memory. He will forget all previous cups of coffee tasted. You can reset his memory at most $$$30\ 000$$$ times.More formally, the memory of your friend is a queue $$$S$$$. Doing a query on cafΓ© $$$c$$$ will: Tell you if $$$a_c$$$ is in $$$S$$$; Add $$$a_c$$$ at the back of $$$S$$$; If $$$|S| &gt; k$$$, pop the front element of $$$S$$$. Doing a reset request will pop all elements out of $$$S$$$.Your friend can taste at most $$$\dfrac{3n^2}{2k}$$$ cups of coffee in total. Find the diversity $$$d$$$ (number of distinct values in the array $$$a$$$).Note that asking your friend to reset his memory does not count towards the number of times you ask your friend to taste a cup of coffee.In some test cases the behavior of the interactor is adaptive. It means that the array $$$a$$$ may be not fixed before the start of the interaction and may depend on your queries. It is guaranteed that at any moment of the interaction, there is at least one array $$$a$$$ consistent with all the answers given so far.
null
C
5e02c236446027bca0b32db48766228e
c24a20d22c71652e0897fd066b27390b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "interactive", "graphs" ]
1580652300
["4 2\nN\nN\nY\nN\nN\nN\nN", "8 8\nN\nN\nN\nN\nY\nY"]
NoteIn the first example, the array is $$$a = [1, 4, 1, 3]$$$. The city produces $$$3$$$ different varieties of coffee ($$$1$$$, $$$3$$$ and $$$4$$$).The successive varieties of coffee tasted by your friend are $$$1, 4, \textbf{1}, 3, 3, 1, 4$$$ (bold answers correspond to Y answers). Note that between the two ? 4 asks, there is a reset memory request R, so the answer to the second ? 4 ask is N. Had there been no reset memory request, the answer to the second ? 4 ask is Y.In the second example, the array is $$$a = [1, 2, 3, 4, 5, 6, 6, 6]$$$. The city produces $$$6$$$ different varieties of coffee.The successive varieties of coffee tasted by your friend are $$$2, 6, 4, 5, \textbf{2}, \textbf{5}$$$.
PASSED
3,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 1024$$$, $$$k$$$ and $$$n$$$ are powers of two). It is guaranteed that $$$\dfrac{3n^2}{2k} \le 15\ 000$$$.
["? 1\n? 2\n? 3\n? 4\nR\n? 4\n? 1\n? 2\n! 3", "? 2\n? 6\n? 4\n? 5\n? 2\n? 5\n! 6"]
#include <stdio.h> #define N 1024 int min(int a, int b) { return a < b ? a : b; } int query(int i) { if (i == -1) { printf("R\n"), fflush(stdout); return 0; } else { static char s[2]; printf("? %d\n", i + 1), fflush(stdout); scanf("%s", s); return s[0] == 'N'; } } int ii_[N], cnt1_; int solve(int *ii, int cnt1, int *jj, int cnt2, int k) { int h, g, cnt2_; if (cnt2 == 0) { for (h = 0; h < cnt1; h++) ii_[cnt1_++] = ii[h]; return 0; } for (h = 0; h < cnt1; h++) query(ii[h]); cnt2_ = 0; for (h = 0; h < cnt2; h++) { int j = jj[h]; if (query(j)) jj[cnt2_++] = j; } for (h = 0; h < cnt1 - 1; h++) { int i = ii[h]; if (h == 0) for (g = 0; g < k * 2 + 1 - cnt1 - cnt2; g++) query(ii[cnt1 - 1]); if (query(i)) ii_[cnt1_++] = i; } ii_[cnt1_++] = ii[cnt1 - 1]; query(-1); return cnt2_; } int main() { static int ii[N], jj[N]; int n, k, g, cnt1, cnt2; scanf("%d%d", &n, &k); cnt1 = 0; for (g = 0; g < n / k; g++) { int l = g * k, r = (g + 1) * k, h, i; cnt2 = 0; for (i = l; i < r; i++) if (query(i)) jj[cnt2++] = i; query(-1); cnt1_ = 0; for (h = 0; h < cnt1; h += k) cnt2 = solve(ii + h, min(cnt1 - h, k), jj, cnt2, k); cnt1 = 0; for (h = 0; h < cnt1_; h++) ii[cnt1++] = ii_[h]; for (h = 0; h < cnt2; h++) ii[cnt1++] = jj[h]; } printf("! %d\n", cnt1), fflush(stdout); return 0; }
This is the hard version of the problem. You can find the easy version in the Div. 2 contest. Both versions only differ in the number of times you can ask your friend to taste coffee.This is an interactive problem.You're considering moving to another city, where one of your friends already lives. There are $$$n$$$ cafΓ©s in this city, where $$$n$$$ is a power of two. The $$$i$$$-th cafΓ© produces a single variety of coffee $$$a_i$$$. As you're a coffee-lover, before deciding to move or not, you want to know the number $$$d$$$ of distinct varieties of coffees produced in this city.You don't know the values $$$a_1, \ldots, a_n$$$. Fortunately, your friend has a memory of size $$$k$$$, where $$$k$$$ is a power of two.Once per day, you can ask him to taste a cup of coffee produced by the cafΓ© $$$c$$$, and he will tell you if he tasted a similar coffee during the last $$$k$$$ days.You can also ask him to take a medication that will reset his memory. He will forget all previous cups of coffee tasted. You can reset his memory at most $$$30\ 000$$$ times.More formally, the memory of your friend is a queue $$$S$$$. Doing a query on cafΓ© $$$c$$$ will: Tell you if $$$a_c$$$ is in $$$S$$$; Add $$$a_c$$$ at the back of $$$S$$$; If $$$|S| &gt; k$$$, pop the front element of $$$S$$$. Doing a reset request will pop all elements out of $$$S$$$.Your friend can taste at most $$$\dfrac{3n^2}{2k}$$$ cups of coffee in total. Find the diversity $$$d$$$ (number of distinct values in the array $$$a$$$).Note that asking your friend to reset his memory does not count towards the number of times you ask your friend to taste a cup of coffee.In some test cases the behavior of the interactor is adaptive. It means that the array $$$a$$$ may be not fixed before the start of the interaction and may depend on your queries. It is guaranteed that at any moment of the interaction, there is at least one array $$$a$$$ consistent with all the answers given so far.
null
C
5e02c236446027bca0b32db48766228e
82701b6850f3ce682bfc2324341eea66
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "interactive", "graphs" ]
1580652300
["4 2\nN\nN\nY\nN\nN\nN\nN", "8 8\nN\nN\nN\nN\nY\nY"]
NoteIn the first example, the array is $$$a = [1, 4, 1, 3]$$$. The city produces $$$3$$$ different varieties of coffee ($$$1$$$, $$$3$$$ and $$$4$$$).The successive varieties of coffee tasted by your friend are $$$1, 4, \textbf{1}, 3, 3, 1, 4$$$ (bold answers correspond to Y answers). Note that between the two ? 4 asks, there is a reset memory request R, so the answer to the second ? 4 ask is N. Had there been no reset memory request, the answer to the second ? 4 ask is Y.In the second example, the array is $$$a = [1, 2, 3, 4, 5, 6, 6, 6]$$$. The city produces $$$6$$$ different varieties of coffee.The successive varieties of coffee tasted by your friend are $$$2, 6, 4, 5, \textbf{2}, \textbf{5}$$$.
PASSED
3,000
standard input
1 second
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 1024$$$, $$$k$$$ and $$$n$$$ are powers of two). It is guaranteed that $$$\dfrac{3n^2}{2k} \le 15\ 000$$$.
["? 1\n? 2\n? 3\n? 4\nR\n? 4\n? 1\n? 2\n! 3", "? 2\n? 6\n? 4\n? 5\n? 2\n? 5\n! 6"]
/* upsolve using zigzag */ /* https://codeforces.com/blog/entry/73563 */ #include <stdio.h> #include <string.h> #define N 1024 int query(int i) { if (i == -1) { printf("R\n"), fflush(stdout); return 0; } else { static char s[2]; printf("? %d\n", i + 1), fflush(stdout); scanf("%s", s); return s[0] == 'N'; } } int main() { static char alive[N]; int n, k, m, g, h, i, ans; scanf("%d%d", &n, &k), m = n / k; memset(alive, 1, n * sizeof *alive); for (g = 0; g < m; g++) { query(-1); for (h = 0; h < m; h++) { int g_ = (g + (h % 2 == 0 ? h / 2 : m - (h + 1) / 2)) % m, l = g_ * k, r = (g_ + 1) * k; for (i = l; i < r; i++) if (alive[i] && !query(i)) alive[i] = 0; } } ans = 0; for (i = 0; i < n; i++) if (alive[i]) ans++; printf("! %d\n", ans), fflush(stdout); return 0; }
The only difference between easy and hard versions are constraints on $$$n$$$ and $$$k$$$.You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most $$$k$$$ most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations equals $$$0$$$).Each conversation is between you and some of your friends. There is at most one conversation with any of your friends. So each conversation is uniquely defined by your friend.You (suddenly!) have the ability to see the future. You know that during the day you will receive $$$n$$$ messages, the $$$i$$$-th message will be received from the friend with ID $$$id_i$$$ ($$$1 \le id_i \le 10^9$$$).If you receive a message from $$$id_i$$$ in the conversation which is currently displayed on the smartphone then nothing happens: the conversations of the screen do not change and do not change their order, you read the message and continue waiting for new messages.Otherwise (i.e. if there is no conversation with $$$id_i$$$ on the screen): Firstly, if the number of conversations displayed on the screen is $$$k$$$, the last conversation (which has the position $$$k$$$) is removed from the screen. Now the number of conversations on the screen is guaranteed to be less than $$$k$$$ and the conversation with the friend $$$id_i$$$ is not displayed on the screen. The conversation with the friend $$$id_i$$$ appears on the first (the topmost) position on the screen and all the other displayed conversations are shifted one position down. Your task is to find the list of conversations (in the order they are displayed on the screen) after processing all $$$n$$$ messages.
In the first line of the output print one integer $$$m$$$ ($$$1 \le m \le min(n, k)$$$) β€” the number of conversations shown after receiving all $$$n$$$ messages. In the second line print $$$m$$$ integers $$$ids_1, ids_2, \dots, ids_m$$$, where $$$ids_i$$$ should be equal to the ID of the friend corresponding to the conversation displayed on the position $$$i$$$ after receiving all $$$n$$$ messages.
C
485a1ecf8f569b85327b99382bda9466
04f16d87292f534613dc4bf76dd0b7b6
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "data structures", "implementation" ]
1569940500
["7 2\n1 2 3 2 1 3 2", "10 4\n2 3 3 1 1 2 1 2 3 3"]
NoteIn the first example the list of conversations will change in the following way (in order from the first to last message): $$$[]$$$; $$$[1]$$$; $$$[2, 1]$$$; $$$[3, 2]$$$; $$$[3, 2]$$$; $$$[1, 3]$$$; $$$[1, 3]$$$; $$$[2, 1]$$$. In the second example the list of conversations will change in the following way: $$$[]$$$; $$$[2]$$$; $$$[3, 2]$$$; $$$[3, 2]$$$; $$$[1, 3, 2]$$$; and then the list will not change till the end.
PASSED
1,300
standard input
2 seconds
The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 200)$$$ β€” the number of messages and the number of conversations your smartphone can show. The second line of the input contains $$$n$$$ integers $$$id_1, id_2, \dots, id_n$$$ ($$$1 \le id_i \le 10^9$$$), where $$$id_i$$$ is the ID of the friend which sends you the $$$i$$$-th message.
["2\n2 1", "3\n1 3 2"]
#include <stdio.h> #include <stdlib.h> #define N 200000 #define K 200000 int aa[N]; int compare(const void *a, const void *b) { int i = *(int *) a; int j = *(int *) b; return aa[i] - aa[j]; } int main() { static int ii[N], aa_[N], qq[N]; static char used[N]; int n, k, i, n_, head, cnt; scanf("%d%d", &n, &k); for (i = 0; i < n; i++) { scanf("%d", &aa[i]); ii[i] = i; } qsort(ii, n, sizeof *ii, compare); n_ = 0; for (i = 0; i < n; ) { int a, j; a = aa[ii[i]]; j = i + 1; while (j < n && aa[ii[j]] == a) j++; while (i < j) aa[ii[i++]] = n_; aa_[n_++] = a; } head = cnt = 0; for (i = 0; i < n; i++) { int i_; i_ = aa[i]; if (used[i_]) continue; if (cnt == k) used[qq[cnt--, head++]] = 0; used[i_] = 1; qq[head + cnt++] = i_; } printf("%d\n", cnt); while (cnt--) printf("%d ", aa_[qq[head + cnt]]); printf("\n"); return 0; }
There is a string s, consisting of capital Latin letters. Let's denote its current length as |s|. During one move it is allowed to apply one of the following operations to it: INSERT pos ch β€” insert a letter ch in the string s in the position pos (1 ≀ pos ≀ |s| + 1, A ≀ ch ≀ Z). The letter ch becomes the pos-th symbol of the string s, at that the letters shift aside and the length of the string increases by 1. DELETE pos β€” delete a character number pos (1 ≀ pos ≀ |s|) from the string s. At that the letters shift together and the length of the string decreases by 1. REPLACE pos ch β€” the letter in the position pos of the line s is replaced by ch (1 ≀ pos ≀ |s|, A ≀ ch ≀ Z). At that the length of the string does not change. Your task is to find in which minimal number of moves one can get a t string from an s string. You should also find the sequence of actions leading to the required results.
In the first line print the number of moves k in the given sequence of operations. The number should be the minimal possible one. Then print k lines containing one operation each. Print the operations in the format, described above. If there are several solutions, print any of them.
C
3cef1144dbd24e3e3807ab097b022c13
8b870387855e7fd72628760de2cb3ec3
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "dp" ]
1295626200
["ABA\nABBBA", "ACCEPTED\nWRONGANSWER"]
null
PASSED
2,100
standard input
2 seconds
The first line contains s, the second line contains t. The lines consist only of capital Latin letters, their lengths are positive numbers from 1 to 1000.
["2\nINSERT 3 B\nINSERT 4 B", "10\nREPLACE 1 W\nREPLACE 2 R\nREPLACE 3 O\nREPLACE 4 N\nREPLACE 5 G\nREPLACE 6 A\nINSERT 7 N\nINSERT 8 S\nINSERT 9 W\nREPLACE 11 R"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <stdint.h> // N = 1000 + \n + \0 #define N 1002 enum action { NOTHING, REPLACE, INSERT, DELETE }; typedef struct entry { uint16_t dist : 10; int8_t y : 2; int8_t x : 2; } entry; typedef struct move { enum action action : 2; uint16_t pos : 10; char ch : 8; } move; static entry mat[N][N]; static char s[N] = { 0 }; static char t[N] = { 0 }; static move stack[N]; static int stack_size = 0; static void min_distance(int i, int j) { entry d[4] = { { mat[i - 1][j - 1].dist + 0, 1, 1 }, /* match */ { mat[i - 1][j - 1].dist + 1, 1, 1 }, /* replace */ { mat[i - 1][j - 0].dist + 1, 1, 0 }, /* delete */ { mat[i - 0][j - 1].dist + 1, 0, 1 } /* insert */ }; if (s[i - 1] != t[j - 1]) d[0].dist = N; const entry *min = d; for (int i = 1; i < 4; ++i) min = (d[i].dist < min->dist) ? d + i : min; mat[i][j] = *min; } static void backtrace(int i, int j) { entry e = mat[i][j]; if (e.dist == 0) return; switch (2 * e.y + e.x) { case 0: abort(); case 1: stack[stack_size++] = (move) { INSERT , i + 1, t[j - 1] }; break; case 2: stack[stack_size++] = (move) { DELETE , i, '#' }; break; case 3: if (s[i - 1] != t[j - 1]) stack[stack_size++] = (move) { REPLACE, i, t[j - 1] }; break; } return backtrace(i - e.y, j - e.x); } void print_moves() { move move; int add = 0; int sub = 0; while (stack_size) { move = stack[--stack_size]; switch (move.action) { case NOTHING: break; case REPLACE: printf("REPLACE %d %c\n", move.pos + add - sub, move.ch); break; case INSERT: printf("INSERT %d %c\n", move.pos + add - sub, move.ch); ++add; break; case DELETE: printf("DELETE %d\n", move.pos + add - sub); ++sub; break; } } } int main() { fgets(s, sizeof s, stdin); fgets(t, sizeof t, stdin); //strcpy(s, "ACCEPTED\n"); //strcpy(t, "WRONGANSWER\n"); size_t m = strlen(s) - 1; size_t n = strlen(t) - 1; s[m] = t[n] = '\0'; mat[0][0] = (entry) { 0 }; for (size_t i = 1; i <= m; ++i) mat[i][0] = (entry) { i, 1, 0 }; for (size_t j = 1; j <= n; ++j) mat[0][j] = (entry) { j, 0, 1 }; for (size_t i = 1; i <= m; ++i) { for (size_t j = 1; j <= n; ++j) min_distance(i, j); } /*// print table printf(" "); for (size_t j = 0; j < n; ++j) printf("%c ", t[j]); printf("\n "); for (size_t j = 0; j <= n; ++j) printf("%d ", mat[0][j].dist); putchar('\n'); for (size_t i = 1; i <= m; ++i) { printf("%c ", s[i - 1]); for (size_t j = 0; j <= n; ++j) printf("%d ", mat[i][j].dist); putchar('\n'); }*/ backtrace(m, n); printf("%d\n", mat[m][n].dist); print_moves(); return 0; }
There is a string s, consisting of capital Latin letters. Let's denote its current length as |s|. During one move it is allowed to apply one of the following operations to it: INSERT pos ch β€” insert a letter ch in the string s in the position pos (1 ≀ pos ≀ |s| + 1, A ≀ ch ≀ Z). The letter ch becomes the pos-th symbol of the string s, at that the letters shift aside and the length of the string increases by 1. DELETE pos β€” delete a character number pos (1 ≀ pos ≀ |s|) from the string s. At that the letters shift together and the length of the string decreases by 1. REPLACE pos ch β€” the letter in the position pos of the line s is replaced by ch (1 ≀ pos ≀ |s|, A ≀ ch ≀ Z). At that the length of the string does not change. Your task is to find in which minimal number of moves one can get a t string from an s string. You should also find the sequence of actions leading to the required results.
In the first line print the number of moves k in the given sequence of operations. The number should be the minimal possible one. Then print k lines containing one operation each. Print the operations in the format, described above. If there are several solutions, print any of them.
C
3cef1144dbd24e3e3807ab097b022c13
c24b5f08c24c75f3cec16ea7d04f0b54
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "dp" ]
1295626200
["ABA\nABBBA", "ACCEPTED\nWRONGANSWER"]
null
PASSED
2,100
standard input
2 seconds
The first line contains s, the second line contains t. The lines consist only of capital Latin letters, their lengths are positive numbers from 1 to 1000.
["2\nINSERT 3 B\nINSERT 4 B", "10\nREPLACE 1 W\nREPLACE 2 R\nREPLACE 3 O\nREPLACE 4 N\nREPLACE 5 G\nREPLACE 6 A\nINSERT 7 N\nINSERT 8 S\nINSERT 9 W\nREPLACE 11 R"]
#include <stdlib.h> #include <string.h> #include <stdio.h> #include <stdint.h> #define max(x, y) ((x > y) ? x : y) enum action { REPLACE, NOTHING, INSERT, DELETE }; struct edit { uint16_t dist : 14; enum action parent : 2; }; struct trace { enum action action : 2; uint16_t pos : 10; char ch : 8; }; static struct edit *matrix = NULL; static char *s = NULL; static char *t = NULL; static int m = -1; static int n = -1; static struct trace *stack = NULL; static int stack_size = 0; static char *readline(void) { char *str = malloc(1002); fgets(str, 1002, stdin); return str; } static void distance(void) { struct edit (*mat)[n + 1] = (struct edit (*)[n + 1]) matrix; for (int i = 1; i <= m; ++i) { for (int j = 1; j <= n; ++j) { struct edit d[4] = { { mat[i - 1][j - 1].dist, NOTHING }, { mat[i - 1][j - 1].dist + 1, REPLACE }, { mat[i][j - 1].dist + 1, INSERT }, { mat[i - 1][j].dist + 1, DELETE } }; d[0].dist = (s[i - 1] != t[j - 1]) ? 1002 : d[0].dist; const struct edit *min = d; for (int i = 1; i < 4; ++i) min = (d[i].dist < min->dist) ? d + i : min; mat[i][j] = *min; } } } static void backtrace(void) { struct edit (*mat)[n + 1] = (struct edit (*)[n + 1]) matrix; int i = m; int j = n; while (mat[i][j].dist) { switch (mat[i][j].parent) { case REPLACE: stack[stack_size++] = (struct trace) { REPLACE, i, t[j - 1] }; case NOTHING: --i, --j; break; case INSERT: stack[stack_size++] = (struct trace) { INSERT, i + 1, t[j - 1] }; --j; break; case DELETE: stack[stack_size++] = (struct trace) { DELETE, i, t[j - 1] }; --i; } } } static void print_ops(void) { int add = 0, sub = 0; while (stack_size) { struct trace t = stack[--stack_size]; switch (t.action) { case NOTHING: abort(); break; case REPLACE: printf("REPLACE %d %c\n", t.pos + add - sub, t.ch); break; case INSERT: printf("INSERT %d %c\n", t.pos + add++ - sub, t.ch); break; case DELETE: printf("DELETE %d\n", t.pos + add - sub++); break; } } } int main() { s = readline(); t = readline(); m = strlen(s) - 1; n = strlen(t) - 1; s[m] = t[n] = '\0'; struct edit (*mat)[n + 1] = malloc((m + 1) * sizeof *mat); stack = malloc(max(m, n) * sizeof *stack); mat[0][0] = (struct edit) { 0, NOTHING }; for (int i = 1; i <= m; ++i) mat[i][0] = (struct edit) { i, DELETE }; for (int j = 1; j <= n; ++j) mat[0][j] = (struct edit) { j, INSERT }; matrix = &mat[0][0]; distance(); printf("%d\n", mat[m][n].dist); backtrace(); print_ops(); return 0; }
There is a string s, consisting of capital Latin letters. Let's denote its current length as |s|. During one move it is allowed to apply one of the following operations to it: INSERT pos ch β€” insert a letter ch in the string s in the position pos (1 ≀ pos ≀ |s| + 1, A ≀ ch ≀ Z). The letter ch becomes the pos-th symbol of the string s, at that the letters shift aside and the length of the string increases by 1. DELETE pos β€” delete a character number pos (1 ≀ pos ≀ |s|) from the string s. At that the letters shift together and the length of the string decreases by 1. REPLACE pos ch β€” the letter in the position pos of the line s is replaced by ch (1 ≀ pos ≀ |s|, A ≀ ch ≀ Z). At that the length of the string does not change. Your task is to find in which minimal number of moves one can get a t string from an s string. You should also find the sequence of actions leading to the required results.
In the first line print the number of moves k in the given sequence of operations. The number should be the minimal possible one. Then print k lines containing one operation each. Print the operations in the format, described above. If there are several solutions, print any of them.
C
3cef1144dbd24e3e3807ab097b022c13
c0b39bf66ec4bb5f9cbfe7e2601ab8fb
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "dp" ]
1295626200
["ABA\nABBBA", "ACCEPTED\nWRONGANSWER"]
null
PASSED
2,100
standard input
2 seconds
The first line contains s, the second line contains t. The lines consist only of capital Latin letters, their lengths are positive numbers from 1 to 1000.
["2\nINSERT 3 B\nINSERT 4 B", "10\nREPLACE 1 W\nREPLACE 2 R\nREPLACE 3 O\nREPLACE 4 N\nREPLACE 5 G\nREPLACE 6 A\nINSERT 7 N\nINSERT 8 S\nINSERT 9 W\nREPLACE 11 R"]
#include <stdlib.h> #include <string.h> #include <stdio.h> #include <stdint.h> #define max(x, y) ((x > y) ? x : y) enum action { REPLACE, NOTHING, INSERT, DELETE }; struct edit { uint16_t dist : 10; uint16_t parent : 2; }; struct trace { enum action action : 2; uint16_t pos : 10; char ch : 8; }; static struct edit mat[1001][1001]; static char s[1002]; static char t[1002]; static int m = -1; static int n = -1; static struct trace stack[1000]; static int stack_size = 0; static void distance(void) { for (int i = 1; i <= m; ++i) { for (int j = 1; j <= n; ++j) { struct edit d[4] = { { mat[i - 1][j - 1].dist, NOTHING }, { mat[i - 1][j - 1].dist + 1, REPLACE }, { mat[i][j - 1].dist + 1, INSERT }, { mat[i - 1][j].dist + 1, DELETE } }; d[0].dist = (s[i - 1] != t[j - 1]) ? 1002 : d[0].dist; const struct edit *min = d; for (int i = 1; i < 4; ++i) min = (d[i].dist < min->dist) ? d + i : min; mat[i][j] = *min; } } } static void backtrace(void) { int i = m; int j = n; while (mat[i][j].dist) { switch (mat[i][j].parent) { case REPLACE: stack[stack_size++] = (struct trace) { REPLACE, i, t[j - 1] }; case NOTHING: --i, --j; break; case INSERT: stack[stack_size++] = (struct trace) { INSERT, i + 1, t[j - 1] }; --j; break; case DELETE: stack[stack_size++] = (struct trace) { DELETE, i, t[j - 1] }; --i; } } } static void print_ops(void) { int add = 0, sub = 0; while (stack_size) { struct trace t = stack[--stack_size]; switch (t.action) { case NOTHING: abort(); break; case REPLACE: printf("REPLACE %d %c\n", t.pos + add - sub, t.ch); break; case INSERT: printf("INSERT %d %c\n", t.pos + add++ - sub, t.ch); break; case DELETE: printf("DELETE %d\n", t.pos + add - sub++); break; } } } int main() { fgets(s, sizeof s, stdin); fgets(t, sizeof t, stdin); m = strlen(s) - 1; n = strlen(t) - 1; s[m] = t[n] = '\0'; mat[0][0] = (struct edit) { 0, NOTHING }; for (int i = 1; i <= m; ++i) mat[i][0] = (struct edit) { i, DELETE }; for (int j = 1; j <= n; ++j) mat[0][j] = (struct edit) { j, INSERT }; distance(); printf("%d\n", mat[m][n].dist); backtrace(); print_ops(); return 0; }
Arpa has found a list containing n numbers. He calls a list bad if and only if it is not empty and gcd (see notes section for more information) of numbers in the list is 1.Arpa can perform two types of operations: Choose a number and delete it with cost x. Choose a number and increase it by 1 with cost y. Arpa can apply these operations to as many numbers as he wishes, and he is allowed to apply the second operation arbitrarily many times on the same number.Help Arpa to find the minimum possible cost to make the list good.
Print a single integer: the minimum possible cost to make the list good.
C
41a1b33baa83aea57423b160247adcb6
d93ac37a6a9efef458b633b6a53091b9
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation", "number theory" ]
1504535700
["4 23 17\n1 17 17 16", "10 6 2\n100 49 71 73 66 96 8 60 41 63"]
NoteIn example, number 1 must be deleted (with cost 23) and number 16 must increased by 1 (with cost 17).A gcd (greatest common divisor) of a set of numbers is the maximum integer that divides all integers in the set. Read more about gcd here.
PASSED
2,100
standard input
2 seconds
First line contains three integers n, x and y (1 ≀ n ≀ 5Β·105, 1 ≀ x, y ≀ 109)Β β€” the number of elements in the list and the integers x and y. Second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106)Β β€” the elements of the list.
["40", "10"]
//Preface Version -- 2017.9.14 #include <stdio.h> #include <string.h> #include <ctype.h> #define LL long long #define uLL unsigned long long #define uL unsigned long #define uC unsigned char #define NODES 1000007 #define NNNN 3000007 #define MemoryStackTotal 100 #define error 1e-8 static unsigned char BakaMemoryStack[MemoryStackTotal];static unsigned char *MemoryStackTop=BakaMemoryStack;void *Allocates(unsigned long size){MemoryStackTop+=size;return MemoryStackTop-size;}void Releases(unsigned long size){MemoryStackTop-=size;if (MemoryStackTop<BakaMemoryStack) {MemoryStackTop=BakaMemoryStack;}} void swap(uL *a,uL *b){*a=*a^*b;*b=*a^*b;*a=*a^*b;}void swap64(uLL *a,uLL *b){*a=*a^*b;*b=*a^*b;*a=*a^*b;}uL bsf(uL a){__asm__ __volatile__("bsfl %0,%0":"+r"(a));return a;}uL bsr(uL a){__asm__ __volatile__("bsrl %0,%0":"+r"(a));return a;}uL imin(uL a,uL b){__asm__ __volatile__("cmpl %0,%1\n""cmovll %1,%0":"+&r"(a):"g"(b));return a;}uL imax(uL a,uL b){__asm__ __volatile__("cmpl %0,%1\n""cmovgl %1,%0":"+&r"(a):"g"(b));return a;}uL min(uL a,uL b){__asm__ __volatile__("cmpl %0,%1\n""cmovbl %1,%0":"+&r"(a):"g"(b));return a;}uL max(uL a,uL b){__asm__ __volatile__("cmpl %0,%1\n""cmoval %1,%0":"+&r"(a):"g"(b));return a;} void print(long *a,long size){long i;for (i=0;i<size;i++){printf("%ld ",a[i]);}printf("%ld\n",a[i]);}void printll(LL *a,long size){long i;for (i=0;i<size;i++){printf("%I64d ",a[i]);}printf("%I64d\n",a[i]);} //uLL bsf64(uLL a){__asm__ __volatile__("bsfq %0,%0":"+r"(a));return a;}uLL bsr64(uLL a){__asm__ __volatile__("bsrq %0,%0":"+r"(a));return a;}uLL min63(uLL a,uLL b){__asm__ __volatile__("cmpq %0,%1\n""cmovlq %1,%0":"+&r"(a):"g"(b));return a;}uLL max63(uLL a,uLL b){__asm__ __volatile__("cmpq %0,%1\n""cmovgq %1,%0":"+&r"(a):"g"(b));return a;}uLL min64(uLL a,uLL b){__asm__ __volatile__("cmpq %0,%1\n""cmovbq %1,%0":"+&r"(a):"g"(b));return a;}uLL max64(uLL a,uLL b){__asm__ __volatile__("cmpq %0,%1\n""cmovaq %1,%0":"+&r"(a):"g"(b));return a;} void mergesort(long *ds,int (*compare)(long a,long b),long size){long i,j,k,s,b,e;long *ms=(long*)Allocates(sizeof(long)*(size+1)); for (k=1;k<=size;k=k<<1) { for (i=1;i+k<=size;i+=k<<1) { s=i;b=i+k;e=b+k-1; if (e>size) {e=size;} for (j=1;(s<i+k)&&(b<=e);j++) { if (compare(ds[s],ds[b])<=0) { ms[j]=ds[s++]; } else { ms[j]=ds[b++]; } } for (b=i+k-1;b>=s;b--) { ds[e--]=ds[b]; } for (b=1;b<j;b++) { ds[i+b-1]=ms[b]; } } } Releases(sizeof(long)*(size+1));} long prime[NNNN]; void euler(long n) { long i,j,a; memset(prime,0,sizeof(long)*(n+1)); for (i=2,*prime=0;i<=n;i++) { if (prime[i]==0) { prime[++(*prime)]=i; } for (j=1;j<=*prime;j++) { if (prime[j]*i>n) {break;} prime[i*prime[j]]=prime[j]; if (prime[j]==prime[i]) {break;} } } } long count[NNNN],num[NNNN]; LL sum[NNNN]; int main() { long i,j,k,a,b,c,n,x,y,skip,low,up,l; LL ans,t1,t2,t3,preface; // freopen("in.in","r",stdin); scanf("%ld %ld %ld",&n,&x,&y); up=0;low=0x7FFFFFFF;skip=x/y; preface=0; for (i=1;i<=n;i++) { scanf("%ld",&num[i]); // if (num[i]==1) {i--;n--;preface+=(LL)x;continue;} if (num[i]>up) {up=num[i];} if (num[i]<low) {low=num[i];} } // printf("%ld\n",n); if (n>0) { euler(up+1000); memset(count,0,sizeof(long)*(up<<1)); for (i=1;i<=n;i++) { count[num[i]]+=1; } // print(count,up); /* *num=0; for (i=low;i<=up;i++) { for (j=1;j<=count[i];j++) { num[++(*num)]=i; } }*/ memset(sum,0,sizeof(LL)*(up<<1)); for (i=low;i<=(up<<1);i++) { sum[i]=sum[i-1]+(LL)count[i]*i; } // printll(sum,up); for (i=low;i<=(up<<1);i++) { count[i]=count[i-1]+count[i]; } // print(count,up); ans=(LL)0x7FFFFFFFFFFFFFFF; // printf("%ld %ld\n",low,up); for (i=1;i<=*prime;i++) { // printf("%ld\n",prime[i]); t1=0; for (j=prime[i];;j+=prime[i]) { k=j-skip-1;l=j-prime[i]; if (k<l) {k=l;} t1+=(LL)x*(count[k]-count[l])+(LL)y*((LL)j*(count[j-1]-count[k])-(sum[j-1]-sum[k])); // printf("%lld %ld %ld\n",t1,j,k); if (j>up) {break;} } // printf("*%lld\n",t1); if (t1<ans) {ans=t1;} if (prime[i]>up) {break;} } } else {ans=0;} printf("%lld\n",ans); return 0; }
Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and n don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.Help Inna maximize the total joy the hares radiate. :)
In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.
C
99cf10673cb275ad3b90bcd3757ecd47
4d62a8b0125bba06e517db2141937fb4
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy" ]
1382715000
["4\n1 2 3 4\n4 3 2 1\n0 1 1 0", "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3", "3\n1 1 1\n1 2 1\n1 1 1"]
null
PASSED
1,800
standard input
2 seconds
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≀ ai, bi, ci ≀ 105. Number ai in the first line shows the joy that hare number i gets if his adjacent hares are both hungry. Number bi in the second line shows the joy that hare number i radiates if he has exactly one full adjacent hare. Number сi in the third line shows the joy that hare number i radiates if both his adjacent hares are full.
["13", "44", "4"]
# include <stdio.h> # include <string.h> int list[3002][3]; int din[3][3002], n; int max(int a, int b) { return a > b ? a : b; } int solve(int comido, int position ){ int res = 0; if( position == n ) return 0; if( din[comido][position] != -1 ) return din[comido][position]; if( comido == 0){ if( position != n - 1) res = max(res, solve( 0, position + 1 ) + list[ position ][ 1 ]); res = max(res, solve( 1, position + 1 ) + list[ position ][ 0 ]); } if( comido == 1){ if( position != n - 1) res = max(res, solve( 0, position + 1 ) + list[ position ][ 2 ]); res = max(res, solve( 1, position + 1 ) + list[ position ][ 1 ]); } return din[comido][position] = res; } main(){ int x, y; scanf("%d", &n); memset( din, -1, sizeof( din )); for( x = 0; x < 3; x++) for( y = 0; y < n; y++) scanf("%d", &list[y][x]); if( n == 1) printf("%d\n", list[0][0]); else{ printf("%d\n", max( solve( 0, 1 ) + list[0][1] , solve(1, 1)+list[0][0])); } return 0; }
Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and n don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.Help Inna maximize the total joy the hares radiate. :)
In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.
C
99cf10673cb275ad3b90bcd3757ecd47
515157fe71376bf48e153ff413aea265
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy" ]
1382715000
["4\n1 2 3 4\n4 3 2 1\n0 1 1 0", "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3", "3\n1 1 1\n1 2 1\n1 1 1"]
null
PASSED
1,800
standard input
2 seconds
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≀ ai, bi, ci ≀ 105. Number ai in the first line shows the joy that hare number i gets if his adjacent hares are both hungry. Number bi in the second line shows the joy that hare number i radiates if he has exactly one full adjacent hare. Number сi in the third line shows the joy that hare number i radiates if both his adjacent hares are full.
["13", "44", "4"]
#include<stdio.h> int s[3000],m[3000]; main() { int n,i,temp1,temp2; scanf("%d",&n); int a[n],b[n],c[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) scanf("%d",&b[i]); for(i=0;i<n;i++) scanf("%d",&c[i]); if(n==1) { printf("%d",a[0]); return 0; } s[0]=b[0];m[0]=a[0]; for(i=1;i<n-1;i++) { if(s[i-1]+b[i]<m[i-1]+c[i]) s[i]=m[i-1]+c[i]; else s[i]=s[i-1]+b[i]; if(s[i-1]+a[i]<m[i-1]+b[i]) m[i]=m[i-1]+b[i]; else m[i]=s[i-1]+a[i]; } if(s[n-2]+a[n-1]<m[n-2]+b[n-1]) printf("%d",m[n-2]+b[n-1]); else printf("%d",s[n-2]+a[n-1]); return 0; }
Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and n don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.Help Inna maximize the total joy the hares radiate. :)
In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.
C
99cf10673cb275ad3b90bcd3757ecd47
5aaaeb83822f9696ca77fe6e1cd34e2f
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy" ]
1382715000
["4\n1 2 3 4\n4 3 2 1\n0 1 1 0", "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3", "3\n1 1 1\n1 2 1\n1 1 1"]
null
PASSED
1,800
standard input
2 seconds
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≀ ai, bi, ci ≀ 105. Number ai in the first line shows the joy that hare number i gets if his adjacent hares are both hungry. Number bi in the second line shows the joy that hare number i radiates if he has exactly one full adjacent hare. Number сi in the third line shows the joy that hare number i radiates if both his adjacent hares are full.
["13", "44", "4"]
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) int main(){ int n; int a[3000], b[3000], c[3000]; int dp[3001]; int i, j, add, go; scanf("%d",&n); rep(i,n) scanf("%d",a+i); rep(i,n) scanf("%d",b+i); rep(i,n) scanf("%d",c+i); rep(i,n+1) dp[i] = 0; rep(i,n){ add = 0; REP(j,i,n){ if(j==0 || j > i) go = dp[i] + add + a[j]; else go = dp[i] + add + b[j]; if(dp[j+1] < go) dp[j+1] = go; if(j==0 || j > i) add += b[j]; else add += c[j]; } } printf("%d\n",dp[n]); return 0; }
Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and n don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.Help Inna maximize the total joy the hares radiate. :)
In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.
C
99cf10673cb275ad3b90bcd3757ecd47
5eb6c563da544c52dc89bd8caadf7811
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy" ]
1382715000
["4\n1 2 3 4\n4 3 2 1\n0 1 1 0", "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3", "3\n1 1 1\n1 2 1\n1 1 1"]
null
PASSED
1,800
standard input
2 seconds
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≀ ai, bi, ci ≀ 105. Number ai in the first line shows the joy that hare number i gets if his adjacent hares are both hungry. Number bi in the second line shows the joy that hare number i radiates if he has exactly one full adjacent hare. Number сi in the third line shows the joy that hare number i radiates if both his adjacent hares are full.
["13", "44", "4"]
#include<stdio.h> #include<string.h> #define max(a,b) (a > b ? a : b) int n,a[3005],b[3005],c[3005]; int dp[3005][2]; int rec(int ind, int last) { if(ind==n-1) return (last==1 ? b[ind] : a[ind]); if(dp[ind][last]!=-1) return dp[ind][last]; if(last) return dp[ind][last] = max(b[ind]+rec(ind+1,1),c[ind]+rec(ind+1,0)); else return dp[ind][last] = max(a[ind]+rec(ind+1,1),b[ind]+rec(ind+1,0)); } int main() { int i; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) scanf("%d",&b[i]); for(i=0;i<n;i++) scanf("%d",&c[i]); memset(dp,-1,sizeof(dp)); printf("%d\n",rec(0,0)); return 0; }
Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and n don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.Help Inna maximize the total joy the hares radiate. :)
In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.
C
99cf10673cb275ad3b90bcd3757ecd47
0a6ac31006d9e6b0a92183dcce85ff3b
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy" ]
1382715000
["4\n1 2 3 4\n4 3 2 1\n0 1 1 0", "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3", "3\n1 1 1\n1 2 1\n1 1 1"]
null
PASSED
1,800
standard input
2 seconds
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≀ ai, bi, ci ≀ 105. Number ai in the first line shows the joy that hare number i gets if his adjacent hares are both hungry. Number bi in the second line shows the joy that hare number i radiates if he has exactly one full adjacent hare. Number сi in the third line shows the joy that hare number i radiates if both his adjacent hares are full.
["13", "44", "4"]
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* Author : Sarvesh Mahajan IIIT, Hyderabad */ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> //#define max(a,b) ((a)>(b))?(a):(b) int max(int a,int b) { return a>b?a:b; } #define min(a,b) ((a)<(b))?(a):(b) #define si(n) scanf("%d",&n) #define ss(s) scanf("%s",s) #define sort(a,n) qsort(a,n,sizeof(int),compare) #define pi(n) printf("%d ",n) #define ps(s) printf("%s",s) #define loop(i,n) for(i=0;i<n;i++) #define Loop(i,n) for(i=1;i<=n;i++) #define For(i,j,n) for(i=j;i<=n;++i) typedef long long int lld; #define MAX 100005 int a[MAX],b[MAX],c[MAX],dp[MAX][2]; int compare(const void *a,const void *b) { return *(int *)a-*(int *)b; } int main(void) { int i,n,ans,k,l,m,t; // si(t); // while(t--) // { si(n); loop(i,n) si(a[i]); loop(i,n) si(b[i]); loop(i,n) si(c[i]); dp[0][0]=a[0]; dp[0][1]=0; dp[1][0]=a[1]+b[0]; dp[1][1]=a[0]+b[1]; for(i=2;i<n;++i) { dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][1]); dp[i][0]=a[i]+max((dp[i-1][0]+b[i-1]-a[i-1]),(dp[i-1][1]+c[i-1]-b[i-1])); // pi(dp[i][1]); } pi(max(dp[n-1][0],dp[n-1][1])); // } return 0; }
Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more. Dima felt so grateful to Inna about the present that he decided to buy her n hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to n from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and n don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.Help Inna maximize the total joy the hares radiate. :)
In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.
C
99cf10673cb275ad3b90bcd3757ecd47
7d70229b98c54d2bbb8d54a727121b50
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy" ]
1382715000
["4\n1 2 3 4\n4 3 2 1\n0 1 1 0", "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3", "3\n1 1 1\n1 2 1\n1 1 1"]
null
PASSED
1,800
standard input
2 seconds
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of hares. Then three lines follow, each line has n integers. The first line contains integers a1 a2 ... an. The second line contains b1, b2, ..., bn. The third line contains c1, c2, ..., cn. The following limits are fulfilled: 0 ≀ ai, bi, ci ≀ 105. Number ai in the first line shows the joy that hare number i gets if his adjacent hares are both hungry. Number bi in the second line shows the joy that hare number i radiates if he has exactly one full adjacent hare. Number сi in the third line shows the joy that hare number i radiates if both his adjacent hares are full.
["13", "44", "4"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int max(int a, int b) { return (a > b) ? a : b; } int n; int data[3001][3]; int cache[3001][2][2]; void init() { scanf("%d", &n); int i; int j; for (j = 0; j < 3; j++) { for (i = 1; i <= n; i++) { scanf("%d", &data[i][j]); } } for (i = 1; i <= n; i++) { cache[i][0][0] = -1; cache[i][1][0] = -1; cache[i][1][1] = -1; cache[i][0][1] = -1; } } // ith hare, previous is full? p int dp(int i, int p, int a) { if (cache[i][p][a] >= 0) return cache[i][p][a]; int result; if (i == n) { if (p) { result = data[i][1]; } else { result = data[i][0]; } cache[i][p][a] = result; return result; } if (p && a) { int h = dp(i + 1, 0, 0); int f = dp(i + 1, 0, 1); result = data[i][2] + max(h, f); } else if (!p && a) { int h = dp(i + 1, 0, 0); int f = dp(i + 1, 0, 1); result = data[i][1] + max(h,f); } else if (p && !a) { int h = dp(i + 1, 1, 0); int f = dp(i + 1, 1, 1); result = data[i][1] + max(h,f); } else { int h = dp(i + 1, 1, 0); int f = dp(i + 1, 1, 1); result = data[i][0] + max(h,f); } cache[i][p][a] = result; return result; } int main () { init(); printf("%d\n", max(dp(1,0,0), dp(1,0,1))); return 0; }
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?
In a single line of print the answerΒ β€” "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
C
4b352854008a9378551db60b76d33cfa
c7a877da49e5f408eb08f73e1d6a961b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "greedy", "games", "sortings", "data structures", "binary search", "strings" ]
1484499900
["5 1\npolandball\nis\na\ncool\ncharacter\nnope", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "1 2\na\na\nb"]
NoteIn the first example PolandBall knows much more words and wins effortlessly.In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
PASSED
1,100
standard input
1 second
The first input line contains two integers n and m (1 ≀ n, m ≀ 103)Β β€” number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per lineΒ β€” words familiar to PolandBall. Then m strings follow, one per lineΒ β€” words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.
["YES", "YES", "NO"]
#include<stdio.h> #include<string.h> #define Max_limit 500 main(){ long int n,m; scanf("%ld %ld",&n,&m); char arr1[n][Max_limit]; //storing n words each with character not more than 500 in an array. for(long int i=0;i<n;i++){ scanf("%s",arr1[i]); } char arr2[m][Max_limit]; //storing m words each with character not more than 500 in an array. for(long int i=0;i<m;i++){ scanf("%s",arr2[i]); } long int flag=0; for(long int i=0;i<n;i++){ for(long int j=0;j<m;j++){ if(strcmp(arr1[i],arr2[j])==0){ flag++; break; } } } //end: if(n>m|| n==m&&flag%2){ printf("YES"); } else{ printf("NO"); } /*else if(n==m && flag==1){ printf("YES"); }else if(n==m && flag==0){ printf("NO"); }else if(n<m){ printf("NO"); }*/ }
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?
In a single line of print the answerΒ β€” "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
C
4b352854008a9378551db60b76d33cfa
7a0c9ef5330d3d484215366a489ee07f
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "greedy", "games", "sortings", "data structures", "binary search", "strings" ]
1484499900
["5 1\npolandball\nis\na\ncool\ncharacter\nnope", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "1 2\na\na\nb"]
NoteIn the first example PolandBall knows much more words and wins effortlessly.In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
PASSED
1,100
standard input
1 second
The first input line contains two integers n and m (1 ≀ n, m ≀ 103)Β β€” number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per lineΒ β€” words familiar to PolandBall. Then m strings follow, one per lineΒ β€” words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.
["YES", "YES", "NO"]
#include<stdio.h> #include<ctype.h> #include<string.h> #include<stdlib.h> int main() { int n,m,i; scanf("%d %d",&n,&m); char str[n][501]; char str1[m][501]; for(i=0;i<n;i++) { scanf("%s",str[i]); } for(i=0;i<m;i++) { scanf("%s",str1[i]); } int j,common=0; for(i=0;i<n;i++) { for(j=0;j<m;j++) { if((strcmp(str[i],str1[j])) == 0) common++; } } //if( n > m) //{ // printf("YES"); //} //else //{ n=n-common; m=m-common; if(common%2 == 1) { m--; } if( n > m) printf("YES"); else printf("NO"); // printf("\n %d",common); return 0; }
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?
In a single line of print the answerΒ β€” "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
C
4b352854008a9378551db60b76d33cfa
c046600447c343167bb897feda9d3ab3
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "greedy", "games", "sortings", "data structures", "binary search", "strings" ]
1484499900
["5 1\npolandball\nis\na\ncool\ncharacter\nnope", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "1 2\na\na\nb"]
NoteIn the first example PolandBall knows much more words and wins effortlessly.In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
PASSED
1,100
standard input
1 second
The first input line contains two integers n and m (1 ≀ n, m ≀ 103)Β β€” number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per lineΒ β€” words familiar to PolandBall. Then m strings follow, one per lineΒ β€” words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.
["YES", "YES", "NO"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 501 typedef struct { int count; char word[N]; } item; item A[2001]; int main() { int p, v; char s[501]; int i, j; scanf("%d %d", &p, &v); for (i = 0; i < p; i++) { scanf("%s", s); //(A[i]).word = s; strcpy(A[i].word, s); //printf("%s\n", A[i].word); (A[i]).count = 2; //printf("%d\n", A[i].count); } int len = p; //int d = 0; //printf("%s\n%s\n", A[0].word, A[1].word); for (j = 0; j < v; j++) { scanf("%s", s); for(i = 0; i < p; i++) { if (strcmp(A[i].word, s) == 0) { A[i].count = 1; break; } } if (i >= p) { strcpy(A[len].word, s); A[len].count = 3; len++; } } int k = 0; p = 0; v = 0; for (i = 0; i < len; i++) { if (A[i].count == 1) k++; if (A[i].count == 3) v++; if (A[i].count == 2) p++; } p += k/2 + k%2; v += k/2; if (p > v) printf("YES\n"); else printf("NO\n"); return 0; }
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?
In a single line of print the answerΒ β€” "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
C
4b352854008a9378551db60b76d33cfa
91418075fe8e261bd02c5710771a5548
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "greedy", "games", "sortings", "data structures", "binary search", "strings" ]
1484499900
["5 1\npolandball\nis\na\ncool\ncharacter\nnope", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "1 2\na\na\nb"]
NoteIn the first example PolandBall knows much more words and wins effortlessly.In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
PASSED
1,100
standard input
1 second
The first input line contains two integers n and m (1 ≀ n, m ≀ 103)Β β€” number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per lineΒ β€” words familiar to PolandBall. Then m strings follow, one per lineΒ β€” words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.
["YES", "YES", "NO"]
#include <stdio.h> #include <string.h> int main() { int n, m, i, j, e, common; scanf("%i %i", &n, &m); while (getchar() != '\n') ; char a[n][500], b[m][500]; for (i = 0; i < n; i++) gets(a[i]); for (i = 0; i < m; i++) gets(b[i]); if (n < m) { for (i = 0; i < n; i++) { e = 0, j = 0; while (!e && j < m) { if (strcmp(a[i], b[j]) == 0) common++, e++; j++; } } } else { for (i = 0; i < m; i++) { e = 0, j = 0; while (!e && j < n) { if (strcmp(a[j], b[i]) == 0) common++, e++; j++; } } } if (common % 2) n++; if (n > m) { printf("YES"); return 0; } printf("NO"); return 0; }
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?
In a single line of print the answerΒ β€” "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
C
4b352854008a9378551db60b76d33cfa
1b73357d4e1b6b3eb6150077e6ad628f
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "greedy", "games", "sortings", "data structures", "binary search", "strings" ]
1484499900
["5 1\npolandball\nis\na\ncool\ncharacter\nnope", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "1 2\na\na\nb"]
NoteIn the first example PolandBall knows much more words and wins effortlessly.In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
PASSED
1,100
standard input
1 second
The first input line contains two integers n and m (1 ≀ n, m ≀ 103)Β β€” number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per lineΒ β€” words familiar to PolandBall. Then m strings follow, one per lineΒ β€” words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.
["YES", "YES", "NO"]
#include <stdio.h> #include <stdlib.h> int main(int argc, char** argv) { int i, j, n, m, x = 0; scanf("%d%d", &n, &m); char p[n][500], e[m][500], s[500]; gets(s); for (i = 0; i < n; i++) { gets(p[i]); } for (i = 0; i < m; i++) { gets(e[i]); } if (n < m) { printf("NO"); } else if (n > m) { printf("YES"); } else { for (i = 0; i < n; i++) { for (j = x; j < m; j++) { if (strcmp(p[i], e[j]) == 0) { x++; } } } if (x % 2 == 1) printf("YES"); else printf("NO"); } return (EXIT_SUCCESS); }
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?
In a single line of print the answerΒ β€” "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.
C
4b352854008a9378551db60b76d33cfa
4f9f1e23f3282e23bd24d0164fb2a666
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "greedy", "games", "sortings", "data structures", "binary search", "strings" ]
1484499900
["5 1\npolandball\nis\na\ncool\ncharacter\nnope", "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska", "1 2\na\na\nb"]
NoteIn the first example PolandBall knows much more words and wins effortlessly.In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.
PASSED
1,100
standard input
1 second
The first input line contains two integers n and m (1 ≀ n, m ≀ 103)Β β€” number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per lineΒ β€” words familiar to PolandBall. Then m strings follow, one per lineΒ β€” words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.
["YES", "YES", "NO"]
#include<stdio.h> int main() { int n,m,k=0,i,j,d; scanf("%d %d",&n,&m); char S[n][501],T[m][501]; for(i=0;i<n;i++) { scanf("%s",S[i]); } for(j=0;j<m;j++) { scanf("%s",T[j]); for(i=0;i<n;i++) { d=strcmp(S[i],T[j]); { if(d==0) { break; } } } if(i!=n) { k++; } } if(k%2==1) { m--; } if(m<n) { printf("YES\n"); } else { printf("NO\n"); } }
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.Help Polycarpus and find any suitable method to cut the public key.
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β€” the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them. If there is no answer, print in a single line "NO" (without the quotes).
C
695418026140545863313f5f3cc1bf00
c12bed68e2e1a843452c9467281644c6
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "number theory", "brute force", "math", "strings" ]
1416733800
["116401024\n97 1024", "284254589153928171911281811000\n1009 1000", "120\n12 1"]
null
PASSED
1,700
standard input
1 second
The first line of the input contains the public key of the messenger β€” an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 ≀ a, b ≀ 108).
["YES\n11640\n1024", "YES\n2842545891539\n28171911281811000", "NO"]
#include<string.h> #include<math.h> #include<stdlib.h> typedef long long ll; #define mod 1000000007 #define tam 10000010 char string [tam]; int left[tam],right[tam]; int main(){ int a,b,size; int n = 1; int i,k = 0; int flag = 0; scanf("%s",string); scanf("%lld %lld",&a,&b); size = strlen(string); left[0] = (string[0]-'0')%a; right[size-1] = (string[size-1]-'0')%b; i = 1; while(i<size-1){ left[i] = (left[i-1]*10+string[i]-'0')%a; i++; } //while(i = size-2 && i>0) for(int i=size-2;i>0;i--){ n = (n*10)%b; right[i] = ( (string[i]-'0')*n+right[i+1] )%b; //i--; } i = 0; while(i<size-1){ if(left[i] == 0 && right[i+1] == 0 && string[i+1]!='0' ){ k = i; flag = 1; break; } i++; } switch(flag){ case 1: printf("YES\n"); i = 0; while(i<=k){ printf("%c",string[i]); i++; } printf("\n"); i = k+1; while(i<size){ printf("%c",string[i]); i++; } printf("\n"); break; case 0: printf("NO\n"); } return 0; }
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.Help Polycarpus and find any suitable method to cut the public key.
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β€” the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them. If there is no answer, print in a single line "NO" (without the quotes).
C
695418026140545863313f5f3cc1bf00
a52219af080f7511e756088cb2771460
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "number theory", "brute force", "math", "strings" ]
1416733800
["116401024\n97 1024", "284254589153928171911281811000\n1009 1000", "120\n12 1"]
null
PASSED
1,700
standard input
1 second
The first line of the input contains the public key of the messenger β€” an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 ≀ a, b ≀ 108).
["YES\n11640\n1024", "YES\n2842545891539\n28171911281811000", "NO"]
#include <stdio.h> #include <string.h> #define MAXL 1048576 char in[MAXL], *input = in; int mod_b[MAXL]; int main() { int a, b; scanf("%s%d%d", input, &a, &b); long long left = 0, right = 0; int len = strlen(input); /* if the string length is smaller than 1, it's impossible to parse the string into two parts*/ if(len <= 1 || input[0] == '0') { printf("NO\n"); return 0; } for(int i = len - 1, e = 1; i >= 0; --i, e = (e * 10) % b) { mod_b[i] = right = (right + (input[i] - '0') * e) % b; if(input[i] == '0') { mod_b[i] = -1; // no leading zero } } for(int i = 0; i < len - 1; ++i) { left = (left * 10 + input[i] - '0') % a; if(!left && !mod_b[i + 1]) { char b_first = input[i + 1]; input[i + 1] = '\0'; printf("YES\n%s\n%c%s\n", input, b_first, input + i + 2); return 0; } } printf("NO\n"); return 0; }
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.Help Polycarpus and find any suitable method to cut the public key.
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β€” the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them. If there is no answer, print in a single line "NO" (without the quotes).
C
695418026140545863313f5f3cc1bf00
dd2acf3f4d4b3741d62933cc6f4be3b2
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "number theory", "brute force", "math", "strings" ]
1416733800
["116401024\n97 1024", "284254589153928171911281811000\n1009 1000", "120\n12 1"]
null
PASSED
1,700
standard input
1 second
The first line of the input contains the public key of the messenger β€” an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 ≀ a, b ≀ 108).
["YES\n11640\n1024", "YES\n2842545891539\n28171911281811000", "NO"]
/* practice with Dukkha */ #include <stdio.h> #include <string.h> #define N 1000000 int main() { static char cc[N + 1], aa[N], bb[N]; int n, a, b, d, i, p, q; scanf("%s%d%d", cc, &a, &b); n = strlen(cc); for (i = 0, p = 0; i < n; i++) { d = cc[i] - '0'; p = (p * 10 + d) % a; aa[i] = p == 0; } for (i = n - 1, p = 1, q = 0; i >= 0; i--) { d = cc[i] - '0'; q = (q + d * p) % b; p = p * 10 % b; bb[i] = q == 0; } for (i = 1; i < n; i++) { d = cc[i] - '0'; if (d && aa[i - 1] && bb[i]) { printf("YES\n"); cc[i] = '\0'; printf("%s\n", cc); cc[i] = d + '0'; printf("%s\n", cc + i); return 0; } } printf("NO\n"); return 0; }
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won.Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long integer which may consist of even a million digits!Polycarpus needs to find such a way to cut the public key into two nonempty parts, that the first (left) part is divisible by a as a separate number, and the second (right) part is divisible by b as a separate number. Both parts should be positive integers that have no leading zeros. Polycarpus knows values a and b.Help Polycarpus and find any suitable method to cut the public key.
In the first line print "YES" (without the quotes), if the method satisfying conditions above exists. In this case, next print two lines β€” the left and right parts after the cut. These two parts, being concatenated, must be exactly identical to the public key. The left part must be divisible by a, and the right part must be divisible by b. The two parts must be positive integers having no leading zeros. If there are several answers, print any of them. If there is no answer, print in a single line "NO" (without the quotes).
C
695418026140545863313f5f3cc1bf00
c5f980dc1c3fdde291e164a338aa0c76
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "number theory", "brute force", "math", "strings" ]
1416733800
["116401024\n97 1024", "284254589153928171911281811000\n1009 1000", "120\n12 1"]
null
PASSED
1,700
standard input
1 second
The first line of the input contains the public key of the messenger β€” an integer without leading zeroes, its length is in range from 1 to 106 digits. The second line contains a pair of space-separated positive integers a, b (1 ≀ a, b ≀ 108).
["YES\n11640\n1024", "YES\n2842545891539\n28171911281811000", "NO"]
#include <stdio.h> #include <string.h> int main() { char Str[1000001]; char StrA[1000001]; int ModBy10N[1000000]; int dataA[11], dataB[11]; int A, B, CurModA, CurModB, FinalModB, i, L; char flag = 0; scanf("%s %d %d", Str, &A, &B); for(i = 0; i < 11; ++i) { dataA[i] = i % A; dataB[i] = i % B; } FinalModB = (Str[0] - '0') % B; ModBy10N[0] = 1 % B; for(i = 1; Str[i] != '\0'; ++i) { FinalModB = (((long long)FinalModB * dataB[10]) % B + dataB[Str[i] - '0']) % B; ModBy10N[i] = ((long long)ModBy10N[i - 1] * dataB[10]) % B; } L = i; CurModA = (Str[0] - '0') % A; CurModB = (Str[0] - '0') % B; for(i = 1; Str[i] != '\0'; ++i) { if(Str[i] != '0') { if(CurModA == 0) { if((FinalModB - ((long long)CurModB * ModBy10N[L - i]) % B) % B == 0) { flag = 1; break; } } } CurModA = (((long long)CurModA * dataA[10]) % A + dataA[Str[i] - '0']) % A; CurModB = (((long long)CurModB * dataB[10]) % B + dataB[Str[i] - '0']) % B; } puts(flag ? "YES" : "NO"); if(flag) { memcpy(StrA, Str, i); StrA[i] = '\0'; puts(StrA); puts(Str + i); } return 0; }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
7a0785885f713476725bb1d69716078a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include<stdio.h> #include<string.h> int main() { char s[1000000]; int i,flag=0; scanf("%s",s); int l=strlen(s); for(i=0;i<l;i++) { if(s[i]!='a') { s[i]+=-1; flag=1; if(s[i+1]=='a') break; } } if(flag==0) { s[l-1]='z'; printf("%s",s); } else printf("%s",s); }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
884726eb317d264817ccfc1d6414778e
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include<stdio.h> #include<stdlib.h> #include<string.h> void fun(char *); void fun(char *s) { int i,flag=0; int len=strlen(s); for(i=0;s[i]!='\0';i++) { if(s[i]=='a') { flag=1; } } if(flag==0) { for(i=0;s[i]!='\0';i++) { s[i]=s[i]-1; } return; } i=0; while(s[i]=='a'&&s[i]!='\0') { i++; } if(s[i]=='\0') { s[len-1]='z'; return; } while(s[i]!='a'&&s[i]!='\0') { s[i]=s[i]-1; i++; } } int main() { char a[100001]; scanf("%s",a); fun(a); printf("%s\n",a); return 0; }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
74432e2f8f141e29cad107c1295cd87d
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include <stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> long long cmpfunc (const void * a, const void * b) { return ( *(long long*)a - *(long long*)b ); } int main(void){ long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,b,count1=0,a2,b2; char a[100000]; scanf("%s",a); flag=l=0; n=strlen(a); for(i=0;i<n;i++){ if(a[i]!='a'){ l=i; break; } } for(i=l;i<n;i++){ if(a[i]=='a'){ break; } a[i]-=1; flag=1; } if(flag==0){ a[n-1]='z'; } printf("%s\n",a); return 0; }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
f1a3c645ff7ff36e94ca3147c6a846ae
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include <stdio.h> #include <string.h> char s[123456]; int main() { scanf("%s", s); int n = strlen(s); int k = strlen(s) - 1; for (int i = 0; i < n; i++) { if (s[i] != 'a') { k = i; break; } } s[k] = (((s[k] - 'a') + 25) % 26) + 'a'; k++; while (k < n && s[k] != 'a') { s[k] = (((s[k] - 'a') + 25) % 26) + 'a'; k++; } printf("%s", s); return 0; }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
4c709b47bbe2ac3b83042ccdc7e314ab
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include<stdio.h> #include<string.h> int main() { int i,j=0,n; char SS[1000003]; fgets(SS,sizeof(SS),stdin); n=strlen(SS)-1; for(i=0;i<n;i++) { if(SS[i]!='a') { SS[i]=SS[i]-1; j++; } else { if(i!=0&&j!=0) { break; } if(n==1) { SS[0]='z'; } if(i==n-1&&j==0) { SS[i]='z'; } } } printf("%s",SS); }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
17421c8fb1be7bd494519f8d5b038872
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include<stdio.h> #include<string.h> int main() { int i,a=0,n; char x[100002]; gets(x); n=strlen(x); for(i=0;i<n;i++) if(x[i]!='a') break; if(i==n) x[n-1]='z'; else {for(i=0;i<n;i++) { if(a&&x[i]=='a') break; else if(x[i]>'a'){x[i]-=1; a=1;} }} puts(x); }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
11ac61a0b3bdf2595b88a12d13a541a4
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include<stdio.h> #include<string.h> int main() { int i,a=0,n; char x[100002]; gets(x); n=strlen(x); for(i=0;i<n;i++) { if(a&&x[i]=='a') break; else if(x[i]>'a'){x[i]-=1; a=1;} if(!a&&i==n-1) x[i]='z'; } puts(x); }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
c1282364d1e31b152d9d0773ab75db36
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include<stdio.h> #include<stdlib.h> #include<string.h> int main(){ char str[100000]; int i=0,j=0; int c,d,e; char k; int m; int g=0; int count=0; scanf("%s",str); while(str[i]!='\0'){ if(str[i+1]!='\0'){ if((str[i]=='a'&&count==0)&&str[i+1]!='a'){ count++; c=i; i++; g=1; }} if(((str[i]=='a'&&str[i+1]=='\0')&&count==0)&&str[0]!='a'){ for(e=i-1; ;e--){ if(str[e]!='a'){ count++; c=e+1; j=1; break; } } g=1; } if(j==1){ break; } if(str[i]=='a'&&count==1){ count++; d=i; break; } if(g==0){i++;} g=0; } i=0; g=0; if((count==0&&str[0]!='a')&&g==0){ while(str[i]!='\0'){ k=str[i]; m=k; k=m-1; str[i]=k; i++; } i=0; g=1; } if(count==0&&(str[0]=='a')&&g==0){ while(str[i+1]!='\0'){ str[i]='a'; i++; } if(str[0]=='a'&&str[1]=='\0'){ str[0]='z'; } else{ str[i]='z'; } i=0; g=1; } if(count==1){ if(str[0]=='a'&&g==0){ i=c+1; while(str[i]!='\0'){ k=str[i]; m=k; k=m-1; str[i]=k; i++; } i=0; g=1; } if(str[0]!='a'&&g==0){ while(str[i]!='a'){ k=str[i]; m=k; k=m-1; str[i]=k; i++; } i=0; g=1; } } if((count==2&&g==0)&&str[0]=='a'){ for(i=c+1;i<d;i++){ k=str[i]; m=k; k=m-1; str[i]=k; } i=0; g=1; } if((count==2&&g==0)&&str[0]!='a'){ for(i=0;;i++){ if(str[i]=='a'){ break; } k=str[i]; m=k; k=m-1; str[i]=k; } i=0; g=1; } while(str[i]!='\0'){ printf("%c",str[i]); i++; } return 0; }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
5278e1d8114652676c7dffcd2301948f
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { char s[100000]; int k=0;int l=1; scanf("%s",&s); int n=strlen(s); int i,j; if(n==1){ if(s[0]==97)s[0]=122; else s[0]=s[0]-1; } else {for(i=0;i<n;i++) { if(s[i]==97)l=0; else {l=1; break; } } if(l==0) { s[n-1]=122; printf("%s",s); exit(0); } else { if(s[0]==97) { for(i=1;i<n;i++) { if(k==1) { break; } else { if(s[i]==97) { } else { for(j=i;j<n;j++) { if(s[j]!=97) { s[j]=s[j]-1; } else { k=1; break; } } } } } } else { for(i=0;i<n;i++) { if(k==1) { break; } else { if(s[i]!=97)s[i]=s[i]-1; else { k=1; break; } } } } } } printf("%s",s); }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
f7984ad72f504bbe79d359e79aec2f03
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
// // main.c // CodeForce // // Created by Yash Agarwal on 11/17/19. // Copyright Β© 2019 Yash Agarwal. All rights reserved. // #include <stdio.h> #include <stdio.h> #include <string.h> int main() { char s[100000]; scanf("%s",s); int start=0,end =0, n =(int)strlen(s); while(s[start]=='a') // start stores the index of the first non 'a' character start++; end=start; if(start==n) { s[n-1]='\0'; printf("%s",s); printf("z"); return 0; } while(s[end]!='a'&& end<=n) // end stores the index of the first 'a' after start end++; for(int i =0; i<n; i++) { if(i<start) //the required substring (to alter) is [start,end-1] printf("a"); else if(i<end) printf("%c",s[i]-1); else if( i>=end) printf("%c",s[i]); } }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
b1b0a551e1483edcafcb7973a518d34f
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include <string.h> #include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <limits.h> #include <math.h> #define max(a,b) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ _a > _b ? _a : _b; }) #define min(a,b) \ ({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ _a < _b ? _a : _b; }) int compare(const void * x1, const void * x2) { return ( *(int*)x1 - *(int*)x2 ); } int main () { int i, j; char s[100001]; scanf("%s", s); for(i=0; s[i]!='\0'; i++) { if(s[i]=='a'){continue;} for(j=i; s[j] != '\0' && s[j] != 'a'; j++) { s[j]--; } printf("%s", s); return 0; } s[i-1]='z'; printf("%s", s); //qsort(a, n, sizeof(int), compare); return 0; }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
d4a2d7cb4d2559f26a4bac05431ac78b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> int main() { char *p, *string = (char*) calloc(100001, sizeof(char)); scanf("%s", string); long len = strlen(string); p = string; while(*(p++) == 'a' && (len--)> 0); if(len == 0) { *(p-2) = 'z'; printf("%s\n", string); return 0; } else { p = p - 1; len = len - 1; } while(*(p++) != 'a' && (len--) > -1) *(p-1) = *(p-1)-1; printf("%s\n", string); free(string); return 0; }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
6725132b6314909c3a6497e6d289758e
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include<stdio.h> int main() { char s[100001]; scanf("%s",s); int n=strlen(s),f=0,g=0,l=0,r=0; for(int i=0;i<n;i++) { if(s[i]!='a') { f=1; l=i; break; } } //printf("%d %d",l,f); if(f==0) { for(int i=0;i<n-1;i++) printf("%c",s[i]); printf("%c",'z'); } else { for(int i=l;g==0&&i<n;i++) { if(s[i]=='a') { g=1, r=i; break; } else { if(i==n-1) r=n; } } for(int i=l;i<r;i++) { --s[i]; } printf("%s",s); } return 0; }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
5e8e465b6956b7c067e63a866b460a46
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include<stdio.h> #include <string.h> int main() { int j=-1,k=-1,l,i; char s[100005]; scanf("%s",&s); l=strlen(s); for( i=0;i<l;i++) { if((s[i]!='a')&&(j==-1)) j=i; else if((s[i]=='a')&&(j!=-1)&&(k==-1)) k=i; } if(k==-1) k=l; if(j==-1) { s[l-1]='z'; printf("%s",s); return 0; } for(int i=j;i<k;i++) { s[i]=(s[i]-1); } printf("%s",s); }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
8542391dc4f8ecad482c1c7068ebf11b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include<stdio.h> #include<string.h> int main() { int i,j=0,l,x=0; char s[100005]; gets(s); l=strlen(s); for(i=0;i<l;i++){ if(s[i]!='a'){ j=i; break; } } for(i=j;i<l;i++){ if(s[i]=='a'){ break; } s[i]=s[i]-1; x=1; } if(x==0){ s[l-1]='z'; } printf("%s\n",s); return 0; }
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?
Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.
C
e70708f72da9a203b21fc4112ede9268
5437e4d90abc9601cbc404291f648ef3
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy", "strings" ]
1472056500
["codeforces", "abacaba"]
NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≀ i ≀ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si &lt; ti.
PASSED
1,200
standard input
1 second
The only line of the input contains the string s (1 ≀ |s| ≀ 100 000) consisting of lowercase English letters.
["bncdenqbdr", "aaacaba"]
#include <stdio.h> #define MAX 100001 int main(void) { char s[MAX]; int i = 0; do { scanf("%c", &s[i]); i++; } while (s[i-1] != '\n'); s[i-1] = '\0'; i = 0; while (s[i] != '\0' && s[i] == 'a') i++; if (s[i] == '\0') s[i-1] = 'z'; while (s[i] != '\0' && s[i] != 'a') { s[i] = s[i] - 1; i++; } printf("%s\n", s); return 0; }
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice.
If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "v ml. from cup #a to cup #b." (without the quotes), where v represents the volume of poured juice, a represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), b represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes).
C
7bfc0927ea7abcef661263e978612cc5
3cb2aa87185b9a29a614d9f1fd0a4a7d
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation", "sortings" ]
1311346800
["5\n270\n250\n250\n230\n250", "5\n250\n250\n250\n250\n250", "5\n270\n250\n249\n230\n250"]
null
PASSED
1,300
standard input
0.5 second
The first line contains integer n β€” the number of cups on the royal table (1 ≀ n ≀ 1000). Next n lines contain volumes of juice in each cup β€” non-negative integers, not exceeding 104.
["20 ml. from cup #4 to cup #1.", "Exemplary pages.", "Unrecoverable configuration."]
#include"stdio.h" long n; long f[1011]; long solve() { long i,j,k,r,w,sum=0,mid=0,num=0,ok = 1; long a,b,c; scanf("%ld",&n); for(i=1;i<=n;i++) { scanf("%ld",&f[i]); sum += f[i]; } mid = sum / n; if(mid * n != sum) { return -1; } for(i=1;i<=n;i++) if(f[i] - mid != 0) { if(num == 0) { num = f[i] - mid; k = i; } else if(ok != 1) return -1; else if(num + (f[i] - mid) != 0) return -1; else { if(num > 0) { a = k; b = i; c = num; } else {a = i; b = k; c = -num; } num = 0; ok = 0; } } if(num != 0) return -1; if(ok == 1) return 0; printf("%ld ml. from cup #%ld to cup #%ld.\n",c,b,a); } int main() { long k; k = solve(); if(k == -1) printf("Unrecoverable configuration.\n"); else if(k == 0) printf("Exemplary pages.\n"); return 0; }
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice.
If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "v ml. from cup #a to cup #b." (without the quotes), where v represents the volume of poured juice, a represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), b represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes).
C
7bfc0927ea7abcef661263e978612cc5
621b967ed9d3f917a78af3752157b578
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation", "sortings" ]
1311346800
["5\n270\n250\n250\n230\n250", "5\n250\n250\n250\n250\n250", "5\n270\n250\n249\n230\n250"]
null
PASSED
1,300
standard input
0.5 second
The first line contains integer n β€” the number of cups on the royal table (1 ≀ n ≀ 1000). Next n lines contain volumes of juice in each cup β€” non-negative integers, not exceeding 104.
["20 ml. from cup #4 to cup #1.", "Exemplary pages.", "Unrecoverable configuration."]
#include"stdio.h" long n; long f[1011]; long solve() { long i,j,k,r,w,sum=0,mid=0,num=0,ok = 1; long a,b,c; scanf("%ld",&n); for(i=1;i<=n;i++) { scanf("%ld",&f[i]); sum += f[i]; } mid = sum / n; if(mid * n != sum) { return -1; } for(i=1;i<=n;i++) if(f[i] - mid != 0) { if(num == 0) { num = f[i] - mid; k = i; } else if(ok != 1) return -1; else if(num + (f[i] - mid) != 0) return -1; else { if(num > 0) { a = k; b = i; c = num; } else {a = i; b = k; c = -num; } num = 0; ok = 0; } } if(num != 0) return -1; if(ok == 1) return 0; printf("%ld ml. from cup #%ld to cup #%ld.\n",c,b,a); } int main() { long k; k = solve(); if(k == -1) printf("Unrecoverable configuration.\n"); else if(k == 0) printf("Exemplary pages.\n"); return 0; }
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice.
If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "v ml. from cup #a to cup #b." (without the quotes), where v represents the volume of poured juice, a represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), b represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes).
C
7bfc0927ea7abcef661263e978612cc5
0af1bc0a48c68200984de2b30c6521db
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation", "sortings" ]
1311346800
["5\n270\n250\n250\n230\n250", "5\n250\n250\n250\n250\n250", "5\n270\n250\n249\n230\n250"]
null
PASSED
1,300
standard input
0.5 second
The first line contains integer n β€” the number of cups on the royal table (1 ≀ n ≀ 1000). Next n lines contain volumes of juice in each cup β€” non-negative integers, not exceeding 104.
["20 ml. from cup #4 to cup #1.", "Exemplary pages.", "Unrecoverable configuration."]
#include<stdio.h> int main() { int i,n,a[1002],sum,q=-1,w=-1,ave,t; scanf("%d",&n); for (i=sum=0; i<n; i++) { scanf("%d",&a[i]); sum+=a[i]; } t=sum; ave=sum/n; for (i=sum=0; i<n; i++) { if (a[i]!=ave) { ++sum; if (q==-1) q=i; else w=i; } } if (!sum) puts("Exemplary pages."); else if (sum==2&&t%n==0) { if (a[q]<a[w]) i=q,q=w,w=i; printf("%d ml. from cup #%d to cup #%d.\n",(a[q]-a[w])/2,w+1,q+1); } else puts("Unrecoverable configuration."); return 0; } /*2016-07-26 11:00:12.306*/
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice.
If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "v ml. from cup #a to cup #b." (without the quotes), where v represents the volume of poured juice, a represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), b represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes).
C
7bfc0927ea7abcef661263e978612cc5
914e765291311bfa375ed2a2af27d5b7
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation", "sortings" ]
1311346800
["5\n270\n250\n250\n230\n250", "5\n250\n250\n250\n250\n250", "5\n270\n250\n249\n230\n250"]
null
PASSED
1,300
standard input
0.5 second
The first line contains integer n β€” the number of cups on the royal table (1 ≀ n ≀ 1000). Next n lines contain volumes of juice in each cup β€” non-negative integers, not exceeding 104.
["20 ml. from cup #4 to cup #1.", "Exemplary pages.", "Unrecoverable configuration."]
#include<stdio.h> #include<stdlib.h> int cmp(const void *a, const void *b){ const int *ia = (const int *)a; const int *ib = (const int *)b; return *ib - *ia; } int find_index(int x,int *b,int n){ int i; for(i=0;i<n;i++){ //printf("%d ",b[i]); if(b[i] == x){ //printf("Hi::%d::",(i+1)); return (i+1); } } return -1; } int main(){ int n,a[1003],b[1003],x,y,z,x_count,y_count,z_count,flag=1,i; x=y=z=-1; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&a[i]); b[i] = a[i]; } if(n==1){ printf("Exemplary pages."); }else{ qsort (a, n, sizeof(int), cmp); x=a[0]; z=a[n-1]; if(x == z){ printf("Exemplary pages."); }else{ for(i=1;i<n-1;i++){ if(y==-1){ y=a[i]; }else if(a[i] != y){ flag=0; break; } } if(flag){ //printf("%d %d\n",z,x); if((x-z)%2 != 0){ printf("Unrecoverable configuration."); }else if(n==2 || x-(x-z)/2 == y){ printf("%d ml. from cup #%d to cup #%d.",(x-z)/2,find_index(z,b,n),find_index(x,b,n)); }else{ printf("Unrecoverable configuration."); } }else{ printf("Unrecoverable configuration."); } } } return 0; }
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice.
If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "v ml. from cup #a to cup #b." (without the quotes), where v represents the volume of poured juice, a represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), b represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes).
C
7bfc0927ea7abcef661263e978612cc5
e5bd92d6e1a3d8f7a56428b6252370d3
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation", "sortings" ]
1311346800
["5\n270\n250\n250\n230\n250", "5\n250\n250\n250\n250\n250", "5\n270\n250\n249\n230\n250"]
null
PASSED
1,300
standard input
0.5 second
The first line contains integer n β€” the number of cups on the royal table (1 ≀ n ≀ 1000). Next n lines contain volumes of juice in each cup β€” non-negative integers, not exceeding 104.
["20 ml. from cup #4 to cup #1.", "Exemplary pages.", "Unrecoverable configuration."]
#include <stdio.h> int main() { int n,s=0,i,j,f,k,r; int ara[1000][1]; int a[1000]; int b[1000]; scanf("%d",&n); for (i=0;i<n;i++){ scanf("%d",&ara[i][0]); s=s+ara[i][0]; } if (s%n!=0){ printf("Unrecoverable configuration."); } else{ r=s/n; k=0; f=0; for (i=0;i<n;i++){ if (ara[i][0]!=r){ f=1; a[k]=i+1; b[k]=ara[i][0]; k++; if (k>2) { printf("Unrecoverable configuration."); break; } } } if (f==0){ printf("Exemplary pages."); } else { if (k==2){ if (b[0]>b[1] && b[0]+b[1]==2*r){ printf("%d ml. from cup #%d to cup #%d.",r-b[1],a[1],a[0]); } else if (b[1]>b[0] && b[0]+b[1]==2*r){ printf("%d ml. from cup #%d to cup #%d.",r-b[0],a[0],a[1]); } } } } /*for (i=0;i<k;i++) { printf("%d ",a[i]); }*/ return 0; }
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice.
If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "v ml. from cup #a to cup #b." (without the quotes), where v represents the volume of poured juice, a represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), b represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes).
C
7bfc0927ea7abcef661263e978612cc5
f50e37689b0b4362e322fca71162434a
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation", "sortings" ]
1311346800
["5\n270\n250\n250\n230\n250", "5\n250\n250\n250\n250\n250", "5\n270\n250\n249\n230\n250"]
null
PASSED
1,300
standard input
0.5 second
The first line contains integer n β€” the number of cups on the royal table (1 ≀ n ≀ 1000). Next n lines contain volumes of juice in each cup β€” non-negative integers, not exceeding 104.
["20 ml. from cup #4 to cup #1.", "Exemplary pages.", "Unrecoverable configuration."]
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <time.h> int s,n,t,c,a[1000],i,j,m=1e6,M; main(){ scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&t); s+=t; if(m>t)m=t; if(M<t)M=t; a[i]=t; } if(m==M){ puts("Exemplary pages."); }else{ if(s%i) puts("Unrecoverable configuration."); else{ s/=i; int x,y,z; for(i=0;i<n;i++) { c+=!(s==a[i]); if(s>a[i])x=i; if(s<a[i])y=i,z=a[i]-s; } if(c==2) printf("%d ml. from cup #%d to cup #%d.\n",z,x+1,y+1); else puts("Unrecoverable configuration."); } } return 0; }
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice.
If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "v ml. from cup #a to cup #b." (without the quotes), where v represents the volume of poured juice, a represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), b represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes).
C
7bfc0927ea7abcef661263e978612cc5
51be8f6ecc0d27b4f4dbae2500756a98
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation", "sortings" ]
1311346800
["5\n270\n250\n250\n230\n250", "5\n250\n250\n250\n250\n250", "5\n270\n250\n249\n230\n250"]
null
PASSED
1,300
standard input
0.5 second
The first line contains integer n β€” the number of cups on the royal table (1 ≀ n ≀ 1000). Next n lines contain volumes of juice in each cup β€” non-negative integers, not exceeding 104.
["20 ml. from cup #4 to cup #1.", "Exemplary pages.", "Unrecoverable configuration."]
#include <stdio.h> int main() { int n, sum = 0, f = 0, x = 0, y = 0, i; int a[1000]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); sum += a[i]; } if (sum % n != 0) { puts("Unrecoverable configuration."); return 0; } for (i = 0; i < n; i++) { if (a[i] != sum / n) { f++; if (f >= 3) { puts("Unrecoverable configuration."); return 0; } if (f == 1) { x = i; } else { y = i; } } } if (!f) { puts("Exemplary pages."); return 0; } if (f != 2) { puts("Unrecoverable configuration."); return 0; } if (sum / n * 2 == a[x] + a[y]) { if (a[x] > a[y]) { printf("%d ml. from cup #%d to cup #%d.\n", a[x] - sum / n, y + 1, x + 1); } else { printf("%d ml. from cup #%d to cup #%d.\n", a[y] - sum / n, x + 1, y + 1); } } return 0; }
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.Ahcl wants to construct a beautiful string. He has a string $$$s$$$, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!More formally, after replacing all characters '?', the condition $$$s_i \neq s_{i+1}$$$ should be satisfied for all $$$1 \leq i \leq |s| - 1$$$, where $$$|s|$$$ is the length of the string $$$s$$$.
For each test case given in the input print the answer in the following format: If it is impossible to create a beautiful string, print "-1" (without quotes); Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
C
98c08a3b5e5b5bb78804ff797ba24d87
b1395a8a5a5bbc13381073a650b81cb3
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "greedy" ]
1575556500
["3\na???cb\na??bbc\na?b?c"]
NoteIn the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.In the second test case, it is impossible to create a beautiful string, because the $$$4$$$-th and $$$5$$$-th characters will be always equal.In the third test case, the only answer is "acbac".
PASSED
1,000
standard input
1 second
The first line contains positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$)Β β€” the number of test cases. Next $$$t$$$ lines contain the descriptions of test cases. Each line contains a non-empty string $$$s$$$ consisting of only characters 'a', 'b', 'c' and '?'. It is guaranteed that in each test case a string $$$s$$$ has at least one character '?'. The sum of lengths of strings $$$s$$$ in all test cases does not exceed $$$10^5$$$.
["ababcb\n-1\nacbac"]
#include <stdio.h> #include <string.h> int main () { int t; scanf ("%d", &t); while (t--) { char seq [100001]; scanf ("%s", seq); char str [] = "abc"; int i, j, l; int flag = 0; l = strlen (seq); for (i = 0; i < l-1; i++) { if (seq [i] == seq [i+1] && seq [i] != '?') { flag = 1; } } if (flag == 1) { printf ("-1\n"); continue; } for (i = 0; i < l; i++) { if (seq [i] == '?') { for (j = 0; j < 3; j++) { if (seq [i-1] != str [j] && seq[i+1] != str [j]) { seq [i] = str [j]; break; } } } } printf ("%s\n", seq); } return 0; }
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.Ahcl wants to construct a beautiful string. He has a string $$$s$$$, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!More formally, after replacing all characters '?', the condition $$$s_i \neq s_{i+1}$$$ should be satisfied for all $$$1 \leq i \leq |s| - 1$$$, where $$$|s|$$$ is the length of the string $$$s$$$.
For each test case given in the input print the answer in the following format: If it is impossible to create a beautiful string, print "-1" (without quotes); Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
C
98c08a3b5e5b5bb78804ff797ba24d87
de77b737225238951105966b89127a76
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "greedy" ]
1575556500
["3\na???cb\na??bbc\na?b?c"]
NoteIn the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.In the second test case, it is impossible to create a beautiful string, because the $$$4$$$-th and $$$5$$$-th characters will be always equal.In the third test case, the only answer is "acbac".
PASSED
1,000
standard input
1 second
The first line contains positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$)Β β€” the number of test cases. Next $$$t$$$ lines contain the descriptions of test cases. Each line contains a non-empty string $$$s$$$ consisting of only characters 'a', 'b', 'c' and '?'. It is guaranteed that in each test case a string $$$s$$$ has at least one character '?'. The sum of lengths of strings $$$s$$$ in all test cases does not exceed $$$10^5$$$.
["ababcb\n-1\nacbac"]
#include<stdio.h> #include<string.h> int main() { int t,n,i,j,k,l,len; char a[100001],b[100001]; scanf("%d\n",&t); for(i=0;i<t;i++) { k=1; gets(a); len=strlen(a); //printf("%s\n",a); // printf("%d ",len); for(j=0;j<len;j++) { if((j!=len-1)&&(a[j]!='?')&&(a[j+1]!='?')&&(a[j]==a[j+1])) k=0; if(k==0) break; if(a[j]!='?'){ b[j]=a[j];} else { if(j==0) { if(a[j+1]!='?'&&a[j+1]!='a'){ b[j]='a';} else if(a[j+1]=='a'){ b[j]='b';} else {b[j]='a';} } else if(j<len-1) { if(a[j+1]=='?') { if(b[j-1]=='a'){ b[j]='b';} else {b[j]='a';} } else { if(b[j-1]=='a'&&a[j+1]=='b') b[j]='c'; else if(b[j-1]=='b'&&a[j+1]=='a') b[j]='c'; else if(b[j-1]=='a'&&a[j+1]=='c') b[j]='b'; else if(b[j-1]=='c'&&a[j+1]=='a') b[j]='b'; else if(b[j-1]=='b'&&a[j+1]=='c') b[j]='a'; else if(b[j-1]=='c'&&a[j+1]=='b') b[j]='a'; else if(b[j-1]=='b'&&a[j+1]=='b') b[j]='a'; else if(b[j-1]=='c'&&a[j+1]=='c') b[j]='a'; else if(b[j-1]=='a'&&a[j+1]=='a') b[j]='b'; } } else if(j==len-1) { if(b[j-1]=='a') b[j]='b'; else b[j]='a'; } } } if(k==0) printf("-1"); else for(j=0;j<len;j++) { printf("%c",b[j]); } printf("\n"); } return 0; }
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.Ahcl wants to construct a beautiful string. He has a string $$$s$$$, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!More formally, after replacing all characters '?', the condition $$$s_i \neq s_{i+1}$$$ should be satisfied for all $$$1 \leq i \leq |s| - 1$$$, where $$$|s|$$$ is the length of the string $$$s$$$.
For each test case given in the input print the answer in the following format: If it is impossible to create a beautiful string, print "-1" (without quotes); Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.
C
98c08a3b5e5b5bb78804ff797ba24d87
f52efaceda67f7dee29f300a4a042108
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "greedy" ]
1575556500
["3\na???cb\na??bbc\na?b?c"]
NoteIn the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.In the second test case, it is impossible to create a beautiful string, because the $$$4$$$-th and $$$5$$$-th characters will be always equal.In the third test case, the only answer is "acbac".
PASSED
1,000
standard input
1 second
The first line contains positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$)Β β€” the number of test cases. Next $$$t$$$ lines contain the descriptions of test cases. Each line contains a non-empty string $$$s$$$ consisting of only characters 'a', 'b', 'c' and '?'. It is guaranteed that in each test case a string $$$s$$$ has at least one character '?'. The sum of lengths of strings $$$s$$$ in all test cases does not exceed $$$10^5$$$.
["ababcb\n-1\nacbac"]
#include<stdio.h> #include<string.h> int main() { char str[100010]; int t,i,j,c,l; scanf("%d",&t); for(i=1;i<=t;i++) { scanf("%s",&str); c=0; l=strlen(str); for(j=0;j<(l-1);j++) { if((str[j]==str[j+1])&&str[j]!='?'&&str[j+1]!='?') { c++; } } //printf("%d\n",c); if(c>0) { printf("-1\n"); } else { if(l==1) { if(str[0]=='?') { str[0]='a'; } } if(str[0]=='?') { if(str[1]=='a'||str[1]=='b') { str[0]='c'; } else if(str[1]=='a'||str[1]=='c') { str[0]='b'; } else if(str[1]=='c'||str[1]=='b') { str[0]='a'; } else if(str[1]=='?') { str[0]='a'; } } if(str[l-1]=='?') { if(str[l-2]=='a'||str[l-2]=='b') { str[l-1]='c'; } else if(str[l-2]=='a'||str[l-2]=='c') { str[l-1]='b'; } else if(str[l-2]=='c'||str[l-2]=='b') { str[l-1]='a'; } else if(str[l-2]=='?') { str[l-1]='a'; } } for(j=1;j<(l-1);j++) { if(str[j]=='?'&&(str[j-1]=='a'||str[j-1]=='b')&&(str[j+1]=='b'||str[j+1]=='a')) { str[j]='c'; } else if(str[j]=='?'&&(str[j-1]=='c'||str[j-1]=='b')&&(str[j+1]=='b'||str[j+1]=='c')) { str[j]='a'; } else if(str[j]=='?'&&(str[j-1]=='c'||str[j-1]=='a')&&(str[j+1]=='a'||str[j+1]=='c')) { str[j]='b'; } else if(str[j]=='?'&&(str[j+1]=='?')&&(str[j-1]=='a'||str[j-1]=='c')) { str[j]='b'; } else if(str[j]=='?'&&(str[j+1]=='?')&&(str[j-1]=='a'||str[j-1]=='b')) { str[j]='c'; } else if(str[j]=='?'&&(str[j+1]=='?')&&(str[j-1]=='b'||str[j-1]=='c')) { str[j]='a'; } } printf("%s\n",str); } } return 0; }
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
1efd7fdc573493819aa69ba085dcc82b
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char *x; char a[100005], b[]="AB",c[]="BA"; gets(a); if((x=strstr(a,b)) && strstr(x+2,c)) printf("YES"); else if((x=strstr(a,c)) && strstr(x+2,b)) printf("YES"); else printf("NO"); return 0; }
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
3dac842e776f0b89003ce3fe24a5908b
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include <stdio.h> int main () { char c[100000]; scanf("%s",&c); int i, flag1=0, found=0,flag2=0; for (i=0; c[i]!='\0'; i++) { if (c[i] == 'A' && c[i+1] == 'B' && flag1 == 0) { flag1 = 1; } else if (c[i] == 'B' && c[i+1] == 'A' && flag2 == 0) { flag2 = 1; } if (flag1 == 1) { if(c[i+2] == 'B' && c[i+3] == 'A') { found = 1; } } if (flag2 == 1) { if(c[i+2] == 'A' && c[i+3] == 'B') { found = 1; } } } if(found == 1) { printf("YES\n"); } else printf("NO\n"); return 0; }
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
82c8f0354d6ea52aacb6672fc5a59448
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char s[100000]; gets(s); long i,j, n = strlen(s),a=0,b=0,c=0; for(i=0;i<n;i++) { if((s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='A')||(s[i]=='B'&&s[i+1]=='A'&&s[i+2]=='B')&&i<n-2) { c++;i+=2; } else if (a!=1&&s[i]=='A') { if (s[i+1]=='B') {a=1;i++;} } else if (s[i]=='B'&&b!=1) { if (s[i+1]=='A') {b=1;i++;} } if (a+b==2) {printf ("YES"); return 0;} if (c==2) {printf ("YES"); return 0;} if ((1-a)*(1-b)==0&&c==1) {printf ("YES"); return 0;} } printf ("NO"); return 0; }
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
d801d7e5f3954ebce783080266a2447e
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include<string.h> #include<stdio.h> int main () { char d[100005]; int i,u,k=0,s=0,s1=0,j=0; scanf("%s",d); u=strlen(d); for(i=0;i<u;i++){ if(d[i]=='B'&& d[i+1]=='A'&&s==0){ k++; i++; s++; if(d[i+1]=='B'){ j++; k--; s--; i++; } continue; } if(d[i]=='A'&& d[i+1]=='B'&&s1==0){ k++; i++; s1++; if(d[i+1]=='A'){ j++; k--; s1--; i++; } } } printf((k==2)? "YES":(k && j==1) ? "YES" : (!k && j>1) ? "YES" : "NO"); return 0; }
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
b31d4ac3bdc294f17a29734900084eb2
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include<stdio.h> #include<string.h> int main() { char a[1000006]; int i,j,l,t=0; scanf("%s",a); l=strlen(a); for(i=0;i<l-1;i++) { if(a[i]=='A' && a[i+1]=='B') { for(j=i+2;j<l-1;j++) { if(a[j]=='B' && a[j+1]=='A') { t=1; break; } } break; } } if(t==0) {for(i=0;i<l-1;i++) { if(a[i]=='B' && a[i+1]=='A') { for(j=i+2;j<l-1;j++) { if(a[j]=='A' && a[j+1]=='B') { t=1; break; } } break; } } } if(t==1) printf("YES\n"); else printf("NO\n"); return 0; }
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
d6164cbdb8e8b397c99deb5b8396a33f
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include <stdio.h> #include<string.h> int main() { char s[100005],*p; int x; scanf("%s",s); if((p=strstr(s,"AB"))&&(strstr(p+2,"BA"))){ {printf("YES");} } else if((p=strstr(s,"BA"))&&(strstr(p+2,"AB"))){ {printf("YES");} } else{ printf("NO"); } return 0; /*char a[1000006]; int i,j,l,t; scanf("%s",a); l= strlen(a); for(i=0;i<l;i++) { if(a[i]=='A' && a[i+1]=='B') { for(j=i+2;j<l;j++) { if(a[j]=='B' && a[j+1]=='A') { t=1; break; } } if(t==1) break; } } for(i=0;i<l;i++) { if(a[i]=='B' && a[i+1]=='A') { for(j=i+2;j<l;j++) { if(a[j]=='A' && a[j+1]=='B') { t=1; break; } } if(t==1) break; } } if(t==1) printf("YES\n"); else printf("NO\n");*/ }
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
82f9327ba8ed9923f68ba0688d4112c3
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include <stdio.h> #include <stdlib.h> #include <string.h> char a[100001]; int main() { int b=0,i=0,c=0,j=0,d=0,e=0; scanf("%s",a); int x = strlen(a); for(i=0; i<x; i++) { if(a[i]=='A') { if(a[i+1]=='B') { e = 1; for(j=i+2; j<x; j++) { if(a[j]=='B') { if(a[j+1]=='A') { b=1; a[j] = '1'; a[j+1] = '1'; a[i] = '1'; a[i+1] = '1'; break; } } } } } if(e) break; } for(i=0; i<x; i++) { if(a[i]=='B') { if(a[i+1]=='A') { d = 1; for(j=i+2; j<x; j++) { if(a[j]=='A') { if(a[j+1]=='B') { c=1; a[j] = '1'; a[j+1] = '1'; a[i] = '1'; a[i+1] = '1'; break; } } } } } if(d) break; } if(b||c) printf("YES"); else printf("NO"); return 0; }
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
6b42d59ef2c7d63e21758b93b784ad1e
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include<stdio.h> #include<string.h> int main(void) { int i,n,flag,j; char s[100001]; gets(s); for (i=0, n=strlen(s);i<n;i++) { if (s[i]=='A'&&s[i+1]=='B') { flag=i+1; for (j=strlen(s)-1;j>0;j=j-1) { if (s[j]=='A'&&s[j-1]=='B') { if (j-1>flag) { printf("YES\n"); exit(0); } else break; } } break; } } for (i=0, n=strlen(s);i<n;i++) { if (s[i]=='B'&&s[i+1]=='A') { flag=i+1; for (j=strlen(s)-1;j>0;j=j-1) { if (s[j]=='B'&&s[j-1]=='A') { if (j-1>flag) { printf("YES\n"); exit(0); } else { break; } } } break; } } printf("NO\n"); }
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
e1b1f6cfe561bab98c20deb060f40c40
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include<stdio.h> #include<stdlib.h> int main() { int x=0,y=0; char n[100001]; scanf("%s", &n); for(int i=0; i<strlen(n)-1; i++){ if(n[i]=='A'&&n[i+1]=='B'&&!x){ x++; } if(n[i]=='B'&&n[i+1]=='A'&&!y){ y++; } if(n[i]=='A'&&n[i+1]=='B'&&x&&y){ for(int j=0; j<i-1; j++){ if(n[j]=='B'&&n[j+1]=='A'){ printf("YES"); return 0; } } for(int j=i+2; j<strlen(n)-1; j++){ if(n[j]=='B'&&n[j+1]=='A'){ printf("YES"); return 0; } } } if(n[i]=='B'&&n[i+1]=='A'&&x&&y){ for(int j=0; j<i-1; j++){ if(n[j]=='A'&&n[j+1]=='B'){ printf("YES"); return 0; } } for(int j=i+2; j<strlen(n)-1; j++){ if(n[j]=='A'&&n[j+1]=='B'){ printf("YES"); return 0; } } } } printf("NO"); return 0; };
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
fd7a68f33bb3f71b7a0b71a28102b6d8
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include<stdio.h> #include<string.h> int main() { char ch[100005]; scanf("%s",ch); int len=strlen(ch); int flag=0; int i; for(i=0;i<len-1;i++) { if(ch[i]=='A' && ch[i+1]=='B') { // found left substring i=i+2; while(i<len-1) { if(ch[i]=='B' && ch[i+1]=='A') { flag=1; break; } i++; } break; } } for(i=0;i<len-1;i++) { if(ch[i]=='B' && ch[i+1]=='A') { // found left substring i=i+2; while(i<len-1) { if(ch[i]=='A' && ch[i+1]=='B') { flag=1; break; } i++; } break; } } if(flag==0) printf("NO\n"); else printf("YES\n"); return 0; }
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
e103b726ea08dee2958b6702e59f89c1
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include <stdio.h> #include <string.h> int main() { char p[100001], *s; scanf("%s",p); if((s=strstr(p,"AB"))!=NULL && strstr(s+2,"BA")!=NULL) printf("YES"); else if((s=strstr(p,"BA"))!=NULL && strstr(s+2,"AB")!=NULL) printf("YES"); else printf("NO"); return 0; }
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
35b6b4836716dde7f18523c0130da03a
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include<stdio.h> #include<string.h> char arr[100001]; int ln,i; int posa[2],posb[2]; char flga,flgb; int main() { posa[0]=posb[0]=100002; posa[1]=posb[1]=-1; flga=flgb=0; scanf("%s",arr); ln=strlen(arr); for(i=0;i<ln;++i) { if(arr[i]=='A') { if(flgb==1) { if(posb[0]==100002) posb[0]=i; posb[1]=i; flgb=0; } flga=1; } else if (arr[i]=='B') { if(flga==1) { if(posa[0]==100002) posa[0]=i; posa[1]=i; flga=0; } flgb=1; } else { flga=flgb=0; } } if(posb[1]-posa[0]>1 || posa[1]-posb[0]>1) printf("YES"); else printf("NO"); return 0; }
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
C
33f7c85e47bd6c83ab694a834fa728a2
6bef7e20287984afdc35aae6331d3372
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "greedy", "implementation", "brute force", "strings" ]
1433435400
["ABA", "BACFAB", "AXBYBXA"]
NoteIn the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".In the second sample test there are the following occurrences of the substrings: BACFAB.In the third sample test there is no substring "AB" nor substring "BA".
PASSED
1,500
standard input
2 seconds
The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.
["NO", "YES", "NO"]
#include<string.h> #include<stdio.h> int main() { char s[1000000]; scanf("%s",s); int f=0,i,l=0,k=0,q=-1,a=0,g=0; int p[1000001]={}; for(i=0;i<strlen(s);i++) { if(s[i]=='A'&&s[i+1]=='B') { g++; p[i]=1; } } int sp=0,we=0; for(i=0;i<strlen(s);i++) { if(s[i]=='B'&&s[i+1]=='A') { f=2; we++; } if(s[i]=='B'&&s[i+1]=='A'&&p[i+1]==1&&p[i-1]==1) { sp=1; } if(s[i]=='B'&&s[i+1]=='A'&&p[i+1]!=1&&p[i-1]!=1) { f=1; break; } } if(((f==1&&g>=1)||(g>=2&&f==2))&&(sp!=1||(g>2||we>=2))) printf("YES\n"); else printf("NO\n"); return 0; }
There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.Each shark will grow some number of flowers si. For i-th shark value si is random integer equiprobably chosen in range from li to ri. Wet Shark has it's favourite prime number p, and he really likes it! If for any pair of neighbouring sharks i and j the product siΒ·sj is divisible by p, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks.At the end of the day sharks sum all the money Wet Shark granted to them. Find the expectation of this value.
Print a single real number β€” the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. 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
5aad0a82748d931338140ae81fed301d
478a3ebdbded745ab7a02c3afe3aef1b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "combinatorics", "number theory", "probabilities", "math" ]
1454249100
["3 2\n1 2\n420 421\n420420 420421", "3 5\n1 4\n2 3\n11 14"]
NoteA prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of flowers (s0, s1, s2) each shark grows: (1, 420, 420420): note that s0Β·s1 = 420, s1Β·s2 = 176576400, and s2Β·s0 = 420420. For each pair, 1000 dollars will be awarded to each shark. Therefore, each shark will be awarded 2000 dollars, for a total of 6000 dollars. (1, 420, 420421): now, the product s2Β·s0 is not divisible by 2. Therefore, sharks s0 and s2 will receive 1000 dollars, while shark s1 will receive 2000. The total is 4000. (1, 421, 420420): total is 4000 (1, 421, 420421): total is 0. (2, 420, 420420): total is 6000. (2, 420, 420421): total is 6000. (2, 421, 420420): total is 6000. (2, 421, 420421): total is 4000.The expected value is .In the second sample, no combination of quantities will garner the sharks any money.
PASSED
1,700
standard input
2 seconds
The first line of the input contains two space-separated integers n and p (3 ≀ n ≀ 100 000, 2 ≀ p ≀ 109)Β β€” the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime. The i-th of the following n lines contains information about i-th sharkΒ β€” two space-separated integers li and ri (1 ≀ li ≀ ri ≀ 109), the range of flowers shark i can produce. Remember that si is chosen equiprobably among all integers from li to ri, inclusive.
["4500.0", "0.0"]
#include <stdio.h> long double e(int l1, int r1, int l2, int r2, int p) { long long n1 = r1 / p - (l1 - 1) / p, d1 = r1 - l1 + 1; long long n2 = r2 / p - (l2 - 1) / p, d2 = r2 - l2 + 1; return 2000.0L * (1.0L - (long double) ((d1 - n1) * (d2 - n2)) / (d1 * d2)); } int main(void) { int n, p, l0, r0; scanf("%d %d %d %d", &n, &p, &l0, &r0); int l1 = l0, r1 = r0; long double v = 0.0; for (int i = 1; i < n; i++) { int l2, r2; scanf("%d %d", &l2, &r2); v += e(l1, r1, l2, r2, p); l1 = l2, r1 = r2; } printf("%.10Lf\n", v += e(l0, r0, l1, r1, p)); }
There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.Each shark will grow some number of flowers si. For i-th shark value si is random integer equiprobably chosen in range from li to ri. Wet Shark has it's favourite prime number p, and he really likes it! If for any pair of neighbouring sharks i and j the product siΒ·sj is divisible by p, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks.At the end of the day sharks sum all the money Wet Shark granted to them. Find the expectation of this value.
Print a single real number β€” the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. 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
5aad0a82748d931338140ae81fed301d
d13fe6d1e46cfbdb82d8ea72642d2919
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "combinatorics", "number theory", "probabilities", "math" ]
1454249100
["3 2\n1 2\n420 421\n420420 420421", "3 5\n1 4\n2 3\n11 14"]
NoteA prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of flowers (s0, s1, s2) each shark grows: (1, 420, 420420): note that s0Β·s1 = 420, s1Β·s2 = 176576400, and s2Β·s0 = 420420. For each pair, 1000 dollars will be awarded to each shark. Therefore, each shark will be awarded 2000 dollars, for a total of 6000 dollars. (1, 420, 420421): now, the product s2Β·s0 is not divisible by 2. Therefore, sharks s0 and s2 will receive 1000 dollars, while shark s1 will receive 2000. The total is 4000. (1, 421, 420420): total is 4000 (1, 421, 420421): total is 0. (2, 420, 420420): total is 6000. (2, 420, 420421): total is 6000. (2, 421, 420420): total is 6000. (2, 421, 420421): total is 4000.The expected value is .In the second sample, no combination of quantities will garner the sharks any money.
PASSED
1,700
standard input
2 seconds
The first line of the input contains two space-separated integers n and p (3 ≀ n ≀ 100 000, 2 ≀ p ≀ 109)Β β€” the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime. The i-th of the following n lines contains information about i-th sharkΒ β€” two space-separated integers li and ri (1 ≀ li ≀ ri ≀ 109), the range of flowers shark i can produce. Remember that si is chosen equiprobably among all integers from li to ri, inclusive.
["4500.0", "0.0"]
#include <stdio.h> #include <ctype.h> int getint(void) { int c, v = 0; while (isdigit(c = getchar())) v = 10 * v + c - '0'; return v; } long double e(int l1, int r1, int l2, int r2, int p) { long long n1 = r1 / p - (l1 - 1) / p, d1 = r1 - l1 + 1; long long n2 = r2 / p - (l2 - 1) / p, d2 = r2 - l2 + 1; return 2000.0L * (1.0L - (long double) ((d1 - n1) * (d2 - n2)) / (d1 * d2)); } int main(void) { int n = getint(), p = getint(), l0 = getint(), r0 = getint(); int l1 = l0, r1 = r0; long double v = 0.0; for (int i = 1; i < n; i++) { int l2 = getint(), r2 = getint(); v += e(l1, r1, l2, r2, p); l1 = l2, r1 = r2; } printf("%.10Lf\n", v += e(l0, r0, l1, r1, p)); }
There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.Each shark will grow some number of flowers si. For i-th shark value si is random integer equiprobably chosen in range from li to ri. Wet Shark has it's favourite prime number p, and he really likes it! If for any pair of neighbouring sharks i and j the product siΒ·sj is divisible by p, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks.At the end of the day sharks sum all the money Wet Shark granted to them. Find the expectation of this value.
Print a single real number β€” the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. 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
5aad0a82748d931338140ae81fed301d
74ed5f61826de3b7df111de66d2fbad5
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "combinatorics", "number theory", "probabilities", "math" ]
1454249100
["3 2\n1 2\n420 421\n420420 420421", "3 5\n1 4\n2 3\n11 14"]
NoteA prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of flowers (s0, s1, s2) each shark grows: (1, 420, 420420): note that s0Β·s1 = 420, s1Β·s2 = 176576400, and s2Β·s0 = 420420. For each pair, 1000 dollars will be awarded to each shark. Therefore, each shark will be awarded 2000 dollars, for a total of 6000 dollars. (1, 420, 420421): now, the product s2Β·s0 is not divisible by 2. Therefore, sharks s0 and s2 will receive 1000 dollars, while shark s1 will receive 2000. The total is 4000. (1, 421, 420420): total is 4000 (1, 421, 420421): total is 0. (2, 420, 420420): total is 6000. (2, 420, 420421): total is 6000. (2, 421, 420420): total is 6000. (2, 421, 420421): total is 4000.The expected value is .In the second sample, no combination of quantities will garner the sharks any money.
PASSED
1,700
standard input
2 seconds
The first line of the input contains two space-separated integers n and p (3 ≀ n ≀ 100 000, 2 ≀ p ≀ 109)Β β€” the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime. The i-th of the following n lines contains information about i-th sharkΒ β€” two space-separated integers li and ri (1 ≀ li ≀ ri ≀ 109), the range of flowers shark i can produce. Remember that si is chosen equiprobably among all integers from li to ri, inclusive.
["4500.0", "0.0"]
/* practice with Dukkha */ #include <stdio.h> #define N 100000 int main() { static double pp[N]; int n, p, i, l, r; double sum; scanf("%d%d", &n, &p); for (i = 0; i < n; i++) { scanf("%d%d", &l, &r); pp[i] = (double) (r / p - (l - 1) / p) / (r - l + 1); } sum = 0; for (i = 0; i < n; i++) sum += 1 - (1 - pp[i]) * (1 - pp[(i + 1) % n]); printf("%f\n", sum * 2000); return 0; }
There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.Each shark will grow some number of flowers si. For i-th shark value si is random integer equiprobably chosen in range from li to ri. Wet Shark has it's favourite prime number p, and he really likes it! If for any pair of neighbouring sharks i and j the product siΒ·sj is divisible by p, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks.At the end of the day sharks sum all the money Wet Shark granted to them. Find the expectation of this value.
Print a single real number β€” the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. 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
5aad0a82748d931338140ae81fed301d
814afb157938bd3bae831b898f23cdd9
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "combinatorics", "number theory", "probabilities", "math" ]
1454249100
["3 2\n1 2\n420 421\n420420 420421", "3 5\n1 4\n2 3\n11 14"]
NoteA prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of flowers (s0, s1, s2) each shark grows: (1, 420, 420420): note that s0Β·s1 = 420, s1Β·s2 = 176576400, and s2Β·s0 = 420420. For each pair, 1000 dollars will be awarded to each shark. Therefore, each shark will be awarded 2000 dollars, for a total of 6000 dollars. (1, 420, 420421): now, the product s2Β·s0 is not divisible by 2. Therefore, sharks s0 and s2 will receive 1000 dollars, while shark s1 will receive 2000. The total is 4000. (1, 421, 420420): total is 4000 (1, 421, 420421): total is 0. (2, 420, 420420): total is 6000. (2, 420, 420421): total is 6000. (2, 421, 420420): total is 6000. (2, 421, 420421): total is 4000.The expected value is .In the second sample, no combination of quantities will garner the sharks any money.
PASSED
1,700
standard input
2 seconds
The first line of the input contains two space-separated integers n and p (3 ≀ n ≀ 100 000, 2 ≀ p ≀ 109)Β β€” the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime. The i-th of the following n lines contains information about i-th sharkΒ β€” two space-separated integers li and ri (1 ≀ li ≀ ri ≀ 109), the range of flowers shark i can produce. Remember that si is chosen equiprobably among all integers from li to ri, inclusive.
["4500.0", "0.0"]
#include<stdio.h> typedef long long ll; ll n,p,ar[100009][2]; int main() { scanf("%lld%lld",&n,&p); ll i,f1,nf1,a1,b1,f2,nf2,a2,b2,j; for(i=0;i<n;i++) scanf("%lld%lld",&ar[i][0],&ar[i][1]); long double ans=0.0,aa; for(i=0;i<n;i++) { j=i+1; j=j%n; a1=((ar[i][0]+p-1)/p)*p; b1=(ar[i][1]/p)*p; a2=((ar[j][0]+p-1)/p)*p; b2=(ar[j][1]/p)*p; aa=0.0; f1=(b1-a1)/p+1; if(f1<0) f1=0; nf1=ar[i][1]-ar[i][0]+1; f2=(b2-a2)/p+1; if(f2<0) f2=0; nf2=ar[j][1]-ar[j][0]+1; aa=(f1)*(nf2)+f2*nf1-f1*f2; //printf("%Lf\n",aa); aa=(aa*1.0)/(nf1*nf2); ans+=aa; } ans=ans*2000.0; printf("%Lf",ans); return 0; }
There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.Each shark will grow some number of flowers si. For i-th shark value si is random integer equiprobably chosen in range from li to ri. Wet Shark has it's favourite prime number p, and he really likes it! If for any pair of neighbouring sharks i and j the product siΒ·sj is divisible by p, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks.At the end of the day sharks sum all the money Wet Shark granted to them. Find the expectation of this value.
Print a single real number β€” the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. 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
5aad0a82748d931338140ae81fed301d
346282810a1c6ef0bcfd473bc7b02b71
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "combinatorics", "number theory", "probabilities", "math" ]
1454249100
["3 2\n1 2\n420 421\n420420 420421", "3 5\n1 4\n2 3\n11 14"]
NoteA prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of flowers (s0, s1, s2) each shark grows: (1, 420, 420420): note that s0Β·s1 = 420, s1Β·s2 = 176576400, and s2Β·s0 = 420420. For each pair, 1000 dollars will be awarded to each shark. Therefore, each shark will be awarded 2000 dollars, for a total of 6000 dollars. (1, 420, 420421): now, the product s2Β·s0 is not divisible by 2. Therefore, sharks s0 and s2 will receive 1000 dollars, while shark s1 will receive 2000. The total is 4000. (1, 421, 420420): total is 4000 (1, 421, 420421): total is 0. (2, 420, 420420): total is 6000. (2, 420, 420421): total is 6000. (2, 421, 420420): total is 6000. (2, 421, 420421): total is 4000.The expected value is .In the second sample, no combination of quantities will garner the sharks any money.
PASSED
1,700
standard input
2 seconds
The first line of the input contains two space-separated integers n and p (3 ≀ n ≀ 100 000, 2 ≀ p ≀ 109)Β β€” the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime. The i-th of the following n lines contains information about i-th sharkΒ β€” two space-separated integers li and ri (1 ≀ li ≀ ri ≀ 109), the range of flowers shark i can produce. Remember that si is chosen equiprobably among all integers from li to ri, inclusive.
["4500.0", "0.0"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int i,n,p,c,d; int a[100001][2],b[100001]; double sum,s,e[100001]; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); scanf("%d%d",&n,&p); for(i=1;i<=n;i++) { scanf("%d%d",&a[i][0],&a[i][1]); e[i]=a[i][1]-a[i][0]+1; c=a[i][0]%p;d=a[i][1]-a[i][0]+1+c-p; if(c==0)d+=p; b[i]=d/p;if(d%p!=0&&d>0) b[i]++; //printf("%d %d %d %f\n",a[i][0],a[i][1],b[i],e[i]); } sum=0; //for(i=1;i<=n;i++) //printf("%d %d\n",b[i],e[i]); for(i=1;i<n;i++) { //printf("%d %d\n",b[i],e[i]); //s=(e[i]-b[i])*(e[i+1]-b[i+1])/e[i];printf("%f\n",s); s=2000*(1-(e[i]-b[i])*(e[i+1]-b[i+1])/e[i]/e[i+1]);sum+=s;} s=2000*(1-(e[1]-b[1])*(e[n]-b[n])/e[1]/e[n]);sum+=s; printf("%f\n",sum); return 0; }
There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.Each shark will grow some number of flowers si. For i-th shark value si is random integer equiprobably chosen in range from li to ri. Wet Shark has it's favourite prime number p, and he really likes it! If for any pair of neighbouring sharks i and j the product siΒ·sj is divisible by p, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks.At the end of the day sharks sum all the money Wet Shark granted to them. Find the expectation of this value.
Print a single real number β€” the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6. 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
5aad0a82748d931338140ae81fed301d
6b5a60d9873794984c41b6e8496c48b4
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "combinatorics", "number theory", "probabilities", "math" ]
1454249100
["3 2\n1 2\n420 421\n420420 420421", "3 5\n1 4\n2 3\n11 14"]
NoteA prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of flowers (s0, s1, s2) each shark grows: (1, 420, 420420): note that s0Β·s1 = 420, s1Β·s2 = 176576400, and s2Β·s0 = 420420. For each pair, 1000 dollars will be awarded to each shark. Therefore, each shark will be awarded 2000 dollars, for a total of 6000 dollars. (1, 420, 420421): now, the product s2Β·s0 is not divisible by 2. Therefore, sharks s0 and s2 will receive 1000 dollars, while shark s1 will receive 2000. The total is 4000. (1, 421, 420420): total is 4000 (1, 421, 420421): total is 0. (2, 420, 420420): total is 6000. (2, 420, 420421): total is 6000. (2, 421, 420420): total is 6000. (2, 421, 420421): total is 4000.The expected value is .In the second sample, no combination of quantities will garner the sharks any money.
PASSED
1,700
standard input
2 seconds
The first line of the input contains two space-separated integers n and p (3 ≀ n ≀ 100 000, 2 ≀ p ≀ 109)Β β€” the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime. The i-th of the following n lines contains information about i-th sharkΒ β€” two space-separated integers li and ri (1 ≀ li ≀ ri ≀ 109), the range of flowers shark i can produce. Remember that si is chosen equiprobably among all integers from li to ri, inclusive.
["4500.0", "0.0"]
#include <stdio.h> int main() { int p,n,i,t,l,r; double ans=0,x[100100]; scanf("%d%d",&n,&p); t=0; for(i=1;i<=n;i++) { scanf("%d%d",&l,&r); t=r/p-l/p; if(l%p==0) t++; x[i]=1-(double)t/(r-l+1); } for(i=1;i<n;i++) ans+=1-x[i]*x[i+1]; ans+=1-x[n]*x[1]; ans*=2000; printf("%.9f\n",ans); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
8c0511470f631334afa576572c50cf1c
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> int main(){ long long int d; int n,count=0; scanf("%d",&n); scanf("%lld",&d); int a[n]; for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(a[j]-a[i]>=(-d) && a[j]-a[i]<=d) count+=1;} } printf("%d",count-n); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
ee8a0e757fa479548c1f13acd719f937
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> #include<math.h> #define max 1000000 int main() { long long int i,j,n,m,l,k=0,a[max]; scanf("%lld%lld",&n,&m); for(i=0;i<n;i++) scanf("%lld",&a[i]); for(i=0;i<n-1;i++) { l=i; for(j=i+1;j<n;j++) { if(fabs(a[l]-a[j])<=m) { k++; } } } printf("%lld",k*2); }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
8a75e3679786477496216224fa6b382d
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include <stdio.h> #include <math.h> int a[1001],n,i,j, count, d; int main() { scanf("%d %d", &n, &d); for (i = 1; i <= n; i++) scanf("%d", &a[i]); for (i = 1; i < n; i++) for (j = 1 + i; j <= n; j++) if (abs(a[j] - a[i]) <= d) count+=2; printf("%d", count); }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
445a2ce633f1016d0d29524ba70fc214
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> int main() {int n,i,j,temp,count=0; long long int d; scanf("%d%I64d",&n,&d); int a[n]; for(i=0;i<n;i++) {scanf("%d",&a[i]); } for(i=0;i<n;i++) {for(j=0;j<n;j++) { if(i!=j) {if((a[i]-a[j])<=d&&(a[i]-a[j])>=(-d)) count++; } } } printf("%d",count); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
d9a020d0abba53743658fc88da418967
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> #include<math.h> int main(){ int n,d; scanf("%d %d",&n,&d); int a[n],i,j,k=0; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++){ for(j=0;j<n;j++)if(j!=i && abs(a[i]-a[j])<=d) k++; } printf("%d",k); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
ae4a57b8b34ce4cf30fb5d73bce40be4
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> int main() {int n,i,j,temp,count=0; long long int d; scanf("%d%lld",&n,&d); int a[n]; for(i=0;i<n;i++) {scanf("%d",&a[i]); } for(i=0;i<n;i++) {for(j=0;j<n;j++) { if(i!=j) {if((a[i]-a[j])<=d&&(a[i]-a[j])>=(-d)) count++; } } } printf("%d",count); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
3c5f1097bfce6beffba40dd872131ad3
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include <stdio.h> #include <stdlib.h> int main(){ int n, d, i, j, k, count=0; scanf("%d%d",&n,&d); int arr[n]; for(i=0;i<n;i++){ scanf("%d",&arr[i]); } for(i=0;i<n;i++){ for(j=i+1;j<n;j++){ k=abs(arr[i]-arr[j]); if(k<=d){ count+=1; } } } printf("%d",2*count); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
4d3df921c9e7707f5ac3f9baaa970d82
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> #include<stdlib.h> int main(void) { int n,p; scanf("%d %d",&n,&p); int ara[n]; int i,j,k,l; for(i=0; i<n; i++) scanf("%d",&ara[i]); int count=0; for(i=0; i<n; i++) { for(j=0; j<n; j++) { if(abs(ara[i]-ara[j])<=p && i!=j) count++; } } printf("%d",count); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
5cdc65deef8cd08cb6df56056b7b2332
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include <stdio.h> int main() {long long int n,d; scanf("%lld%lld",&n,&d); long long int a[n+3],i,j,sum=0; for(i=0;i<n;i++) {scanf("%lld",&a[i]);} for(i=0;i<n;i++) {for(j=0;j<n;j++) {if(a[i]-a[j]<=d && a[i]-a[j]>=(-d) && i!=j) sum=sum+1;}} printf("%lld",sum); }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
32d006162b89c5408e3b65de104b8c8b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include <stdio.h> #include <stdlib.h> #include <math.h> #define N_LIMIT 1001 // 1e5+1 typedef long long ll; int a[N_LIMIT]; int comparator(const void *p, const void *q) { return (*(int *)p-*(int*)q); } int main(int argc, char *argv) { int n, d; int i, j, k; int count = 0; scanf("%d %d", &n, &d); for (i=1; i<=n; i++) { scanf("%d", &a[i]); } qsort(&a[1], n, sizeof(int), comparator); //for (i=1; i<=n; i++) //{ //printf("%d ", a[i]); //} //printf("\n"); i=1; j=2; k=1; while (i<=n) { while (j<=n && a[j] <= a[i]+d) { j ++; } j --; count += j - i; count += i - k; //printf("%d %d %d, %d %d %d; %d\n", i, j, k, a[i], a[j], a[k], count); i ++; while (a[k]<a[i]-d) { k ++; } } printf("%d", count); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
99670a086291304f58db5140a9c568cc
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include <stdio.h> int main() { int n,d,a[1000],x,j,i; long long int ans=0; scanf("%d %d",&n,&d); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { x = abs(a[j]-a[i]); if(x <= d) { ans += 2; } } } printf("%I64d\n",ans); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
4395821179c4fa202ec99b5dca2da5d0
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> int main() {int n,i,j,temp,count=0; long long int d; scanf("%d%lld",&n,&d); int a[n]; for(i=0;i<n;i++) {scanf("%d",&a[i]); } for(i=0;i<n;i++) {for(j=0;j<n;j++) { if(i!=j) {if((a[i]-a[j])<=d&&(a[i]-a[j])>=(-d)) count++; } } } printf("%d",count); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
c3e511c38123302c908e1c3389e437ee
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> #include<stdlib.h> int main() { int i,j,a[1001],d,n,c = 0; scanf("%d%d",&n,&d); for(i = 0; i < n; i++) { scanf("%d",&a[i]); } for(i = 0; i < n; i++) { for(j = i+1; j < n; j++) { if(abs(a[i]-a[j]) <= d) { c++; } } } printf("%d",c*2); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
d2843dd11ed96451fe4712fd550071e7
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include <stdio.h> int main() { int n,d; scanf("%d%d",&n,&d); int a[n]; for(int i=0;i<n;i++) scanf("%d",&a[i]); int k=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) if(abs(a[i]-a[j])<=d && i!=j) k++; } printf("%d\n",k); }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
611336e95d3320f791f0c0c7a67f0e42
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include <stdio.h> #include<stdlib.h> int main() {int n,d,nb,i,j; scanf("%d",&n); scanf("%d",&d); int t[n]; for(i=0;i<n;i++) scanf("%d",t+i); for(i=0,nb=0;i<(n-1);i++) for(j=i+1;j<n;j++) if (abs(t[i]-t[j])<=d) nb++; printf("%d",2*nb); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
ef3e45770479855e25756a0324018aff
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include <stdio.h> #include<stdlib.h> int main() {int *n,*d,*t,nb,i,j; n=(int*)malloc(sizeof(int)); d=(int*)malloc(sizeof(int)); scanf("%d",n); t=(int*)malloc(sizeof(int)*(*n)); scanf("%d",d); for(i=0;i<(*n);i++) scanf("%d",t+i); for(i=0,nb=0;i<((*n)-1);i++) for(j=i+1;j<(*n);j++) if (abs(t[i]-t[j])<=*d) nb++; free(n); free(d); free(t); printf("%d",2*nb); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
84695fa8aee07aa8b125349d33374363
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#pragma warning(disable:4996) #include <stdio.h> #include <malloc.h> #include <math.h> #include <stdlib.h> int lol(const void *x1, const void *x2) { return *(int*)x1 - *(int*)x2; } /* int main(void) { int n,x,y, flag =1; scanf("%i", &n); for (x = 4; x <= 999996 && flag; x+=2) for (y = 999996; y >= 4 && flag; y-=2) if (((n - y) / x == 1 || (n - x) / y == 1) && ((n - y) % x == 0 || (n - x) % y == 0)) flag = 0; printf("%i %i", x,y); return 0; } */ /* int gcd(int a, int b) { int c; while (b) { c = a % b; a = b; b = c; } return a; }*/ int main(void) { int n, d, j,i, count=0, a[1000]; scanf("%i%i", &n, &d); for (i = 0; i < n; i++) scanf("%i", &a[i]); qsort(a, n, sizeof(int), lol); for (i = 0; i < n - 1; i++) for (j = i + 1; j < n; j++) if (a[j] - a[i] <= d) count++; printf("%i", count * 2); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
d1d92282b6f2c7a7965f26133f41eb9b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> int rec_for(int a[],int,int); int main() { int n;long d; scanf("%d%lu",&n,&d); int a[n]; for(int i=0;i<n;i++){ scanf("%d",&a[i]); } int c=rec_for(a,n,d); printf("%d",c); return 0; } int rec_for(int a[],int n,int d){ int f=0; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(a[j]-a[i]>=-d && a[j]-a[i]<=d){ f+=2; } } } return f; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
6f6fc8a07da7c3ebef7ecfe32d14d50d
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include <stdio.h> #include <stdlib.h> int cm(const void *a, const void *b){if ( *(long long int*)a-*(long long int *)b > 0) return 1; else return -1;} int main(){ int i,n; long long int d,a[1001],ans = 0LL; scanf("%i%lli",&n,&d); for(i=0;i<n;i++) scanf("%lli",a+i); qsort(a,n,sizeof a[0],cm); for(i=0;i<n-1;i++){ int j; for (j=i+1;j<n && a[j]-a[i]<=d;j++) ans+=2; } printf("%i\n",ans); return 0-0-0;}
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
ec23a06bef5ecd16c575be02e4b037dd
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> #include<stdlib.h> int fun(int [],int ,int ); int fun(int a[],int n,int d) { int i,j,ans=0; for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(abs(a[j]-a[i])<=d) { ans=ans+2; } } } return ans; } int main() { int a[1001]; int n,i,d; scanf("%d%d",&n,&d); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("%d\n",fun(a,n,d)); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
3699d5d78ec03ee26838f64af215de2d
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> #include<math.h> #include<string.h> int main() { int n,m,i,j,x,c=0; scanf("%d %d",&n,&m); int a[n]; for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++){ for(j=0;j<n;j++) { x=((a[i]-a[j])>0?(a[i]-a[j]):(a[j]-a[i])); { if(x<=m && j!=i) { c++; } } } } printf("%d",c); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
ac672a7c26272bcac6bc4f2b4a23725a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> int main() { int n,i=0,j,count=0; long int d; scanf("%d",&n); scanf("%ld",&d); int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if((a[i]-a[j])<=d && (a[i]-a[j])>0) count+=2; if((a[j]-a[i])<=d && (a[j]-a[i])>0) count+=2; if((a[j]-a[i])==0) count+=2; } } printf("%d",count); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
eea56aa6ed90844931d0c0369435e6df
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> int main(){ int n,d,j,i,count=0,a[100000]; scanf("%d %d",&n,&d); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n-1;i++){ for(j=i+1;j<n;j++){ if(abs(a[j]-a[i])<=d) count++; } } printf("%d",2*count); }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
5a9dee6f0c23b1bea6b876b4632f461a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> int main() {int n,i,j,temp,count=0; long long int d; scanf("%d%lld",&n,&d); int a[n]; for(i=0;i<n;i++) {scanf("%d",&a[i]); } for(i=0;i<n;i++) {for(j=0;j<n;j++) { if(i!=j) {if((a[i]-a[j])<=d&&(a[i]-a[j])>=(-d)) count++; } } } printf("%d",count); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
6c0716c75d03e112ab7430ed56632c61
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> #include<math.h> #include<stdlib.h> int main() { int n,i,j,d,count=0; scanf("%d%d",&n,&d); int ara[1005]; for(i=0; i<n; i++) { scanf("%d",&ara[i]); } for(i=0; i<n; i++) { for(j=i+1; j<n; j++) { if((ara[i]-ara[j]<=d && ara[i]-ara[j] >= 0) || (ara[j]-ara[i]<=d && ara[j]-ara[i] >= 0)) { count++; } } } printf("%d",count*2); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
1ae1b87e11faa848a0a33a3677d233b0
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> int main() {int n,i,j,temp,count=0; long long int d; scanf("%d%lld",&n,&d); int a[n]; for(i=0;i<n;i++) {scanf("%d",&a[i]); } for(i=0;i<n;i++) {for(j=0;j<n;j++) { if(i!=j) {if((a[i]-a[j])<=d&&(a[i]-a[j])>=(-d)) count++; } } } printf("%d",count); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
ff92f54d46afcbbceb0d1ffbe6dcaea2
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> int main() {long long n,temp,count=0; long long d; scanf("%lld%lld",&n,&d); int a[n]; for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int i=0;i<n;i++) {for(int j=0;j<n;j++) { if(i!=j) {if((a[i]-a[j])<=d&&(a[i]-a[j])>=(-d)) count++; } } } printf("%d",count); return 0; }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
78770573031ecb1885f9f2e3406d6dc3
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> long d; int n,diff,ctd=0; int main() { scanf("%d %ld",&n,&d); int a[n]; for(int i=0;i<n;i++) { scanf(" %d",&a[i]); } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { diff=(a[i]-a[j])>0?(a[i]-a[j]):(a[j]-a[i]); if((i!=j)&&(diff<=d)) { ctd++; } } } printf("%d",ctd); }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
aba572eaacc87e091665350f0b399131
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include<stdio.h> int main() { int n,m,a[100000],s=0,j,c,i; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]){c=a[i];a[i]=a[j];a[j]=c; } } } for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(a[j]-a[i]<=m)s+=2; } } printf("%d",s); }
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.
Output one number β€” amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.
C
d7381f73ee29c9b89671f21cafee12e7
c152766bdc871aae4f9a1ea3c4ebac12
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "brute force" ]
1286002800
["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"]
null
PASSED
800
standard input
2 seconds
The first line contains two integers n and d (1 ≀ n ≀ 1000, 1 ≀ d ≀ 109) β€” amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers β€” heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.
["6", "6"]
#include <stdio.h> #include<stdlib.h> int main() { int n,d; scanf("%d %d",&n,&d); int arr[n]; for(int i=0;i<n;i++){ scanf("%d",&arr[i]); } int cnt=0; for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ if(abs(arr[i]-arr[j])<=d){ cnt++; } } } printf("%d",2*cnt); return 0; }