prob_desc_description
stringlengths
63
3.8k
prob_desc_output_spec
stringlengths
17
1.47k
lang_cluster
stringclasses
2 values
src_uid
stringlengths
32
32
code_uid
stringlengths
32
32
lang
stringclasses
7 values
prob_desc_output_to
stringclasses
3 values
prob_desc_memory_limit
stringclasses
19 values
file_name
stringclasses
111 values
tags
listlengths
0
11
prob_desc_created_at
stringlengths
10
10
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_notes
stringlengths
4
3k
exec_outcome
stringclasses
1 value
difficulty
int64
-1
3.5k
prob_desc_input_from
stringclasses
3 values
prob_desc_time_limit
stringclasses
27 values
prob_desc_input_spec
stringlengths
28
2.42k
prob_desc_sample_outputs
stringlengths
2
796
source_code
stringlengths
42
65.5k
hidden_unit_tests
stringclasses
1 value
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u > v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u > v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
7a4420ee192c433c5223b4e28af6ac44
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> #include<string.h> int ans[305][305] = {}; int main() { int n; scanf("%d", &n); int tt=n*n; for (int j = 0; j < n; j++) { for (int i = 0; i < n; i++) { ans[i][j] = tt; tt--; } j++; for (int i = n-1; i >= 0; i--) { ans[i][j] = tt; tt--; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { printf("%d ", ans[i][j]); } printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
4ada43ae5b1c95f653863034585e77b1
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include <stdio.h> int main(int arg, char** argv){ int n; scanf("%d", &n); int ans[n][n]; int dir = -1; int i = 0; int place = 1; for(int j = 0; j < n; j++){ for(int k = 0; k < n; k++){ ans[i][j] = place; place++; if(dir == -1 && i < n-1) i++; if(dir == 1 && i > 0) i--; } dir *= -1; } for(i = 0; i < n; i++){ for(int j = 0; j < n; j++){ printf("%d ", ans[i][j]); } printf("\n"); } }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
fc2416a4669a8463965f4a92159924e8
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int main() { long int n; scanf("%ld",&n); for(int i=0;i<n;i++) { for(int j=0;j<(n+1)/2;j++) { printf("%ld",n*n-i-n*j); printf(" "); } for(int j=0;j<n/2;j++) { printf("%ld",1+n*j+i); printf(" "); } printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
48763415efab423f96aecd37a3317534
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include <stdio.h> int main() { int n, i, j; scanf("%d", &n); for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) printf("%d ", n * j + ((j % 2 == 0) ? i : n - 1 - i) + 1); printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
9acf8c6f616d10cdc4e1d9ffbf500f7b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include <stdio.h> int main() { int a, b; int n; scanf("%d", &n); for (a = 1; a <= n; a++) { printf("%d", a); for (b = 1; b < n; b++) { if (b & 1) { printf(" %d", n + 1 - a + n * b); } else { printf(" %d", a + n * b); } } printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
dfe39d6fa5111bc106e8b76fead08dd4
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include <stdio.h> #include <stdlib.h> int main() { int n, i, j; scanf("%d", &n); for(i = 0; i < n; i++){ printf("%d ", i+1); for(j = 0; j < n-1; j += 2){ printf("%d ", n*(2+j) - i); if(j < n-2) printf("%d ", n*(3+j) - (n-i-1)); } printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
5d474aca794f8bd6c9a0443e2c0beb18
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #define pr 0.0000001 typedef long long ll; long long max(long long a, long long b); long long min(long long a, long long b); int comparetor (const void * a, const void * b);//for qsort in ascending order unsigned long long greatestpowerof2lessthan(unsigned long long a); //above function has unsigned for more acciracy. so use type casting. unsigned long long leastpowerof2greaterthan(unsigned long long a); //above function has unsigned for more acciracy. so use type casting. int main() { int arr[305][305] = {0}; int n; scanf("%d", &n); int k=1; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) arr[j][i] = k++; } for(int j=1; j<n; j+=2) { for(int i=0; i<n/2; i++) { int temp = arr[i][j]; arr[i][j] = arr[n-i-1][j]; arr[n-i-1][j] = temp; } } for(int i=0; i<n; i++) { for(int j=0; j<n; j++) printf("%d ", arr[i][j]); printf("\n"); } return 0; } long long max(long long a, long long b) { if(a>=b) return a; else return b; } long long min(long long a, long long b) { if(a<=b) return a; else return b; } int comparetor (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } unsigned long long greatestpowerof2lessthan(unsigned long long a) { unsigned long long ans=1, curr=1; for(int i=0, upperlimit=8*sizeof(unsigned long long); i<upperlimit; i++) { curr = 1<<i; if(curr>a) break; ans = curr; } return ans; } unsigned long long leastpowerof2greaterthan(unsigned long long a) { unsigned long long curr=1; for(int i=0, upperlimit=8*sizeof(unsigned long long); i<upperlimit; i++) { curr = 1<<i; if(curr>=a) break; } return curr; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
86047e547c9848e01e7df10962b3d70a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int main() { int n,flag=0; scanf("%d",&n); int diff=2*n-1; for(int r=1;r<n+1;r++) { int p=r; flag=0; printf("%d ",p); for(int x=0;x<n-1;x++) { if(flag==0) { p=p+diff; flag=1; } else { p=p+2*n-diff; flag=0; } printf("%d ",p); } printf("\n"); diff=diff-2; } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
2811aceadfa11c11631e1ceb8af16faf
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include <stdio.h> #include <stdlib.h> #define N 300 // int cmpfunc (const void * a, const void * b) { // return ( *(int*)a - *(int*)b ); // } // qsort(values, 5, sizeof(int), cmpfunc); int main() { int n, i, j; scanf("%d", &n); int A[N][N]; j = -1; while (++j < n){ if (j%2 == 0){ i = -1; while (++i < n) A[i][j] = i + 1 + n*j; } else { i = -1; while (++i < n) A[n-1-i][j] = i + 1 + n*j; } } i = -1; while (++i < n){ j = -1; while (++j < n) printf("%d ", A[i][j]); printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
3ab0cc53e3f9a24409eb89ebb7a6634a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include <stdio.h> #include <stdlib.h> int main() { int n, i, j; scanf("%d", &n); for(i = 0; i < n; i++){ printf("%d ", i+1); for(j = 0; j < n-1; j += 2){ printf("%d ", n*(2+j) - i); if(j < n-2) printf("%d ", n*(3+j) - (n-i-1)); } printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
9559a3474d2c9f9dbe0a5a73f36165cd
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++){ for(int j=0;j<n;j++){ if(j%2==1) printf("%d ",n*j+i); else{ printf("%d ",n*(j+1)-i+1); } } printf("\n"); } }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
de87930169b35408773b9180c07e5378
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
n; id(i, j) { return (i - 1) * n + j; } main(i, j) { scanf("%d", &n); for (i = 1; i <= n / 2; i++) { for (j = 1; j <= n; j++) printf("%d%c", id(j, j % 2 ? i : n - i + 1), " \n"[j == n]); for (j = 1; j <= n; j++) printf("%d%c", id(j, j % 2 ? n - i + 1 : i), " \n"[j == n]); } if (n % 2) for (j = 1; j <= n; j++) printf("%d%c", id(j, n / 2 + 1), " \n"[j == n]); }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
6e27f954f964aef45fb2c6f3c9779888
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
/* practice with Dukkha */ #include <stdio.h> int main() { int n, k, i, j; scanf("%d", &n); k = n / 2; for (i = 0; i < n; i++) { for (j = i * k; j < i * k + k; j++) printf("%d ", j + 1); if (n % 2 == 1) printf("%d ", k * n + i + 1); for (j = i * k; j < i * k + k; j++) printf("%d ", n * n - j); printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
25f4ebc89a9d6dcea015bd642228b283
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int main() { int m; int x=1; int n; scanf("%d",&n); int s=n*n; int t=s; int a[300000]; int i,j; if(n%2==0) { for(i=1,j=1;i<=s;i++,j++) { if(n/j>=2) a[i]=x++; else a[i]=t--; if(j==n) j=0; } } else { m=(n/2); m=m*n+1; for(i=1,j=1;i<=s;i++,j++) { if(n/j>=2) a[i]=x++; else if(j==n/2+1) a[i]=m++; else a[i]=t--; if(j==n) j=0; } } for(i=1;i<=s;i++){ printf("%d ",a[i]); if(i%n==0) printf("\n"); } }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
847b65e797002868dd19fafb558b93ca
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int WTF[302][302]; int main(){ int n;scanf("%d",&n); for(int j=0;j<n;j++){ if(j%2==0){ for(int i=0;i<n;i++)WTF[i][j]=j*n+i; } else{ for(int i=0;i<n;i++)WTF[n-i-1][j]=j*n+i; } } for(int i=0;i<n;i++){for(int j=0;j<n;j++)printf("%d ",WTF[i][j]+1);printf("\n");} return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
c74a88076396fd2ade39707232c6a4e5
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int main() { #ifndef ONLINE_JUDGE freopen("test.in","r",stdin); freopen("test.out","w",stdout); #endif int n, i, s, x, y, c=0; scanf("%d", &n); x=(n*2)-1; y=1; for(i=1; i<=n; i++) { s=i; c=0; while(s<=(n*n)) { printf("%d ", s); if(c%2==0) { s+=x; } else { s+=y; } c++; } x-=2; y+=2; printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
8e967662c46e8fafb3877ab78ae3ed81
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include <stdio.h> typedef long long int ll; int main() { ll n; scanf("%lld", &n); ll arr[n][n]; int i = 1; int j; while (i <= n) { j = 1; while (j <= n) { if (j % 2 == 0) { arr[i - 1][j - 1] = ((j - 1) * n + i); } else { arr[i - 1][j - 1] = (j * n) - i + 1; } j++; } i++; } i = 0, j = 0; while (i < n) { j = 0; while (j < n) { printf("%lld", arr[i][j]); if (j != n - 1) printf(" "); j++; } printf("\n"); i++; } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
31769ab7e99551e2ad70682177fb026b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int main() { int n, i, j; scanf("%d", &n); for(i=1; i<=n; i++) { for(j=0; j<n; j++) { if(j&1) { printf("%d ", n*(j+1)-i+1); } else { printf("%d ", n*j + i); } } printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
f6e3c9a88d21134196ccad76aee58b1a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> #include<string.h> #define int long long signed main() { int n; scanf("%lld",&n); int k=n*n; int arr[n+1][n+1]; int num=1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { arr[i][j]=num; num++; } } for(int i=1;i<n;i+=2) { for(int j=0;j<n/2;j++) { int temp=arr[i][j]; arr[i][j]=arr[i][n-j-1]; arr[i][n-j-1]=temp; } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { printf("%lld ",arr[j][i]); } printf("\n"); } }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
16fbeeac879899d7efed46319459491f
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> #include<math.h> #include<stdlib.h> int main() { int a,b,c,i,j,m,n,ans,l,g1=0,g=0,h; scanf("%d",&n); for(i=1; i<=n; i++) { for(j=0;j<n;j++) { if(j%2==0) { l=(n*j)+i; printf("%d ",l); } else { l=n*(j+1)-i+1; printf("%d ",l); } } printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
7c0727a8b2fbb96d400a655e6a2c246a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include <stdio.h> int main() { int n; scanf("%d", &n); int square = n*n; int arr[n][n]; for(int i=0; i<n; i++) { if(i%2 == 0) { for(int j=0; j<n; j++) { arr[i][j] = square; square--; } } else { for(int j=n-1; j>=0; j--) { arr[i][j] = square; square--; } } } for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { printf("%d ", arr[j][i]); } printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
243351c56ae3e38aacc92c30bbcc3c7f
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include <stdio.h> int main(void) { // your code goes here int n; scanf("%d",&n); int arr[n][n]; int k=1; int i=0; int c=0; int flag=1; while(i<n && c<n) { if(flag==1) { //printf("%d",k); arr[i][c]=k; i++; } else { //printf("%d",k); arr[i][c]=k; i--; } if(k%n==0) { if(flag==1) { flag=0; i=n-1; c++; } else { flag=1; c++; i=0; } } k++; } for(int j=0;j<n;j++) { for(int l=0;l<n;l++) { printf("%d ",arr[j][l]); } printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
13f0a217e88af94cf4b52700cfc565b1
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int main() { int n,i,j,x=0,ara[400][400],z=1; scanf("%d",&n); while(1){ if(x==n){ break; } if(x%2==0){ for(i=0;i<n;i++){ ara[i][x]=z; z++; } x++; } else{ for(i=n-1;i>=0;i--){ ara[i][x]=z; z++; } x++; } } for(i=0;i<n;i++){ for(j=0;j<n;j++){ printf("%d ",ara[i][j]); } printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
5846a4da8644ba2c8b6344f3d31be4cb
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> #include<stdlib.h> void main() { int i,n,mark,check,pos; scanf("%d",&n); int arr[n][n]; mark = 0; check = 0; pos = 0; i = n*n; while(i>0) { arr[mark][pos] = i; i--; if(i%n==0) { pos++; if(check == 0) { check = 1; mark++; } else { check = 0; mark--; } } if(check == 0) mark++; else mark--; } for(i=0;i<n;i++) { for(pos=0;pos<n;pos++) { printf("%d ",arr[i][pos]); } printf("\n"); } exit(0); }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
d67b22851fcf3d7ae85108f2e8778499
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int group[302][302], ans[302][302], len[302]; int main(){ int n, i, j; scanf("%d", &n); for(i = 0;i < n;i++){ for(j = 0;j < n/2;j++)group[j][i] = i; for(;j < n;j++)group[j][n - 1 - i] = i; } for(i = 0;i < n;i++)for(j = 0;j < n;j++){ int x = group[i][j]; ans[x][len[x]] = i*n + j; len[x]++; } for(i = 0;i < n;i++){ for(j = 0;j < n;j++)printf("%d ", ans[i][j] + 1); printf("\n"); } /* int dubeg = n*n; */ /* for(i = 0;i < n;i++)for(j = 0;j < n;j++)if(i != j){ */ /* int l, m, cur = 0; */ /* for(l = 0;l < n;l++)for(m = 0;m < n;m++)if(ans[i][l] > ans[j][m])cur++; */ /* if(dubeg > cur)dubeg = cur; */ /* } */ /* printf("%d\n", dubeg); */ return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
2c1cc2ce5a02c2cc2a14f52337fe79a1
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include <stdio.h> int main() { int n,k,i,j,p[300][300]; scanf("%d", &n); k=1; for(i=0;i<n;i++) { for(j=0;j<n;j++,k++) { p[(i%2==0)?j:(n-1-j)][i]=k; } } for(i=0;i<n;i++) { for(j=0;j<n;j++) printf("%d ", p[i][j]); printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
2c0062587addd067ee4cebf6d9e1eeb7
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int main() { int n; scanf("%d",&n); int ar[n][n],a=1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i%2==0) ar[i][j]=a++; else ar[i][n-1-j]=a++; } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) printf("%d ",ar[j][i]); printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
c8c3116515526ac91a9b94117c4e0895
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int main() { long long int n,temp; scanf("%lld",&n); long long int a[n][n]; temp=n*n; long long int i=0,j=0; while(temp>0) { i=0; while(i<n) { a[i][j] = temp; temp--; //printf("%d %d\n",temp,a[i][j]); i++; } j++; i--; if(j<n) { while(i>=0) { a[i][j]=temp; temp--; i--; } j++; } } //printf("%lld %lld\n",a[1][0],a[2][0]); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%lld ",a[i][j]); } printf("\n"); } }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
13db70164ce3fe8cfbaef65689363eb0
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include<stdio.h> int main() { int i,n,j,k=1; int a[305][305] = {0}; scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(i%2==0) { a[i][j] = k; k++; } else { a[i][n-1-j] = k; k++; } } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d ",a[j][i]); } printf("\n"); } return 0; }
In order to do some research, $$$n^2$$$ labs are built on different heights of a mountain. Let's enumerate them with integers from $$$1$$$ to $$$n^2$$$, such that the lab with the number $$$1$$$ is at the lowest place, the lab with the number $$$2$$$ is at the second-lowest place, $$$\ldots$$$, the lab with the number $$$n^2$$$ is at the highest place.To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number $$$u$$$ to the lab with the number $$$v$$$ if $$$u &gt; v$$$.Now the labs need to be divided into $$$n$$$ groups, each group should contain exactly $$$n$$$ labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$ is equal to the number of pairs of labs ($$$u, v$$$) such that the lab with the number $$$u$$$ is from the group $$$A$$$, the lab with the number $$$v$$$ is from the group $$$B$$$ and $$$u &gt; v$$$. Let's denote this value as $$$f(A,B)$$$ (i.e. $$$f(A,B)$$$ is the sum of units of water that can be sent from a group $$$A$$$ to a group $$$B$$$).For example, if $$$n=3$$$ and there are $$$3$$$ groups $$$X$$$, $$$Y$$$ and $$$Z$$$: $$$X = \{1, 5, 6\}, Y = \{2, 4, 9\}$$$ and $$$Z = \{3, 7, 8\}$$$. In this case, the values of $$$f$$$ are equal to: $$$f(X,Y)=4$$$ because of $$$5 \rightarrow 2$$$, $$$5 \rightarrow 4$$$, $$$6 \rightarrow 2$$$, $$$6 \rightarrow 4$$$, $$$f(X,Z)=2$$$ because of $$$5 \rightarrow 3$$$, $$$6 \rightarrow 3$$$, $$$f(Y,X)=5$$$ because of $$$2 \rightarrow 1$$$, $$$4 \rightarrow 1$$$, $$$9 \rightarrow 1$$$, $$$9 \rightarrow 5$$$, $$$9 \rightarrow 6$$$, $$$f(Y,Z)=4$$$ because of $$$4 \rightarrow 3$$$, $$$9 \rightarrow 3$$$, $$$9 \rightarrow 7$$$, $$$9 \rightarrow 8$$$, $$$f(Z,X)=7$$$ because of $$$3 \rightarrow 1$$$, $$$7 \rightarrow 1$$$, $$$7 \rightarrow 5$$$, $$$7 \rightarrow 6$$$, $$$8 \rightarrow 1$$$, $$$8 \rightarrow 5$$$, $$$8 \rightarrow 6$$$, $$$f(Z,Y)=5$$$ because of $$$3 \rightarrow 2$$$, $$$7 \rightarrow 2$$$, $$$7 \rightarrow 4$$$, $$$8 \rightarrow 2$$$, $$$8 \rightarrow 4$$$. Please, divide labs into $$$n$$$ groups with size $$$n$$$, such that the value $$$\min f(A,B)$$$ over all possible pairs of groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) is maximal.In other words, divide labs into $$$n$$$ groups with size $$$n$$$, such that minimum number of the sum of units of water that can be transported from a group $$$A$$$ to a group $$$B$$$ for every pair of different groups $$$A$$$ and $$$B$$$ ($$$A \neq B$$$) as big as possible.Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values $$$f$$$ for some division.If there are many optimal divisions, you can find any.
Output $$$n$$$ lines: In the $$$i$$$-th line print $$$n$$$ numbers, the numbers of labs of the $$$i$$$-th group, in any order you want. If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.
C
d5ae278ad52a4ab55d732b27a91c2620
eb3e80fdf8d723f7f9a40e35703302f0
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation", "greedy" ]
1571319300
["3"]
NoteIn the first test we can divide $$$9$$$ labs into groups $$$\{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}$$$.From the first group to the second group we can transport $$$4$$$ units of water ($$$8 \rightarrow 3, 8 \rightarrow 4, 5 \rightarrow 3, 5 \rightarrow 4$$$).From the first group to the third group we can transport $$$5$$$ units of water ($$$2 \rightarrow 1, 8 \rightarrow 7, 8 \rightarrow 6, 8 \rightarrow 1, 5 \rightarrow 1$$$).From the second group to the first group we can transport $$$5$$$ units of water ($$$9 \rightarrow 2, 9 \rightarrow 8, 9 \rightarrow 5, 3 \rightarrow 2, 4 \rightarrow 2$$$).From the second group to the third group we can transport $$$5$$$ units of water ($$$9 \rightarrow 7, 9 \rightarrow 6, 9 \rightarrow 1, 3 \rightarrow 1, 4 \rightarrow 1$$$).From the third group to the first group we can transport $$$4$$$ units of water ($$$7 \rightarrow 2, 7 \rightarrow 5, 6 \rightarrow 2, 6 \rightarrow 5$$$).From the third group to the second group we can transport $$$4$$$ units of water ($$$7 \rightarrow 3, 7 \rightarrow 4, 6 \rightarrow 3, 6 \rightarrow 4$$$).The minimal number of the sum of units of water, that can be transported from one group to another is equal to $$$4$$$. It can be proved, that it is impossible to make a better division.
PASSED
1,300
standard input
1 second
The only line contains one number $$$n$$$ ($$$2 \leq n \leq 300$$$).
["2 8 5\n9 3 4\n7 6 1"]
#include <stdio.h> int main() { int n,i,j,c=1,a[301][301]; scanf("%d",&n); for(i=0;i<n;i++) {for(j=0;j<n;j++) {if(i%2==0) a[j][i]=c++; else a[n-j-1][i]=c++;}} for(i=0;i<n;i++){for(j=0;j<n;j++){printf("%d ",a[i][j]);}printf("\n");} return 0;}
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
c689aca3a17ffb63b87994dfcbccf9a8
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include<stdio.h> typedef long long int L; L gcd(L a,L b) { if(b==0) return a; else return gcd(b,a%b); } int main() { L a,b,g; int n; scanf("%I64d%I64d",&a,&b); g=gcd(a,b); scanf("%d",&n); while(n--) { scanf("%I64d%I64d",&a,&b); if(g<a) printf("-1\n"); else if(g>=a && g<=b) printf("%I64d\n",g); else { L i=g/a+1; L j=g/b; if(j>1) j--; while(j<=i) { if(g%j==0 && g/j>=a && g/j<=b) {printf("%I64d\n",g/j); a=-1; break;} j++; } if(a!=-1) printf("-1\n"); } } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
2bf7820617a5e6d76d3fedee40e0ecad
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include <stdio.h> #include <stdlib.h> #include <math.h> long long PGCD(long a,long b){ if (a == b ){ return a ; }else { if ( a > b ){ return PGCD (a- b ,b); }else { return PGCD ( a , b-a ); } } } int main() { long long n,a,b,low,high,max; long long div[100000]; scanf("%I64d %I64d %I64d",&a,&b,&n); int i,j,k; long long pgcd=PGCD(a,b); long long output[n]; for(i=1,j=0;i<=sqrt(pgcd);i++) { if(pgcd%i==0){ div[j]=i; div[j+1]=pgcd/i; j+=2; } } for(i=0;i<n;i++){ max=-1; scanf("%I64d %I64d",&low,&high); if(low>pgcd) output[i]=max; else{ for( k=0;k<j;k++){ if((div[k]>max)&&(div[k]>=low)&&(div[k]<=high)) max=div[k]; } output[i]=max; } } for( i=0;i<n;i++) printf("%I64d\n",output[i]); return 0; } /*9 27 3 1 5 10 11 9 11*/
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
5dabf19ca86423f08ec47b5d0d1b284b
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include <stdio.h> int pgcd(int a, int b) { while (b != 0) { int t = a % b; a = b; b = t; } return a; } int main() { int a, b,n,l,h,k=0; int i, dn = 0, Tab[10000]; scanf("%d%d", &a, &b); scanf("%d", &n); int c = pgcd(a, b); for (i = 1; i*i <= c; i++) if (c % i == 0) { Tab[k++] = i; Tab[k++] = c/i; } for (i = 0; i < n; i++) { int j, cmp = -1; scanf("%d %d", &l, &h); for (j = 0; j < k; j++) if (l <= Tab[j] && Tab[j] <= h) if (cmp == -1 || Tab[j] > cmp) cmp = Tab[j]; printf("%d\n", cmp); } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
a5e71a0bce96765b2903351405f98fa1
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include<stdio.h> int gcd(int a, int b){ if(a==0) return b; else return gcd(b%a, a); } int f(int h, int l, int p, int q){ int n, x; //x = gcd(p, q); //if(h<p) return -1; if(l>q) return -1; else if(l>p) return -1; else if(h>p) h=p; for(n=h; n>=l; ){ if(p%n==0 && q%n==0){ return n; } n = p/((p/n) + 1); } return -1; } int main() { int a, b, n, v[10000], m[10000], r[10000], i, c, d; scanf("%d %d", &a, &b); scanf("%d", &n); //printf("%d", gcd(a,b)); for(i=0; i<n; i++){ scanf("%d %d", &c, &d); r[i] = f(d, c, a, b); } for(i=0; i<n; i++){ printf("%d\n", r[i]); } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
7bcb904f585b868229d9f6def82b5199
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include <stdio.h> #include <stdlib.h> int gcd(int a, int b) { if (a < b) return gcd(b, a); if (a % b == 0) { return b; } else { return gcd(b, a % b); } } int cmp(const void *a, const void *b) { return *((int *)b) - *((int *)a); } int main() { int a, b, g, n, p = 0, i, j; int c[10000]; scanf("%d %d", &a, &b); scanf("%d", &n); g = gcd(a, b); for (i = 1; i * i <= g; i++) { if (g % i == 0) { c[p++] = i; c[p++] = g / i; } } qsort(c, p, sizeof(int), cmp); for (i = 0; i < n; i++) { int l, r; scanf("%d %d", &l, &r); for (j = 0; j < p; j++) { if (c[j] >= l && c[j] <= r) { printf("%d\n", c[j]); break; } } if (j == p) puts("-1"); } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
e6dfc8a4872bbd6750c3584af5d26e48
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include <stdio.h> int d[50000]; int t[50000]; int calc(int g) { int i, j, m, n; m = n = 0; for (i = 1; i * i <= g; i ++) { if (g % i == 0) { d[m ++] = i; if (g / i != i) { t[n ++] = g / i; } } } for (j = n - 1; j >= 0; j --) { d[m ++] = t[j]; } return m; } int gcd(int a, int b) { int ret; while (1) { if (a == 0) { ret = b; break; } if (b == 0) { ret = a; break; } if (a >= b) { a %= b; } else { b %= a; } } return ret; } void solve(int left, int right, int m) { int l, r, mid, ans; l = 0; r = m - 1; ans = -1; while (l <= r) { mid = (l + r) >> 1; if (d[mid] <= right && d[mid] >= left) { ans = d[mid]; l = mid + 1; } else if (d[mid] > right) { r = mid - 1; } else { l = mid + 1; } } printf("%d\n", ans); } int main() { int a, b, n, m, l, r, i, ret; while (scanf("%d%d", &a, &b) == 2) { ret = gcd(a, b); m = calc(ret); scanf("%d", &n); for (i = 0; i < n; i ++) { scanf("%d%d", &l, &r); solve(l, r, m); } } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
d51820568349a532456b96fd212ba697
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include <stdio.h> int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { int a, b, g, i, n, max; scanf("%d%d%d", &a, &b, &n); g = gcd(a, b); while (n-- > 0) { int low, high; scanf("%d%d", &low, &high); max = -1; for (i = 1; i * i <= g; i++) { if (g % i == 0 && i >= low && i <= high && max < g / i) max = i; if (g % i == 0 && g / i >= low && g / i <= high && max < g / i) max = g / i; } printf("%d\n", max); } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
ea3eb09f0ba54883d3b0308322943910
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include <stdio.h> int pgcd(int x, int y) { while (y != 0) { int t = x % y; x = y; y = t; } return x; } int main() { int a, b,n,l,h,k=0; int i, dn = 0, Tab[10000]; scanf("%d%d", &a, &b); scanf("%d", &n); int c = pgcd(a, b); for (i = 1; i*i <= c; i++) if (c % i == 0) { Tab[k++] = i; Tab[k++] = c/i; } for (i = 0; i < n; i++) { int j, cmp = -1; scanf("%d %d", &l, &h); for (j = 0; j < k; j++) if (l <= Tab[j] && Tab[j] <= h) if (cmp == -1 || Tab[j] > cmp) cmp = Tab[j]; printf("%d\n", cmp); } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
63e936b2630aba7d9ab9778d37076dec
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <strings.h> int *divisors; long mgcd(long a, long b); long gcd (long a, long b); int compare(const void *a, const void *b); long search(long low, long high, long max); int main (int argc, char *argv[]) { long a, b; long low, high; long n, i, max; scanf("%ld%ld", &a, &b); scanf("%ld", &n); max = mgcd(a, b); for (i = 0; i < n; i++) { scanf("%ld%ld", &low, &high); printf("%ld\n", search(low, high, max)); } return 0; } long mgcd(long a, long b) { long i, j = 0; long s_gcd = gcd(a, b); long border = (long)sqrt(((long)s_gcd) + 1); divisors = (int *)malloc(sizeof(int) * border); bzero(divisors, sizeof(divisors) * sizeof(int)); for (i = 1; i <= border; i++) { if (!(s_gcd % i)) { divisors[j++] = i; divisors[j++] = s_gcd / i; } } qsort(divisors, j, sizeof(int), compare); return j - 1; } long gcd (long a, long b) { long nod; long max = (a > b) ? a : b; long min = (a < b) ? a : b; nod = max % min; while (min) { nod = max; max = min; min = nod % min; } return max; } int compare(const void *a, const void *b) { const long *ia = (const long *)a; const long *ib = (const long *)b; return *ia - *ib; } long search(long low, long high, long max) { long i; for (i = max; high < divisors[i]; i--) { ; } return (divisors[i] >= low && divisors[i] <= high) ? divisors[i] : -1; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
25aa02c95c44c925241fecd2e5e3bc3d
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include<stdio.h> #include<math.h> #define MAX 100000 main() { int a,b,i,temp; scanf("%d%d",&a,&b); int arr[MAX],act_arr[MAX],no=0,no_of_elem=0;if(a>b){temp=a;a=b;b=temp;} for(i=1;i<=(int)floor(sqrt(a));i++){if(a%i==0)arr[no_of_elem++]=i;} for(i=no_of_elem-1;i>=0;i--){if(arr[i]!=a/arr[i])arr[no_of_elem++]=a/arr[i];} for(i=0;i<no_of_elem;i++){if(b%arr[i]==0)act_arr[no++]=arr[i];} int n,l,r; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d%d",&l,&r);int low=0,high=no-1,mid; while(high>low+1) { mid=(low+high)/2; if(act_arr[mid]<l)low=mid+1; else if(act_arr[mid]>r)high=mid-1; else low=mid; } if(act_arr[high]<=r&&act_arr[high]>=l)printf("%d\n",act_arr[high]); else if(act_arr[low]<=r&&act_arr[low]>=l)printf("%d\n",act_arr[low]); else printf("-1\n"); } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
e10c122c8e25c993fe7b4d80ac2cdd6a
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include <stdio.h> int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { int i ,j,ans,a,b,l,h,n,temp; scanf("%d%d%d",&a,&b,&n); temp=gcd(a,b); while(n--) {ans=-1; scanf("%d%d",&l,&h); for(i=1;i*i<=temp;i++) { if(temp%i==0 && (i>=l && i<=h) && temp/i>ans) ans=i; if(temp%i==0 && (temp/i>=l && temp/i <=h) && temp/i >ans) ans=temp/i; } printf("%d\n",ans); } }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
b763d9bdfa73030a06ae3a7129bcf4c4
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include<stdio.h> int gcd(int a, int b){ if(a==0) return b; else return gcd(b%a, a); } int f(int h, int l, int p, int q){ int n, x; //x = gcd(p, q); //if(h<p) return -1; if(l>q) return -1; else if(l>p) return -1; else if(h>p) h=p; for(n=h; n>=l; ){ if(p%n==0 && q%n==0){ return n; } n = p/((p/n) + 1); } return -1; } int main() { int a, b, n, v[10000], m[10000], r[10000], i, c, d; scanf("%d %d", &a, &b); scanf("%d", &n); //printf("%d", gcd(a,b)); for(i=0; i<n; i++){ scanf("%d %d", &c, &d); r[i] = f(d, c, a, b); } for(i=0; i<n; i++){ printf("%d\n", r[i]); } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
eb68d7b60ff5b8a56eb0452d954555c1
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include <stdio.h> int a,b,high,low,k=0,arr[100001],t[1010]; int gcd(int x,int y){ if(y==0) return x; else return gcd(y,x%y); } int bsearch(int left,int right,int g){ int mid,c=-1,r=k,l=0; while(r>=l){ mid=(r+l)/2; if(arr[mid]<=right&&arr[mid]>=left){ l=mid+1; c=arr[mid]; } else if(arr[mid]>right) r=mid-1; else l=mid+1; } return c; } int main(){ int n,i,g,m=0,j; scanf("%d%d%d",&a,&b,&n); g=gcd(a,b); for (i = 1; i * i <= g; i ++){ if (g % i == 0){ arr[k ++] = i; if (g / i != i) t[m ++] = g / i; } } for (j = m - 1; j >= 0; j --) arr[k ++] = t[j]; while(n--){ scanf("%d%d",&low,&high); printf("%d\n",bsearch(low,high,g)); } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
4aa9c723d7ddcdfa01914b23f31bf247
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include <stdio.h> int gcd(int a, int b) { while (b != 0) { int t = a % b; a = b; b = t; } return a; } int main() { int a, b; scanf("%d%d", &a, &b); int c = gcd(a, b); int i, dn = 0, d[10000]; for (i = 1; i*i <= c; i++) if (c % i == 0) { d[dn++] = i; d[dn++] = c/i; } int n; scanf("%d", &n); for (i = 0; i < n; i++) { int l, r; scanf("%d%d", &l, &r); int j, dd = -1; for (j = 0; j < dn; j++) if (l <= d[j] && d[j] <= r) if (dd == -1 || d[j] > dd) dd = d[j]; printf("%d\n", dd); } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
6cdfc876620c7d1dfb5c1778a6e569c3
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int gcd(int a,int b) { if(a==0) return b; gcd(b%a,a); } int max(int a,int b) { if(a>b) return a; return b; } int main() { int x,b,n,a[100005],i=0,j=0; scanf("%d%d%d",&x,&b,&n); int p=gcd(x,b); int q=sqrt(p); for(i=1;i<=q+2;i++) { if(p%i==0) { if(p/i==i) { a[j++]=i; } else { a[j++]=i; a[j++]=p/i; } } } while(n--) { int l,r,ans=-1; scanf("%d%d",&l,&r); for(i=0;i<j;i++) { if(a[i]>=l && a[i]<=r) { ans=max(ans,a[i]); } } printf("%d\n",ans); } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
3efdb864c6b4a65677d9a94829ed0f3a
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include<stdio.h> #include<stdlib.h> int gcd(int a,int b) { return b?gcd(b,a%b):a; } int p[64],r[64]; int cnt,n,cnt1; int f[1000000]; void factor(int m) { int i; for(i=2;i*i<=m;i++) if (m%i==0) { p[cnt]=i,r[cnt]=0; for(;m%i==0;m/=i) r[cnt]++; cnt++; } if (m>1) p[cnt]=m,r[cnt]=1,cnt++; } void dfs(int t,int s) { int i; if (t==cnt) { f[cnt1++]=s; return ; } for(i=0;i<=r[t];i++,s*=p[t]) dfs(t+1,s); } int bf(int a[],int n,int val) { int l=0,r=n; while(l<r) if (a[(l+r)/2]<=val) l=(l+r)/2+1; else r=(l+r)/2; return l-1; } int cmp(const void *a,const void *b) { return *(int *)a-*(int *)b; } int main() { int a,b,i,d; scanf("%d %d",&a,&b); factor(gcd(a,b)); dfs(0,1); qsort(f,cnt1,sizeof(f[0]),cmp); scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d %d",&a,&b); d=bf(f,cnt1,b); if (f[d]<a) puts("-1"); else printf("%d\n",f[d]); } return 0; }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
e19c6987904aed37e857561c9bdc3e42
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include <stdio.h> int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { int i ,j,ans,a,b,l,h,n,temp; scanf("%d%d%d",&a,&b,&n); temp=gcd(a,b); while(n--) {ans=-1; scanf("%d%d",&l,&h); for(i=1;i*i<=temp;i++) { if(temp%i==0 && (i>=l && i<=h) && temp/i>ans) ans=i; if(temp%i==0 && (temp/i>=l && temp/i <=h) && temp/i >ans) ans=temp/i; } printf("%d\n",ans); } }
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
C
6551be8f4000da2288bf835169662aa2
b73560841f31dd74fff1775311126231
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "number theory" ]
1302706800
["9 27\n3\n1 5\n10 11\n9 11"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
["3\n-1\n9"]
#include "stdio.h" int gcd(int a, int b) { return (b > 0) ? gcd(b, a % b) : a; } int divs[100000]; int divsc; int main() { int a, b; scanf("%d %d", &a, &b); int gcdbuf = gcd(a, b); int i, j; divsc = 0; for(i = 1; i * i <= gcdbuf; i++) { if(gcdbuf % i == 0) { divs[divsc++] = i; } } for(i = divsc - 1; i >= 0; i--) { divs[divsc++] = gcdbuf / divs[i]; } int n, low, high; scanf("%d", &n); for(i = 0; i < n; i++) { scanf("%d %d", &low, &high); int l = -1, r = divsc; while(l + 1 < r) { if(divs[(l + r) / 2] > high) { r = (l + r) / 2; } else { l = (l + r) / 2; } } if(l != -1 && divs[l] >= low) { printf("%d\n", divs[l]); } else { printf("-1\n"); } } return 0; }
There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is located at point (xi, yi). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0, 0) and (n, m). Walls of the room are parallel to coordinate axes.At the moment 0, from the point (0, 0) the laser ray is released in the direction of point (1, 1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1, 1) in exactly one second after the start.When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print  - 1 for such sensors.
Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or  - 1 if this will never happen.
C
27a521d4d59066e50e870e7934d4b190
b9e48ef8257ebdb962bc663976ac05fe
GNU C
standard output
256 megabytes
train_002.jsonl
[ "hashing", "greedy", "number theory", "math", "implementation", "sortings" ]
1475928900
["3 3 4\n1 1\n1 2\n2 1\n2 2", "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3", "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3"]
NoteIn the first sample, the ray will consequently pass through the points (0, 0), (1, 1), (2, 2), (3, 3). Thus, it will stop at the point (3, 3) after 3 seconds. In the second sample, the ray will consequently pass through the following points: (0, 0), (1, 1), (2, 2), (3, 3), (2, 4), (1, 3), (0, 2), (1, 1), (2, 0), (3, 1), (2, 2), (1, 3), (0, 4). The ray will stop at the point (0, 4) after 12 seconds. It will reflect at the points (3, 3), (2, 4), (0, 2), (2, 0) and (3, 1).
PASSED
1,800
standard input
2 seconds
The first line of the input contains three integers n, m and k (2 ≤ n, m ≤ 100 000, 1 ≤ k ≤ 100 000) — lengths of the room's walls and the number of sensors. Each of the following k lines contains two integers xi and yi (1 ≤ xi ≤ n - 1, 1 ≤ yi ≤ m - 1) — coordinates of the sensors. It's guaranteed that no two sensors are located at the same point.
["1\n-1\n-1\n2", "1\n-1\n-1\n2\n5\n-1", "13\n2\n9\n5\n-1"]
#include <stdio.h> long long xy[2]; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int xygcd(int a, int b) { if (b == 0) { xy[0] = 1; xy[1] = 0; return a; } else { int g = xygcd(b, a % b); long t = xy[0] - a / b * xy[1]; xy[0] = xy[1]; xy[1] = t; return g; } } int main() { int n, m, k, x, y, g; long long lcm; scanf("%d%d%d", &n, &m, &k); g = gcd(n * 2, -m * 2); lcm = (long long) n * 2 / (g > 0 ? g : -g) * m * 2; while (k-- > 0) { int sx, sy; long long k; scanf("%d%d", &x, &y); if (x == y) { k = x; } else { k = -1; /*n * 2 * xy[0] - m * 2 * xy[1] = y * sy - x * sx*/ for (sx = -1; sx <= 1; sx += 2) for (sy = -1; sy <= 1; sy += 2) if ((y * sy - x * sx) % g == 0) { int c = (y * sy - x * sx) / g; long long x_; xy[0] = xy[1] = 0; xygcd(n * 2, -m * 2); x_ = (long long) xy[0] * n * 2 * c + x * sx; /* y_ = (long long) xy[1] * m * 2 * c + y * sy; */ x_ = (x_ % lcm + lcm) % lcm; if (k > x_ || k < 0) k = x_; } } printf("%lld\n", k); } return 0; }
There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is located at point (xi, yi). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0, 0) and (n, m). Walls of the room are parallel to coordinate axes.At the moment 0, from the point (0, 0) the laser ray is released in the direction of point (1, 1). The ray travels with a speed of meters per second. Thus, the ray will reach the point (1, 1) in exactly one second after the start.When the ray meets the wall it's reflected by the rule that the angle of incidence is equal to the angle of reflection. If the ray reaches any of the four corners, it immediately stops.For each sensor you have to determine the first moment of time when the ray will pass through the point where this sensor is located. If the ray will never pass through this point, print  - 1 for such sensors.
Print k integers. The i-th of them should be equal to the number of seconds when the ray first passes through the point where the i-th sensor is located, or  - 1 if this will never happen.
C
27a521d4d59066e50e870e7934d4b190
e5c866bde76b5aad52cfc57e31459844
GNU C
standard output
256 megabytes
train_002.jsonl
[ "hashing", "greedy", "number theory", "math", "implementation", "sortings" ]
1475928900
["3 3 4\n1 1\n1 2\n2 1\n2 2", "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3", "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3"]
NoteIn the first sample, the ray will consequently pass through the points (0, 0), (1, 1), (2, 2), (3, 3). Thus, it will stop at the point (3, 3) after 3 seconds. In the second sample, the ray will consequently pass through the following points: (0, 0), (1, 1), (2, 2), (3, 3), (2, 4), (1, 3), (0, 2), (1, 1), (2, 0), (3, 1), (2, 2), (1, 3), (0, 4). The ray will stop at the point (0, 4) after 12 seconds. It will reflect at the points (3, 3), (2, 4), (0, 2), (2, 0) and (3, 1).
PASSED
1,800
standard input
2 seconds
The first line of the input contains three integers n, m and k (2 ≤ n, m ≤ 100 000, 1 ≤ k ≤ 100 000) — lengths of the room's walls and the number of sensors. Each of the following k lines contains two integers xi and yi (1 ≤ xi ≤ n - 1, 1 ≤ yi ≤ m - 1) — coordinates of the sensors. It's guaranteed that no two sensors are located at the same point.
["1\n-1\n-1\n2", "1\n-1\n-1\n2\n5\n-1", "13\n2\n9\n5\n-1"]
#include<stdio.h> #include<stdlib.h> typedef long long unsigned llu; typedef unsigned u; u G(u a,u b){return b?G(b,a%b):a;} u egcd(u a,u b) { u m=b,q,r,x=0,lx=1; while(b) { r=x;x=lx-(q=a/b)*x;lx=r; r=b;b=a-b*q;a=r; } return(lx>m)?lx+m:lx; } llu F(u a,u b,u x,u y) { u g,j,ja,k;llu p,r; g=G(x,y); ja=j=G(g,G(a,b)); x/=j;a/=j; y/=j;b/=j; if((k=a%y-b%y)>=y)k+=y; g=G(G(x,y),k); if((k=a%y-b%y)>=y)k+=y; k/=g;y/=g;p=y*(llu)x; if(G(j=x/g%y,y)>1)return-1llu; k=k*(llu)egcd(j,y)%y; r=a-(x*(llu)k%p); if(r>=p)r+=p; r*=ja;p*=ja; return r; } int main() { u x,y,q,i,j;llu k,l; for(scanf("%u%u%u",&x,&y,&q);q--;) { scanf("%u%u",&i,&j);k=-1llu; if((l=F( +i, +j,x<<1,y<<1))<k)k=l; if((l=F( +i,(y<<1)-j,x<<1,y<<1))<k)k=l; if((l=F((x<<1)-i, +j,x<<1,y<<1))<k)k=l; if((l=F((x<<1)-i,(y<<1)-j,x<<1,y<<1))<k)k=l; printf("%I64d\n",k); } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
7feb0d8fed10314b5c61b16750d9fcf5
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include <stdio.h> int main(){ int n ,i,j,k,m,p=0; scanf("%d", &n); //n = 9; n = n+ 1 ; for(i=0;i < n ;i++){ for(j= n-i-1;j>0;j--){ printf(" "); } for(k=0;k<=i;k++){ if(k==0 && p==0){ printf("0"); p++ ; } else{ printf("%d ",k); } } for(m=k-2;m>=0;m--){ if(m==0 ){ printf("0"); } else{ printf("%d ",m); } } printf("\n"); } for(i=0 ; i < n ;i++){ //printf(" "); if(i < n-1){ for(j=0;j<=i;j++){ printf(" "); } } for(k= 0;k < n-i-1 ;k++){ if(k==0 && p==1 && k==n-i-2){ printf("0"); p++ ; } else{ printf("%d ",k); } } for(m= n - i-3;m>=0;m--){ if(m==0){ printf("0"); } else{ printf("%d ",m); } } if(i < n-2){ printf("\n"); } } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
bd22e83801e23138e2a5329fda2929e7
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include<stdio.h> int main() { int n,a[105][105],z=0,z1,z2=2; scanf("%d",&n); int tong=(n*2+1+n*2)/2+(n*2+1)%2; for (int i=0;i<n*2+1;i++) { if (i<=tong/2) { for (int j=1;j<=tong+i*2;j++) { if (j%2!=0) { if (tong-i*2==j) { for(int l=tong-i*2;l<=tong+i*2;l++) { if (l%2!=0) { if (l<=tong) { printf("%d",z); if (l<tong) { z++; } } else { z--; printf("%d",z); } } else { printf(" "); } } j=tong+i*2; } else { printf(" "); } } else { printf(" "); } } printf("\n"); z1=3; } else { for (int j=1;j<=n*2+1+n*2-z2;j++) { if (j%2!=0) { if (z1==j) { for(int l=z1;l<=n*2+1+n*2-z2;l++) { if (l%2!=0) { if (l<=tong) { printf("%d",z); if (l<tong) { z++; } } else { z--; printf("%d",z); } } else { printf(" "); } } j=n*2+1+n*2; } else { printf(" "); } } else { printf(" "); } } printf("\n"); z2+=2; z1+=2; } } }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
ff217eb71779d91629d21f303513586e
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include<stdio.h> int main() { int n,i,space,j,l=0; scanf("%d",&n); space=n*2; for(i=1;i<=n+1;i++) { for(j=1;j<=space;j++) { printf(" "); } space=space-2; for(j=1;j<=i;j++) { printf("%d",l); if(j<i) { printf(" "); } l++; } l--; for(j=1;j<i;j++) { if(j==1) { printf(" "); } l--; printf("%d",l); if(j<i-1) { printf(" "); } } l=0; printf("\n"); } l=0; space=space+4; for(i=n;i>=1;i--) { for(j=1;j<=space;j++) { printf(" "); } space=space+2; for(j=1;j<=i;j++) { printf("%d",l); if(j!=i) { printf(" "); } l++; } l--; for(j=1;j<i;j++) { l--; if(j==1) { printf(" "); } printf("%d",l); if(j!=(i-1)) { printf(" "); } } l=0; printf("\n"); } }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
75de48857ddc35f6893ddd8d43231d03
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include<stdio.h> int main() { int n; int i, j, ki, kj, ind; scanf("%d", &n); for(ki = 1, i = 1; i <= 2*n+1; i++) { ind = 0; for(kj = 1, j = 1; j <= 2*n+1; j++) { if(ki + kj - n - 2 == 0 && (ind == 1 || i == 1 || i == 2*n+1)) printf("%d", ki + kj - n- 2); else if(ki + kj - n-2 >= 0) printf("%d ", ki+kj-n-2); else if(ind == 0) printf(" "); if(j > n) { kj--; ind = 1; } else kj++; } if(i > n) ki--; else ki++; printf("\n"); } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
87b886bf70800436e79ac50285f6c4b3
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include<stdio.h> int main(){ int i,j,k,n,l,star,s,d,q,w,e,r,p,t; int count=0; scanf("%d",&t); n=2*t+1; p=n; star=(n-1)/2; s=star; for(i=0;i<=s;i++){ d=2*i+1; for(k=0;k<star;k++){ printf(" "); } for(j=0;j<d-1;j++){ if(d==1){printf("0"); } else printf("%d ",count); if(j<d/2 && d>0){count++; } else{count--; } } printf("0"); count=0; star--; printf("\n"); } star=(p-1)/2; for(i=0;i<s;i++){ d=2*(star-1)+1; for(k=star-1;k<s;k++){ printf(" "); } for(j=0;j<d-1;j++){ if(d==1){ printf("0"); } else printf("%d ",count); if(j<d/2 && d>0){count++; } else{count--; } } printf("0"); count=0; star--; printf("\n"); } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
23e54e090f90b1ae4b97611c51654d08
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include<stdio.h> #include<math.h> int main() { int n; int i,j,k,z,y; scanf("%d",&n); //upper part for(i=1;i<=(n+1);i++) { //space of the left part for(j=1;j<=(n+1-i);j++) { printf(" "); } //digits of the left part for(k=0;k<i-1;k++) { printf("%d ",k); } printf("%d",k); //right part for(k=0;k<(i-1);k++) { printf(" %d",(i-2-k)); } printf("\n"); } z=n; y=n-1; //lower part of the pattern for(i=1;i<=n;i++) { //left part, space for(j=1;j<=i;j++) { printf(" "); } //left part, digit print for(k=0;k<z-1;k++) { printf("%d ",k); } printf("%d",k); z--; //right part of the pattern for(k=y-1;k>=1;k--) { printf(" %d",k); } if(k>=0) { printf(" %d",k); } y--; printf("\n"); } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
c189a7a99b0b2417807d33b623939489
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include<stdio.h> int main() { int i,j,k,n,m; scanf("%d",&n); for(i=0;i<n+1;i++) { for(j=0;j<2*(n-i);j++) printf(" "); for(k=0;k<=i;k++) { printf("%d",k); if(i!=0 ) printf(" "); } for(k=i-1;k>=0;k--) { printf("%d",k); if(k!=0) printf(" ");} printf("\n"); } for(i=n-1;i>-1;i--) { for(j=0;j<2*(n-i);j++) printf(" "); for(k=0;k<i;k++) { printf("%d",k); printf(" ");} for(k=i;k>=0;k--) { printf("%d",k); if(k!=0) printf(" ");} printf("\n"); } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
19687c628bbdfe469cdd747c4effb24f
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include <stdio.h> int main() { int i,j,n; scanf("%d",&n); for(i=1;i<=n;i++) { for(j=n;j>=i;j--) { printf(" "); } printf("0"); for(j=1;j<i;j++) { printf(" %d",j); } if(i>2) { for(j=(i-2);j>=1;j--) { printf(" %d",j); } } if(i>1) { printf(" 0"); } printf("\n"); } for(i=(n+1);i>=1;i--) { for(j=i;j<(n+1);j++) { printf(" "); } printf("0"); for(j=1;j<=(i-1);j++) { printf(" %d",j); } if(i>2) { for(j=(i-2);j>=1;j--) { printf(" %d",j); } } if(i>1) { printf(" 0"); } printf("\n"); } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
9547b88c8d5e425846fa8c09d6243fed
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include <stdio.h> int i,j,n; int main() { scanf("%d",&n); for(i=0;i<=n;i++) { for(j=n;j>=i+1;j--) printf(" "); for(j=0;j<=i;j++) { printf("%d",j); if(j!=i) printf(" "); } for(j=i-1;j>=0;j--) printf(" %d",j); printf("\n"); } for(i=0;i<=n-1;i++) { for(j=0;j<=i;j++) printf(" "); for(j=0;j<=n-i-1;j++) { printf("%d",j); if(j!=n-i-1) printf(" "); } for(j=n-i-2;j>=0;j--) { printf(" %d",j); } printf("\n"); } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
8efb8ccf754d770f72fef86657db3c90
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include<stdio.h> int main () { int n,c,i,j,d,x; char b[25]; scanf("%d",&n); for(i=0;i<n*2+2;i++)b[i]=32; c=n+1; for(i=0;i<n+1;i++) { d=48+i; b[c]=d; for(j=1;j<=i;j++) { b[c+j]=d-1,b[c-j]=d-1; d=d-1; } x=j; for(j=1;j<c+x-1;j++)printf("%c ",b[j]); printf("%c",b[c+x-1]); printf("\n"); } for(i=0;i<n*2+2;i++)b[i]=32; for(i=n-1;i>=0;i--) { d=48+i; b[c]=d; for(j=1;j<=i;j++) { b[c+j]=d-1,b[c-j]=d-1; d=d-1; } x=j; for(j=1;j<c+x-1;j++)printf("%c ",b[j]); printf("%c",b[c+x-1]); printf("\n"); for(j=0;j<n*2+2;j++)b[j]=32; } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
e486f58590169f61fa3f9d2ea9011ddd
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include <stdio.h> int main() { int n,i,j,p; scanf("%d",&n); for (j=0;j<=n-1;j++){ for (i=1;i<(n-j)*2;i++){ printf(" "); } for (i=0;i<=j;i++){ printf(" %d",i); } p=j-1; //printf("%d ",p); while(p>=0){ printf(" %d",p); p--; } printf("\n"); } for (i=0;i<n;i++){ printf("%d ",i); } printf("%d",n); p=n-1; //printf("%d ",p); while(p>=0){ printf(" %d",p); p--; } printf("\n"); for (j=n-1;j>=0;j--){ for (i=1;i<(n-j)*2;i++){ printf(" "); } for (i=0;i<=j;i++){ printf(" %d",i); } p=j-1; while(p>=0){ printf(" %d",p); p--; } printf("\n"); } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
ecce7f17ee455420fd207e4413293e6b
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include<stdio.h> int main() { int i,j,n,k,l; scanf("%d",&n); for(i=1;i<=n+1;i++){ for(j=n+1-i;j>=1;j--){ printf(" ");} for(k=0;k<=i-1;k++){ if(i==1) printf("%d",k); else printf("%d ",k); } for(l=2*i-1-i;l>0;l--){ if(l!=1){printf("%d ",l-1);} else { printf("0");} } printf("\n");} for(i=n;i>=1;i--){ for(j=n+1-i;j>=1;j--){ printf(" "); } for(k=0;k<=i-1;k++){ if(i==1){ printf("%d",k); } else printf("%d ",k); } for(l=2*i-1-i;l>0;l--){ if(l!=1) {printf("%d ",l-1);} else { printf("0");} } printf("\n"); } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
d4e93f5ccaa59a6b1d075b0837ae8a09
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include <stdio.h> #include <stdlib.h> int main() { int i,j,n,k,l; scanf("%d",&n); for (i=0; i<n; i++) { for (j=n-i; j>0; j--) printf(" "); for(k=0; k<=i; k++) { if(i==0) printf("%d",k); else printf("%d ",k); } for(l=i-1; l>=0; l--) { if(l==0) printf("%d",l); else printf("%d ",l); } printf("\n"); } for (i=n; i>=0; i--) { for (j=0; j<=n-1-i; j++) printf(" "); for(k=0; k<=i; k++) { if(i==0) printf("%d",k); else printf("%d ",k); } for(l=i-1; l>=0; l--) { if(l==0) printf("%d",l); else printf("%d ",l); } printf("\n"); } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
c50a08afa3dd0f7fadbc6fb4295311fc
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include<stdio.h> int main() { int a,i,j,k; scanf("%d",&a); for(i=0;i<=a;i++) { for(j=0;j<a-i;j++) printf(" "); for(j=0;j<=i;j++) { if(i==0) printf("%d",j); else printf("%d ",j); } j--; for(;j>1;) printf("%d ",--j); j--; if(j>=0) printf("%d",j); printf("\n"); } for(i=a;i>0;i--) { for(j=0;j<=a-i;j++) printf(" "); for(j=0;j<i;j++) { if(i==1) printf("%d",j); else printf("%d ",j); } j--; for(;j>1;) printf("%d ",--j); j--; if(j>=0) printf("%d",j); if(i!=1) printf("\n"); } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
9bf0d5f31d4aa7202815ff09fb27e182
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include <stdio.h> int main() { int i,j,n; scanf("%d",&n); for(i=0;i<=n;i++) { for(j=1;j<=n-i;j++) { printf(" "); } for(j=0;j<i;j++) { printf("%d ", j); } for(j=i;j>=0;j--) { if(j==0){ printf("%d",j); }else{ printf("%d ",j) ; } } printf("\n"); } for(i=n+2;i<=2*n+1;i++){ for(j=1;j<i-n;j++) { printf(" ") ; } for(j=0;j<2*n+1-i;j++) { printf("%d ", j); } for(j=2*n+1-i;j>=0;j--) { if(j==0){ printf("%d",j); }else{ printf("%d ",j); } } printf("\n"); } return 0; }
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:           0        0 1 0      0 1 2 1 0    0 1 2 3 2 1 0  0 1 2 3 4 3 2 1 00 1 2 3 4 5 4 3 2 1 0  0 1 2 3 4 3 2 1 0    0 1 2 3 2 1 0      0 1 2 1 0        0 1 0          0Your task is to determine the way the handkerchief will look like by the given n.
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
C
7896740b6f35010af751d3261b5ef718
6751896ebfc285a39e4d019cbc2e86ef
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "implementation" ]
1317999600
["2", "3"]
null
PASSED
1,000
standard input
2 seconds
The first line contains the single integer n (2 ≤ n ≤ 9).
["0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0"]
#include<stdio.h> int main() { int i,j,k,l,n,p; scanf("%d",&n); for(j=0;j<=n;j++) { for(l=j;l<n;l++) {printf(" "); printf(" "); } for(p=0;p<j;p++) printf("%d ",p); printf("%d",j); if(j!=0) { for(p=j-1;p>=0;p--) printf(" %d",p); } printf("\n"); } for(i=1;i<=n;i++) { for(p=0;p<i;p++) printf(" "); for(p=0;p<n-i;p++) printf("%d ",p); printf("%d",n-i); for(p=n-i-1;p>=0;p--) printf(" %d",p); printf("\n"); } return 0; }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
c0d146cee6132244462a1a353f7a5a12
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
#include<stdio.h> #include<string.h> #define MAX 100001 int temp[MAX]; void mergesort(int Array[],int first,int last) { if(first>=last) return; int middle=(first+last)/2; mergesort(Array,first,middle); mergesort(Array,middle+1,last); int i,j,k; for(i=first,j=first,k=middle+1;i<=last;i++) { if(j==middle+1) temp[i]=Array[k++]; else if(k==last+1) temp[i]=Array[j++]; else if(Array[k]<Array[j]) temp[i]=Array[k++]; else temp[i]=Array[j++]; } for(i=first;i<=last;i++) { Array[i]=temp[i]; } } int main() { int m,k,n,i,remainder=0; scanf("%d %d %d",&n,&m,&k); int b[n],gaps[n-1]; int minimum_length=n; for(i=0;i<n;i++) { scanf("%d",&b[i]); if(i>0) { gaps[i-1] = b[i] - b[i-1]-1; //printf("gap=%d\n",gaps[i-1]); } } mergesort(gaps,0,n-2); for(i=0;i<n-k;i++) { //printf("gap=%d\n",gaps[i]); minimum_length = minimum_length +gaps[i]; } printf("%d",minimum_length); return 0; }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
77c17055083fb685df7a2b9ca3d8bcea
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
//practice with dukkha #include<stdlib.h> #include<stdio.h> #include<string.h> #include<math.h> void merge(int arr[], int l, int m, int r) { int i, j, k; int n1 = m - l + 1; int n2 = r - m; int L[n1], R[n2]; for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr[m + 1+ j]; i = 0; j = 0; k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } void mergeSort(int arr[], int l, int r) { if (l < r) { int m = l+(r-l)/2; mergeSort(arr, l, m); mergeSort(arr, m+1, r); merge(arr, l, m, r); } } int main() { int p,q,r; scanf("%d %d %d",&p,&q,&r); int brr[p]; for(int i=0;i<p;i++) scanf("%d",&brr[i]); int arr[p-1]; for(int i=0;i<p-1;i++) arr[i]=brr[i+1]-brr[i]; mergeSort(arr, 0, p - 2); int ans=p; for(int i=0;i<(p-r);i++) { int t=arr[i]-1; ans+=t; } printf("%d",ans); return 0; }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
726e74a109d215f9503e333739eb6cf6
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
#include <stdio.h> #include <stdlib.h> #define MAX_N 10000000 int n, m, k; int a[MAX_N]; int b[MAX_N]; int min(int a, int b) { return (a < b) ? a : b; } int cmp(const void* x, const void* y) { return *(int*)y - *(int*)x; } int main() { scanf("%d%d%d", &n, &m, &k); for (int i = 0; i < n; ++i) scanf("%d", a + i); int total = a[n - 1] - a[0] + 1; for (int i = 0; i < n - 1; ++i) { b[i] = a[i + 1] - a[i] - 1; } qsort(b, n - 1, sizeof(int), cmp); for (int i = 0; i < k - 1; ++i) { //printf("%d\n", b[i]); total -= b[i]; } printf("%d\n", total); return 0; }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
f0da724e7886ef68d88884b7f7112f86
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
#include<stdio.h> void merge(int arr[], int l, int m, int r) { int i, j, k; int n1 = m - l + 1; int n2 = r - m; int L[n1], R[n2]; for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr[m + 1+ j]; i = 0; j = 0; k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } void sort(int arr[],int l, int r) { if (l < r) { int m = l+(r-l)/2; sort(arr, l, m); sort(arr, m+1, r); merge(arr, l, m, r); } } int main() { int n,m,k; scanf("%d %d %d",&n,&m,&k); int arr[n],temp[n]; for(int i=0;i<n;i++) scanf("%d",&arr[i]); for(int i=0;i<n-1;i++) temp[i]=arr[i]-arr[i+1]; temp[n-1]=arr[n-1]-arr[0]; sort(temp,0,n-2); int sum=0; for(int i=0;i<k-1;i++) sum+=temp[i]; printf("%d",sum+temp[n-1]+k); }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
f69004b9cd353f86af8867244220b2d5
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
#include <stdio.h> #include<stdlib.h> int com(const void *a,const void *b){ int c=*(int *)a; int d=*(int *)b; if(c<d) return -1; if(c==d) return 0; return 1; } int main(void){ int n,m,k; int a[100000]; int diff[100000]; int i; int result; scanf("%d %d %d",&n,&m,&k); result=n; for(i=0;i<n;i++){ scanf("%d",&a[i]); } for(i=0;i<n-1;i++){ diff[i]=a[i+1]-a[i]; } qsort(diff,(n-1),sizeof(int),com); for(i=0;i<n-k;i++){ result+=diff[i]-1; } printf("%d",result); }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
4fb0e5d94fa915c4c5cf5ac295cea2f6
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> int i, n, m, x, b, k, t[1000000], w, p, a; int war(const void*c, const void*d) { return(*(int*)d-*(int*)c); } char s[400000]; int main() { scanf("%d%d%d", &n, &m, &k); w=m; scanf("%d", &a); w=w-a+1; k--; for(i=0; i<n-1; i++) { p=a; scanf("%d", &a); t[i]=a-p-1; } w-=m-a; qsort(t, n-1, 4, war); for(i=0; i<k; i++) { w-=t[i]; } printf("%d\n", w); return(0); }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
47a5c7ad849b8410a8c54a432d68752b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
#include<stdio.h> #include<stdlib.h> #include<stdint.h> #include<inttypes.h> typedef int64_t i64; typedef int32_t i32; static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}} static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;} int cmp (const void *a, const void *b) { i32 d = *(i32 *)a - *(i32 *)b; return d == 0 ? 0 : d < 0 ? -1 : 1; } void run (void) { i32 n = read_int(); i32 m = read_int(); i32 k = read_int(); i32 *b = (i32 *) calloc (n, sizeof (i32)); for (i32 i = 0; i < n; ++i) { b[i] = read_int(); } i32 *d = (i32 *) calloc (n - 1, sizeof (i32)); for (i32 i = 0; i < n - 1; ++i) { d[i] = b[i + 1] - b[i] - 1; } qsort (d, n - 1, sizeof (i32), cmp); i32 ans = n; for (i32 i = 0; i < n - k; ++i) { ans += d[i]; } print_int (ans); puts(""); } int main (void) { run (); return 0; }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
454ca0ae442488af708dab8d58fec2f4
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
#include <stdio.h> #include <stdlib.h> int comp(const void * elem1, const void * elem2) { int f = *((int*)elem1); int s = *((int*)elem2); if (f > s) return 1; if (f < s) return -1; return 0; } int main() { int a, b, c, swap; scanf("%d %d %d", &a, &b, &c); int d[a]; for (size_t i = 0; i < a; i++) { scanf("%d", &d[i]); } int dis[a-1]; for (size_t i = 0; i < a-1; i++) { dis[i] = d[i+1] - d[i]; } qsort (dis, sizeof(dis)/sizeof(*dis), sizeof(*dis), comp); int result = 0; for (size_t i = 0; i < a - c; i++) { result += dis[i]; } printf("%d\n", result+c); return 0; }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
74c1754888c6a27a23e61e598106417a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
#include <stdio.h> #include <stdlib.h> int t[1000000]; int cmp(const void*a, const void*b) { return(*(int*)b-*(int*)a); } int main(void) { int n,m,x,b,k,w,p,a; scanf("%d%d%d",&n,&m,&k); w = m; scanf("%d", &a); w = w - a + 1; for(int i=0;i<n-1;i++){ p = a; scanf("%d",&a); t[i] = a - p - 1; //�����������ڶϵ�ľ��� } w -= m - a; //��Ҫ��������󳤶� ���� w = (w-a) - (m-a) + 1; qsort(t,n-1,sizeof(t[0]),cmp); //�����о����ɴ�С���� k--; //���Լ�ȥ�������� = ��uŶ�Ǹ������� - 1 for(int i=0;i<k;i++) w -= t[i]; //��ȥ��Խϳ��ij��� printf("%d",w); return 0; }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
0db2cd81f5a4ce788a2aa5e6e2df413f
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
#include<stdio.h> int compare(const void *a, const void *b) { return *(int *)b - *(int *)a; } int main(){ int n, m, k, first, last, prev, res; scanf("%d %d %d", &n, &m, &k); int *w = (int *)malloc(sizeof(int) * (n - 1)); scanf("%d", &first); prev = last = first; for(int i = 0;i < n - 1; ++i){ prev = last; scanf("%d", &last); w[i] = last - prev - 1; } qsort(w, n - 1, sizeof(int), compare); res = last - first + 1; for(int i = 0; i < k - 1; ++i) res -= w[i]; printf("%d\n", res); return 0; }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
07bafbc416d3089425a3862988975e61
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
#include <stdio.h> #include <math.h> #include <string.h> #include <stdbool.h> //for bool #include <stdlib.h> // abs,labs,llabs typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; //%Lf void swap(int* a, int* b){ int temp = *a; *a = *b; *b = temp; } int partition(int a[], int low, int high){ int pivot = a[high]; int i = low - 1; for(int j = low; j <= high - 1; j++){ if(a[j] >= pivot){ i++; swap(&a[i], &a[j]); } } swap(&a[i + 1], &a[high]); return(i + 1); } void quicksort(int a[], int low, int high){ if(low < high){ int pi = partition(a, low, high); quicksort(a, low, pi - 1); quicksort(a, pi + 1, high); } } int main(void) { int n, m, k, i, ans = 0; scanf("%d %d %d", &n, &m, &k); int a[n], b[n - 1]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n - 1; i++) { b[i] = (a[i + 1] - a[i] ) - 1; } quicksort(b , 0 ,n - 2); ans = (a[n - 1] - a[0]) + 1; for (i = 0; i < k - 1; i++) { ans -= b[i]; } printf("%d\n", ans); return 0; }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
168e2babdad33a1b249a657d60c82dbf
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
//Codeforces 1110B -- Tape #include <stdio.h> #include <stdlib.h> int cpr(const void * n1, const void * n2){ int u= *((int*)n1); int v = *((int*)n2); if (u > v) return 1; if (u < v) return -1; return 0; } int main(){ int a, b, c; scanf("%d %d %d", &a, &b, &c); int ar[a]; for(size_t i = 0; i<a; ++i){ scanf("%d", &ar[i]); } int ft[a-1]; for (size_t i = 0; i < a-1; ++i) { ft[i] = ar[i+1] - ar[i]; } qsort(ft, sizeof(ft)/sizeof(*ft), sizeof(*ft), cpr); int res = 0; for(size_t i=0; i< a-c; i++) res += ft[i]; printf("%d\n", res+c); return 0; }
You have a long stick, consisting of $$$m$$$ segments enumerated from $$$1$$$ to $$$m$$$. Each segment is $$$1$$$ centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length $$$t$$$ placed at some position $$$s$$$ will cover segments $$$s, s+1, \ldots, s+t-1$$$.You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.Time is money, so you want to cut at most $$$k$$$ continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?
Print the minimum total length of the pieces.
C
6b2b56a423c247d42493d01e06e4b1d2
5720de8d0b3e2403a41ff68372414bbe
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "sortings", "greedy" ]
1549546500
["4 100 2\n20 30 75 80", "5 100 3\n1 2 4 60 87"]
NoteIn the first example, you can use a piece of length $$$11$$$ to cover the broken segments $$$20$$$ and $$$30$$$, and another piece of length $$$6$$$ to cover $$$75$$$ and $$$80$$$, for a total length of $$$17$$$.In the second example, you can use a piece of length $$$4$$$ to cover broken segments $$$1$$$, $$$2$$$ and $$$4$$$, and two pieces of length $$$1$$$ to cover broken segments $$$60$$$ and $$$87$$$.
PASSED
1,400
standard input
1 second
The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 10^5$$$, $$$n \le m \le 10^9$$$, $$$1 \le k \le n$$$) — the number of broken segments, the length of the stick and the maximum number of pieces you can use. The second line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le m$$$) — the positions of the broken segments. These integers are given in increasing order, that is, $$$b_1 &lt; b_2 &lt; \ldots &lt; b_n$$$.
["17", "6"]
#include <stdio.h> #include <stdlib.h> int comp(const void *a, const void *b) { int l = *(int*)(a); int r = *(int*)(b); if (r > l) { return -1; } else if (r < l) { return 1; } else { return 0; } } int main() { int n, m, k; scanf("%d %d %d", &n, &m, &k); int a[n]; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int b[n-1]; for (int i = 0; i < n-1; i++) { b[i] = a[i+1] - a[i]; } qsort(b, n-1, sizeof(int), comp); int ans = 0; for (int i = 0; i < n-k; i++) { ans += b[i]; } printf("%d", ans+k); return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
7691f42e8c9579e5f1448f85bcbda0bc
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include<stdio.h> int main() { int n; scanf("%d",&n); int height[200001],width[200001],prefix[200001],postfix[200001]; int i,width_total=0; for(i=0;i<n;i++) { scanf("%d%d",&width[i],&height[i]); width_total+=width[i]; } int max=height[0]; prefix[0]=max; for(i=1;i<n;i++) { if(height[i]>max) { prefix[i]=height[i]; max=height[i]; } else { prefix[i]=max; } // printf("%d\n",prefix[i]); } max=height[n-1]; postfix[n-1]=max; for(i=n-2;i>=0;i--) { if(height[i]>max) { postfix[i]=height[i]; max=height[i]; } else { postfix[i]=max; } // printf("%d\n",postfix[i]); } long long ans; for(i=0;i<n;i++) { if(i-1<0) ans=(long long)postfix[i+1]*((long long )width_total-width[i]); else if(i+1>=n) ans=(long long)prefix[i-1]*((long long )width_total-width[i]); else ans=(long long)(prefix[i-1]>postfix[i+1]?prefix[i-1]:postfix[i+1])*((long long )width_total-width[i]); if(i==0) printf("%lld",ans); else printf(" %lld",ans); } putchar('\n'); return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
a72101dcfd5d68049339445f455d40e6
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include<stdio.h> #include<stdlib.h> typedef struct node { long long int width; long long int height; long long int index; }node; node *a; long long int count=0; void insert(long long int w,long long int h,long long int in) { count++; a[count].width=w; a[count].height=h; a[count].index=in; long long int i=count,flag=0; node temp; while(i>1) { if(a[i].height>a[i/2].height) { flag=1; temp=a[i]; a[i]=a[i/2]; a[i/2]=temp; } if(flag==0) break; flag=0; i=i/2; } } long long int max(long long int a,long long int b) { if(a>b) return a; else return b; } int main() { //node *a; long long int n,i,height,width,widthsum=0,maxheight,*w; scanf("%lld",&n); w=malloc(sizeof(long long int)*(n+1)); a=malloc(sizeof(node)*(n+1)); for(i=1;i<=n;i++) { scanf("%lld%lld",&width,&height); w[i]=width; insert(width,height,i); widthsum+=width; } /// printf("%d\n",count); // for(i=1;i<=n;i++) // printf("%lld %lld with index=%lld\n",a[i].width,a[i].height,a[i].index); for(i=1;i<=n;i++) { if(a[1].index==i) { if(n>2) maxheight=max(a[2].height,a[3].height); else maxheight=a[2].height; } else maxheight=a[1].height; // printf("sum of widths=%d\n",(widthsum-a[i].width)); printf("%lld ",(maxheight*(widthsum-w[i]))); } printf("\n"); free(a); free(w); return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
a964001dc3edf075460806c27fcac563
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include <stdio.h> int main() { int n,i,wSum=0,w[200000],hMax=0,hSec=0,iMax=0,h,pixels; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d%d",&w[i],&h); if(h>=hMax){ hSec=hMax; iMax=i; hMax=h; } else if(h>=hSec) { hSec=h; } wSum+=w[i]; } for(i=0;i<n;i++) { pixels = (wSum-w[i])*((i==iMax)?hSec:hMax); printf("%d ",pixels); } return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
00041fbc37ace5553c3d7583a6a758cb
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include<stdio.h> int m1=0,m2=0,xm1=0,xm2=0,n,w[200005]={0},sw=0,h[200005]={0},i; int main() { scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d %d",&w[i],&h[i]); sw+=w[i]; if(h[i]>m1) { m2=m1; xm2=xm1; m1=h[i]; xm1=i; } else if(h[i]>m2) { m2=h[i]; xm2=i; } } for(i=1;i<=n;i++) { if(i==xm1) printf("%d ",m2*(sw-w[i])); else printf("%d ",m1*(sw-w[i])); } }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
e6a8b1a2cba73344a607b48d229f3aa6
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include<stdio.h> #include<string.h> int main () { int i, n, Wsum = 0, W, H, maxh = 0, predmaxh = 0, c; scanf("%d", &n); int w[n], h[n]; for(i = 0; i < n; i++){ scanf("%d%d", &w[i], &h[i]); Wsum += w[i]; if(predmaxh < h[i]){ predmaxh = h[i]; } if(maxh < predmaxh){ c = maxh; maxh = predmaxh; predmaxh = c; } } for(i = 0; i < n; i++){ W = Wsum - w[i]; if (h[i] == maxh) H = predmaxh; else H = maxh; printf("%d ", W * H); } }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
cce5e03bd86c6c9fddf6c7a4ebcfd2da
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include "stdio.h" struct Node { unsigned int w; unsigned int h; }; unsigned int max(unsigned int x, unsigned int y) { if (x > y) { return x; } return y; } int main(){ int n,i; scanf("%d ", &n); struct Node *arr = malloc(sizeof(struct Node)*n); struct Node *left = malloc(sizeof(struct Node)*n); struct Node *right = malloc(sizeof(struct Node)*n); for (i=0 ; i<n ; i++) { scanf("%d %d ",&arr[i].w ,&arr[i].h ); } left[0].w = arr[0].w; left[0].h = arr[0].h; for (i=1 ; i<n ; i++) { left[i].w = arr[i].w + left[i-1].w; left[i].h = max(arr[i].h, left[i-1].h); } right[n-1].w = arr[n-1].w; right[n-1].h = arr[n-1].h; for (i=n-2 ; i>=0 ; i--) { right[i].w = arr[i].w + right[i+1].w; right[i].h = max(arr[i].h, right[i+1].h); } printf("%d ",right[1].h * right[1].w); for (i=1 ; i<n-1 ; i++) { printf("%d ",max(left[i-1].h, right[i+1].h) * (left[i-1].w+right[i+1].w)); } printf("%d ",left[n-2].h * left[n-2].w); return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
71affb2db6e43beddddde1ec89c7f740
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include<stdio.h> int main(){ long long int i,j,k,l,n,m,a[200000],c[200000],max1=0,max2=0; long long int sum=0; scanf("%lld",&n); for(i=0;i<n;i++){ scanf("%lld%lld",&c[i],&a[i]); if(a[i]>=max2){ max2=a[i]; if(a[i]>=max1){ max2=max1; max1=a[i]; } } sum=sum+c[i]; } for(i=0;i<n;i++){ if(a[i]==max1) printf("%lld ",(sum-c[i])*max2); else printf("%lld ",(sum-c[i])*max1); } printf("\n"); return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
db568cac3b22a96932bbbb6a429c8c08
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include <stdio.h> int main(void) { long long a[200001],min1=-1,min2=-1,n,sum,b[200001],c[200001],i; scanf("%lld",&n); for(i=0;i<n;i++){ scanf("%lld %lld",&b[i],&c[i]); sum+=b[i]; if(c[i]==min1){ min2 = min1; } if(c[i]>min1){ min2 = min1; min1 = c[i]; } else if (c[i]>min2 && i!=0){ min2 = c[i]; } } for(i=0;i<n;i++){ if(min1 == c[i]){ printf("%lld ",(sum-b[i])*min2); } else { printf("%lld ",(sum-b[i])*min1); } } return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
0656cb6fce63f7ae43380ce6e4d5524c
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include <stdio.h> /* NIIICE ONE */ int main(int argc, char *argv[]) { int i, j; long int n; struct q{ int w; int h; }; long long int result; int max = 0, max2 =0, maxPr=0; long int sum = 0; scanf("%li", &n); struct q arr[n]; for (i = 0; i<n;i++) { scanf("%d %d", &arr[i].w, &arr[i].h); sum+=arr[i].w; if (max <= arr[i].h) { max2=max; max = arr[i].h; } else if ((max2 == 0) || ((max2 <= max) && (max2 < arr[i].h))) { max2 = arr[i].h; } } maxPr = max; for (i=0; i<n;i++ ) { if (max==arr[i].h) { maxPr=max2; } result = (sum-arr[i].w)*maxPr; printf("%llu ", result); maxPr=max; } return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
81da829b9a1df2f6594042cb91a5f294
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include <stdio.h> int main() { int ara1[200000]; int ara2[200000]; int n,a=0,b=0,c=0,h,w; int i,j; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d %d",&w,&h); ara1[i]=w; ara2[i]=h; a+=w; if(h>b) { c=b; b=h; } else if(h>c) { c=h; } } for(i=0;i<n-1;i++) { w=a-ara1[i]; if(ara2[i]==b) { h=c; } else { h=b; } j=w*h; printf("%d ",j); } i=n-1; w=a-ara1[i]; if(ara2[i]==b) { h=c; } else { h=b; } j=w*h; printf("%d\n",j); return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
6bd258cb9d983997fd7b2ca84546b58f
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include <stdio.h> int main() { int ara1[200000]; int ara2[200000]; int n,a=0,b=0,c=0,h,w; int i,j; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d %d",&w,&h); ara1[i]=w; ara2[i]=h; a+=w; if(h>b) { c=b; b=h; } else if(h>c) { c=h; } } for(i=0;i<n;i++) { w=a-ara1[i]; if(ara2[i]==b) { h=c; } else { h=b; } j=w*h; printf("%d ",j); } printf("\n"); return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
dd2c74f3bf95a61f25ed87a25e3c0ddb
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include <stdio.h> int main() { int N, i, SumW, H; int W[200000]; int MaxH[2], MaxIdx; scanf("%d", &N); SumW = MaxH[0] = MaxH[1] = 0; for(i = 0; i < N; ++i) { scanf("%d %d", &W[i], &H); SumW += W[i]; if(H > MaxH[0]) { MaxH[1] = MaxH[0]; MaxH[0] = H; MaxIdx = i; } else if(H > MaxH[1]) { MaxH[1] = H; } } for(i = 0; i < N; ++i) { printf("%d ", (SumW - W[i]) * (i == MaxIdx ? MaxH[1] : MaxH[0])); } puts(""); return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
04cf8b28bd7ec71a2cf6e3b84c84e444
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include<stdio.h> #define N 200000 int main() { int n; scanf("%d",&n); int i; int w[N]; int h[N]; int sum_w=0; int max_h=0; int max_times=0; int second_max_h=0; for(i=0;i<n;i++){ scanf("%d%d",&w[i],&h[i]); sum_w+=w[i]; if(h[i]>max_h){ second_max_h=max_h; max_h=h[i]; max_times=1; }else if(h[i]==max_h){ max_times++; }else{ if(h[i]>second_max_h){ second_max_h=h[i]; } } //printf("%d %d\n",max_h,second_max_h); } //printf("sum w is %d\n",sum_w); for(i=0;i<n;i++){ if(h[i]<max_h){ printf(" %lld",(long long)(sum_w-w[i])*(long long)max_h); }else{ if(max_times>1){ printf(" %lld",(long long)(sum_w-w[i])*(long long)max_h); }else{ printf(" %lld",(long long)(sum_w-w[i])*(long long)second_max_h); } } } printf("\n"); return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
102d7e0c25b506c05d631c52c67fe590
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include <stdio.h> int main(int argc, const char * argv[]) { int n, i, all_w = 0, max_h = 0, max_h_index = 0, sec_max_h = 0; scanf("%d", &n); int w[n]; int h[n]; for(i = 0; i<n; i++){ scanf("%d", &w[i]); scanf("%d", &h[i]); } for(i = 0; i<n; i++){ if(max_h<h[i]){ max_h = h[i]; max_h_index = i; } all_w+=w[i]; } for(i = 0; i<n; i++){ if(sec_max_h<h[i] && i!= max_h_index){ sec_max_h = h[i]; } } if(sec_max_h == 0) sec_max_h = max_h; for(i = 0; i<n; i++){ if(i!=max_h_index){ printf("%d ", max_h*(all_w-w[i])); } else printf("%d ", sec_max_h*(all_w-w[i])); } return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
1fd04e3abc857e54fb6b8e5732cef7d4
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include<stdio.h> int main() { int n,i,j,x[200000],y[200000],w=0; int max1=0,max2=0; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d %d",&x[i],&y[i]); w+=x[i]; if(y[i] >= max2) { if(y[i] >= max1) { max2=max1; max1=y[i]; } else max2=y[i]; } } for(i=1;i<=n;i++) { if(y[i]==max1) printf("%d ",(w-x[i])*max2); else printf("%d ",(w-x[i])*max1); } printf("\n"); return 0; }
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for the j-th friend as he was the photographer.Print the minimum size of each made photo in pixels.
Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.
C
e1abc81cea4395ba675cf6ca93261ae8
6960c908f444761401a999338283a109
GNU C
standard output
256 megabytes
train_002.jsonl
[ "dp", "implementation", "*special", "data structures" ]
1425740400
["3\n1 10\n5 5\n10 1", "3\n2 1\n1 2\n2 1"]
null
PASSED
1,100
standard input
2 seconds
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends. Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
["75 110 60", "6 4 6"]
#include<stdio.h> #include<stdlib.h> int main() { int n,i,j; scanf("%d",&n); long long int w[n],h[n],totW=0,max[]={-1,-1},max_index[2],temp,tempW; for(i=0;i<n;i++){ scanf("%lld %lld",&w[i],&h[i]); totW+=w[i]; if(h[i]>max[0]){max[1]=max[0];max_index[1]=max_index[0];max[0]=h[i];max_index[0]=i;} else if(h[i]>max[1]){max[1]=h[i];max_index[1]=i;} } for(i=0;i<n;i++){ temp=1; temp*=(totW-w[i]); if(i!=max_index[0])temp*=max[0]; else temp*=max[1]; printf("%lld\n",temp); } return 0; }
Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads.The President of Berland decided to make changes to the road system and instructed the Ministry of Transport to make this reform. Now, each road should be unidirectional (only lead from one city to another).In order not to cause great resentment among residents, the reform needs to be conducted so that there can be as few separate cities as possible. A city is considered separate, if no road leads into it, while it is allowed to have roads leading from this city.Help the Ministry of Transport to find the minimum possible number of separate cities after the reform.
Print a single integer — the minimum number of separated cities after the reform.
C
1817fbdc61541c09fb8f48df31f5049a
2fb03dee20b32a1936bdc41f0a1d4af1
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "greedy", "graphs", "dsu", "data structures", "dfs and similar" ]
1459353900
["4 3\n2 1\n1 3\n4 3", "5 5\n2 1\n1 3\n2 3\n2 5\n4 3", "6 5\n1 2\n2 3\n4 5\n4 6\n5 6"]
NoteIn the first sample the following road orientation is allowed: , , .The second sample: , , , , .The third sample: , , , , .
PASSED
1,600
standard input
1 second
The first line of the input contains two positive integers, n and m — the number of the cities and the number of roads in Berland (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000). Next m lines contain the descriptions of the roads: the i-th road is determined by two distinct integers xi, yi (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the numbers of the cities connected by the i-th road. It is guaranteed that there is no more than one road between each pair of cities, but it is not guaranteed that from any city you can get to any other one, using only roads.
["1", "0", "1"]
#include <stdio.h> #include <stdlib.h> //并查集是一种树型的数据结构,用于处理一些不相交集合(Disjoint Sets) //的合并及查询问题.常常在使用中以森林来表示 int visit[100000]; int filiation[100000];//filiation意为父子关系,此数组用于存储两结点的上下级关系 int search_root_node(int random_node)//查找根结点;random_node任意结点 { int root_node;//root_node用于储存最后找到的根结点 int intermediary=random_node;//intermediary意为中介 //对于根结点root_node,有filiation[root_node]==root_node; //非根结点元素不满足此关系 while(filiation[intermediary]!=intermediary)//若当前元素的上级不是根结点 { intermediary=filiation[intermediary];//继续查看上级的上级是不是根结点 } //退出循环后intermediary即为根结点 root_node=intermediary; return root_node; } int merger(int random_node,int root_node)//merge意为合并,即路径压缩 {//将查找路径中所有属于根结点但上级不是根结点的结点的上级换成根结点 int j; while(random_node!=root_node) { j=filiation[random_node]; filiation[random_node]=root_node; random_node=j; } return 0; } int main() { int sum=0; int n,m,i,a,b;//n为结点总数,m为路径数量 int a_root,b_root; scanf("%d%d",&n,&m); for(i=1;i<=n;i++)//刚开始所有结点的上级都是自己 { filiation[i]=i; } for(i=1;i<=m;i++) { scanf("%d%d",&a,&b); //寻找根结点 a_root=search_root_node(a); b_root=search_root_node(b); //路径压缩 merger(a,a_root); merger(b,b_root); if(a_root!=b_root)//说明a,b两结点应属于同一个根结点但没有 { filiation[a_root]=b_root;//连接a_root与b_root if(visit[a]||visit[a_root]||visit[b]||visit[b_root]) { visit[a]=visit[a_root]=visit[b]=visit[b_root]=1; } } else { visit[a]=visit[a_root]=visit[b]=visit[b_root]=1; } } for(i=1;i<=n;i++) { if(!visit[i]&&filiation[i]==i)////!visit[i]说明城市i未被访问 {//filiation[i]==i&&!visit[i]说明城市i自成一派 sum++; } } printf("%d",sum); return 0; }
Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads.The President of Berland decided to make changes to the road system and instructed the Ministry of Transport to make this reform. Now, each road should be unidirectional (only lead from one city to another).In order not to cause great resentment among residents, the reform needs to be conducted so that there can be as few separate cities as possible. A city is considered separate, if no road leads into it, while it is allowed to have roads leading from this city.Help the Ministry of Transport to find the minimum possible number of separate cities after the reform.
Print a single integer — the minimum number of separated cities after the reform.
C
1817fbdc61541c09fb8f48df31f5049a
2c896b0c3b61851ecb46fb08f9c8f0fe
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "greedy", "graphs", "dsu", "data structures", "dfs and similar" ]
1459353900
["4 3\n2 1\n1 3\n4 3", "5 5\n2 1\n1 3\n2 3\n2 5\n4 3", "6 5\n1 2\n2 3\n4 5\n4 6\n5 6"]
NoteIn the first sample the following road orientation is allowed: , , .The second sample: , , , , .The third sample: , , , , .
PASSED
1,600
standard input
1 second
The first line of the input contains two positive integers, n and m — the number of the cities and the number of roads in Berland (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000). Next m lines contain the descriptions of the roads: the i-th road is determined by two distinct integers xi, yi (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi and yi are the numbers of the cities connected by the i-th road. It is guaranteed that there is no more than one road between each pair of cities, but it is not guaranteed that from any city you can get to any other one, using only roads.
["1", "0", "1"]
/* practice with Dukkha */ #include <stdio.h> #define N 100000 #define M 100000 int next[M * 2 + 1], jj[M * 2 + 1]; int link(int q, int j) { static int _ = 1; next[_] = q, jj[_] = j; return _++; } int ao[N]; char visited[N]; int dfs(int p, int i) { int l, j; if (visited[i]) return 1; visited[i] = 1; for (l = ao[i]; l; l = next[l]) if ((j = jj[l]) != p && dfs(i, j)) return 1; return 0; } int main() { int n, m, i, j, cnt; scanf("%d%d", &n, &m); while (m--) { scanf("%d%d", &i, &j), i--, j--; ao[i] = link(ao[i], j); ao[j] = link(ao[j], i); } cnt = 0; for (i = 0; i < n; i++) if (!visited[i] && !dfs(-1, i)) cnt++; printf("%d\n", cnt); return 0; }
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$.
Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$.
C
907f7db88fb16178d6be57bea12f90a2
f050cb217ac2128490f63d27da260e7b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1569762300
["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"]
NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$.
PASSED
1,400
standard input
1 second
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$.
["2", "0", "797922655"]
#include<stdio.h> #define mod 1000000007 int main() { int h,w; scanf("%d %d",&h,&w); int r[1005],a[1005][1005]={0}; for(int i=0;i<1005;i++) { for(int j=0;j<1005;j++) { a[i][j]=0; } } for(int i=0;i<h;i++) { scanf("%d",&r[i]); } int c[1005]; for(int i=0;i<w;i++) { scanf("%d",&c[i]); } int j,flag=0; for(int i=0;i<h;i++) { j=0; for( j=0;j<r[i];j++) { if(a[i][j]==0||a[i][j]==1) a[i][j]=1; else if(i<h&&j<w)a[i][j]=2; } if(a[i][j]==0||a[i][j]==-1) a[i][j]=-1; else if(i<h&&j<w) a[i][j]=2; } for(int i=0;i<w;i++) { j=0; for( j=0;j<c[i];j++) { if(a[j][i]==0||a[j][i]==1) a[j][i]=1; else if(j<h&&i<w)a[j][i]=2; } if(a[j][i]==0||a[j][i]==-1) a[j][i]=-1; else if(j<h&&i<w)a[j][i]=2; } int count=0; long long ans=1; for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { if(a[i][j]==0)count++; else if(a[i][j]==2) { printf("0\n"); return 0; } } } long long v=2; while(count>0) { if(count%2==1) { ans=ans%mod; ans=(ans*v)%mod; } count=count/2; v=v%mod; v=v*v%mod; v=v%mod; }if(flag==-1000)printf("0\n"); else printf("%Ld\n",ans); return 0; }
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$.
Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$.
C
907f7db88fb16178d6be57bea12f90a2
d53f5e6309854c9796204c78f91c3641
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1569762300
["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"]
NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$.
PASSED
1,400
standard input
1 second
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$.
["2", "0", "797922655"]
#include<stdio.h> #include<string.h> int iMap[1005][1005]; //assume 0 for empty 1 for nonempty 2 for both int iErr; const int MOD=1e9+7; long long mpow(long long b,int p){ long long res=1; while(p){ if(p&1) res=(res*(long long)b)%MOD; b=(b*b)%MOD; p>>=1; } return res; } int main(int argc,char **argv) { int n,m,v; scanf("%d %d",&n,&m); iErr=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) iMap[i][j]=2; for(int i=1;i<=n;i++){ scanf("%d",&v); v++; for(int j=1;j<v;j++) iMap[i][j]=1; iMap[i][v]=0;//v could be m+1 } for(int i=1;i<=m;i++){ scanf("%d",&v); v++; for(int j=1;j<v;j++) { if(iMap[j][i]==0) iErr=1; iMap[j][i]=1; } if(iMap[v][i]==1) iErr=1; iMap[v][i]=0; } if(iErr){ printf("0\n"); return 0; } int cnt=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(iMap[i][j]==2) cnt++; long long res=mpow((long long)2,cnt); printf("%d\n",(int)res); return 0; }
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$.
Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$.
C
907f7db88fb16178d6be57bea12f90a2
10639f6118292f774ec8e4f1e3b848a2
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1569762300
["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"]
NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$.
PASSED
1,400
standard input
1 second
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$.
["2", "0", "797922655"]
#include<stdio.h> int T[2000][2000]; int main() { int m, n, t, l, i, j; scanf("%d %d", &m, &n); for(i = 1; i <= m; i++) for(j = 1; j <= n; j++) T[i][j] = 2; for(i = 1; i <=m; i++) { scanf("%d", &t); for(j = 1; j <= t; j++) T[i][j] = 1; T[i][t + 1] = 0; } for(i = 1; i <= n; i++) { scanf("%d", &t); for(j = 1; j <= t; j++) { l = 1; if(T[j][i] != 2 && T[j][i] != l) { printf("0\n"); return 0; } T[j][i] = l; } if(T[t + 1][i] == 2) T[t + 1][i] = 0; else if(T[t + 1][i] == 1) { printf("0\n"); return 0; } } int count = 0; long long ans = 1; for(i = 1; i <= m; i++) for(j = 1; j <= n; j++) if(T[i][j] == 2) { ans *= 2; ans %= 1000000007; } printf("%lld\n", ans); return 0; }