Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Romania ACM Programming Contest – Bucharest & Iasi Subregions May 15, 2010 A - Odd-Even Sum Given a natural number N, compute the value S(N)=1-2+3-4+5-6+...N (i.e. the sum of all the odd numbers less than or equal to N minus the sum of all the even numbers less than or equal to N). Input Data The first line contains the number T of test cases. Each of the next T lines contains a natural number N (0≤N≤2.000.000.000). Output Data You should print T lines. The ith line of output should contain the value S(N), where N is the number from the ith test case (i.e. the number on the (i+1)st line of the input). Example Standard Input 4 0 10 11 12 Standard Output 0 -5 6 -6 B - Domino Cover Consider a rectangular board composed of HxN squares (1≤H≤7 ; 1≤N≤1.000.000.000). We want to fully cover the board by placing non-overlapping dominoes. A domino is a 2x1 or a 1x2 rectangular piece (i.e. it covers two squares having a common side). Compute the total number of possibilities in which we can cover the entire board with non-overlapping dominoes. Input Data The input data consists of 7 sets of test cases, one for each possible value of H. Each set of test cases contains the number T of test cases on the first line. Each of the next T lines contains a value of N (a test case is thus described by the value H corresponding to the set of test cases and by the value N on the corresponding line). The sets of test cases are given in increasing order of H and are separated by a blank line. Output Data For each test case print the total number of possibilities to cover the board, modulo 30047. Example Standard Input Standard Output Explanation 2 1 2 0 1 3 5 0 The values printed to the standard output correspond to the following test cases (in order): H=1, N=1 H=1, N=2 H=2, N=3 2 Romania ACM Programming Contest – Bucharest & Iasi Subregions May 15, 2010 3 4 2 5 6 2 7 8 41 781 2245 0 5639 28993 5567 0 23808 H=2, H=3, H=3, H=4, H=4, H=5, H=5, H=6, H=6, H=7, H=7, N=4 N=5 N=6 N=7 N=8 N=9 N=10 N=11 N=12 N=13 N=14 2 9 10 2 11 12 2 13 14 C - Valleys & Mountains Let’s consider a permutation h(1), ..., h(N) of the numbers 1, ..., N, where each position i (1≤i≤N) also has an associated value v(i). A valley is a contiguous subsequence h(i), h(i+1), ..., h(j), such that: 1. j-i+1≥3 2. the subsequence is decreasing from h(i) to some number h(p), and then increasing from h(p) up to h(j) 3. i+1≤p≤j-1 (i.e. p must not be the first or the last position of the sequence). A mountain is a contiguous subsequence h(i), h(i+1), ..., h(j), such that: 4. j-i+1≥3 5. the subsequence is increasing from h(i) to some number h(p), and then decreasing from h(p) to h(j) 6. i+1≤p≤j-1 (i.e. p must not be the first or the last position of the sequence). The value of a contiguous subsequence h(i), h(i+1), …, h(j) is equal to the sum of the values of the positions contained in the subsequence (i.e. it is equal to v(i)+v(i+1)+…+v(j)). Find the maximum value of a valley and the maximum value of a mountain. Input Data The first line of input contains the number T of test cases which are described next. The first line of each test case contains the number N (3≤N≤50.000). The ith line of the next N lines contains two integer values separated by one blank: h(i) and v(i) (-20.000≤ v(i)≤+20.000). Romania ACM Programming Contest – Bucharest & Iasi Subregions May 15, 2010 Output Data For each test case you should print one line containing two numbers MV and MM, separated by one blank: the maximum value of a valley and the maximum value of a mountain for the corresponding test case. If no valley exists, you should print the string „no valley” (without quotes) instead of the number MV. If no mountain exists, you should print the string „no mountain” (without quotes) instead of the number MM. Example Standard Input Standard Output 2 10 1 -1 3 -2 5 3 7 -4 6 5 4 6 2 -7 8 10 9 -9 10 10 4 4 10 3 -1 1 -10 2 -9 15 10 -10 no mountain D - Minimum Enclosing Diamond A diamond is a square rotated by 45 degrees (i.e. its two diagonals are parallel to the coordinate axes). The size of a diamond is the length of its diagonals. Given a set of N points in the plane, find the minimum size of a diamond containing all the points inside of it or on its borders. Input Data The first line of input contains the number T of test cases which are described next. The first line of a test case contains the number N (1≤N≤50.000) of points. The next N lines contain two integer numbers each, separated by a blank: the x and y coordinates of a point. Output Data For each test case print a line containing the size of the minimum enclosing diamond. Some careful analysis will reveal that this number is an integer. Example Standard Input Standard Output 2 3 1 2 3 6 0 4 6 19 Romania ACM Programming Contest – Bucharest & Iasi Subregions May 15, 2010 4 -1 3 -2 -5 -10 6 4 4 E - Dual-Processor Scheduling There are N jobs (numbered from 1 to N) which have to be executed on a dual-processor machine with non-identical processors. Each job i must be executed t1[i] contiguous seconds on processor 1 and t2[i] contiguous seconds on processor 2. At each time moment, at most one job can be executed on the same processor. Moreover, the two time intervals when a job i is executed on processor 1 and on processor 2 must not overlap (but it is allowed to start the execution on the other processor as soon as the execution on one of the processors ends). There are no ordering constraints regarding the execution of each job on the two processors (i.e. each job i may be executed first on any of the two processors and later on the other one) or regarding the execution of the jobs on the same processor. This also implies that the jobs may be executed in different orders on the two processors. Considering that the execution of the jobs starts at the time moment 0, find a schedule of the N jobs on the two processors, such that the earliest time moment TE (expressed in seconds) when the execution of all the jobs on both processors ends is minimum. Input Data The first line of input contains the number T of test cases which are described next. The first line of a test case contains the number N (1≤N≤100.000) of jobs. The ith line of the next N lines contain two integer numbers each, separated by a blank: the values t1[i] and t2[i], in this order (1≤t1[i],t2[i]≤20.000). Output Data For each test case print a line containing the minimum value of TE. Example Standard Input Standard Output 2 3 3 4 6 4 1 2 4 7 13 15 5 1 6 8 4 2 1 F - Multiversion Stack We consider a stack which can have multiple versions. The only initial version is numbered with 0 and is an empty stack. We will perform a sequence of PUSH and POP operations on this stack. Romania ACM Programming Contest – Bucharest & Iasi Subregions May 15, 2010 A PUSH operation has the form PUSH(v) and performs the following actions: 1. let C be the index of the operation in the sequence of operations (C is indexed starting from 1; both types of operations are indexed) 2. a new version vnew is created, which contains all the elements of the version v; vnew is the smallest natural number which does not exist as a version 3. the element C+v is added at the top of the version vnew 4. print at the standard output a line containing the number of elements in the stack version vnew A POP operation has the form POP(v) and performs the following actions: 1. a new version vnew is created, which contains all the elements of the version v; vnew is the smallest natural number which does not exist as a version 2. the topmost element of the stack version vnew is removed from the version vnew and printed to the standard output on a single line ; if the version vnew does not contain any element, then -1 is printed to the standard output on a single line Input Data The first line of input contains the number NOP of operations in the sequence of operations. Each of the next NOP lines describes one operation. An operation is described by two integer numbers, separated by a blank: op and v (v≥0). If op=1 then the operation to be performed is PUSH(v). If op=2 then the operation to be performed is POP(v). The parameter v will always denote an existing version. This problem contains only one test case. Output Data Print the output of the sequence of operations. Example Standard Input Standard Output Explanation 9 1 1 1 1 2 2 2 2 1 1 2 3 1 5 3 1 -1 3 The sequence of operations is: Push(0), Push(1), Push(2), Push(0), Pop(3), Pop(2), Pop(1), Pop(7). The stacks corresponding to each version are the following (left-to-right corresponds to the bottom-to-top order): version 0: empty version 1: 1 version 2: 1, 3 version 3: 1, 3, 5 version 4: 4 version 5: 1, 3 version 6: 1 version 7: empty version 8: empty version 9: 1, 3, 11 0 1 2 0 3 2 1 7 2 Romania ACM Programming Contest – Bucharest & Iasi Subregions May 15, 2010 G - Valleys & Mountains 2 Romania is well-known for its beautiful and unique landscape. In particular, it is known that Romania has V valleys and M mountains. During a trip to Romania, George took a photo of Romania’s landscape. The photo is represented as a sequence of the characters / and \ . There are 2*N characters in the sequence, N characters of type / and N characters of type \. A valley is represented by two consecutive characters \/ (\ followed by /). A mountain is represented by two consecutive characters /\ (/ followed by \). The map starts and ends at the sea level (altitude 0) and: 1) for every / character the altitude increases by 1 2) for every \ character the altitude decreases by 1 3) the altitude never decreases below 0 In order to decide if Romania’s landscape is indeed unique, George would like to count the total number of possible photos containing N characters of type /, N characters of type \, having V valleys and M mountains and which obey all the specified altitude constraints. Input Data This problem has no input. Output Data Let C(N,V,M) be the number of sequences with N characters of type /, N characters of type \, V valleys and M mountains and which obey all the specified altitude constraints. Print all the non-zero values C(N,V,M) of all the tuples (N,V,M) in increasing lexicographic order of the tuples, for all the values of N from 1 to 30. Example Standard Input Standard Output Explanation 1 1 1 1 3 1 1 6 6 1 1 10 20 10 1 ... The values printed to the standard output correspond, in order, to the following tuples: (1,0,1) (2,0,1) (2,1,2) (3,0,1) (3,1,2) (3,2,3) (4,0,1) (4,1,2) (4,2,3) (4,3,4) (5,0,1) (5,1,2) (5,2,3) (5,3,4) (5,4,5) ... The 3 sequences for the tuple (3,1,2) are: 1) //\\/\ 2) /\//\\ 3) //\/\\ Romania ACM Programming Contest – Bucharest & Iasi Subregions May 15, 2010 H - Minimum Steiner Tree Let’s consider an undirected complete graph with N nodes numbered from 1 to N. We denote by C[i][j] the cost of the edge (i,j) (we have C[i][j]=C[j][i]≥1 and C[i][i]=0). Some of the nodes of the graph are marked as being special. We want to select a subset S of graph edges such that there is a path from every special node to every other special node using the edges from S. The cost of the subset S is the sum of the costs of the edges contained in it. We are interested in finding the minimum cost of such a subset S. Input Data The first line of input contains the number T of test cases which are described next. The first line of a test case contains two integer numbers, separated by a blank: N (1≤N≤19) and Q (1≤Q≤100.000). The next N lines contain N numbers each, separated by blanks: the jth number on the ith of these lines represents the value C[i][j] (1≤C[i][j]≤100.000.000). Each of the next Q lines contains a query sequence SQ of N characters (plus the terminating newline character). The ith character in SQ is 1 if the node i is marked as being special, and 0 otherwise. Output Data For each query sequence SQ from the input print a line containing the minimum cost of a subset of edges S such that there is a path from every node marked as special in SQ to every other special node using only the edges from S. When computing the answer for a query sequence you must consider its corresponding graph. Moreover, the other query sequences from the same test case do not have any influence on which node is marked as special or not (only the current query sequence SQ specifies this). Example Standard Input Standard Output 1 6 15 0 5 100000000 5 5 8 5 0 9 7 7 8 100000000 9 0 5 5 100000000 5 7 5 0 5 5 5 7 5 5 0 5 8 8 100000000 5 5 0 001110 010000 100000 100000 010010 100100 000100 101111 001010 010010 111011 010101 001001 001111 011001 10 0 0 0 7 5 0 20 5 7 20 12 10 15 17 Romania ACM Programming Contest – Bucharest & Iasi Subregions May 15, 2010 I - Minimum Sum of Averages Division Consider a sequence of N positive natural numbers: v1, ..., vN. We want to divide this sequence into K contiguous subsequences such that: 1. the K subsequences are non-overlapping 2. each position i (1≤i≤N) of the sequence belongs to a subsequence 3. the total cost of the subsequences is minimum The cost of a contiguous subsequence vi, ..., vj is equal to: (vi+vi+1+...+vj-1+vj) div (j-i+1). where (vi+vi+1+...+vj-1+vj) denotes the sum of all the numbers in the subsequence. We denote by A div B the quotient of the division of A at B (i.e. the integer division of A at B). For instance, 19 div 3=6 and 20 div 4=5. Input Data The first line of input contains the number T of test cases which are described next. The first line of a test case contains two integer numbers, separated by a blank: N (1≤N≤300) and K (1≤K≤N). The second line of each test case contains the values v1, ..., vN, separated by blanks. We have 1≤vi≤30.000 (1≤i≤N). Output Data For each test case print a line containing the minimum total cost of dividing the sequence into the given number of contiguous subsequences. Example Standard Input Standard Output Explanation 2 4 2 10 20 30 40 6 2 10 100 1000 100 10 1 40 245 In the first test case, the two subsequences are: 10 => cost =10/1=10 20 30 40 => cost =(20+30+40)/3=30 The total cost is 10+30=40. In the 2nd test case, the two subsequences are: 10 100 1000 100 10 => cost=1220/5=244 1 => cost=1/1=1 The total cost is 244+1=245.