task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
Matrix Vector Multiplication Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$. A column vector with m elements is represented by the following equation. \[ b = \left( \begin{array}{c} b_1 \\ b_2 \\ : \\ b_m \\ \end{array} \right) \] A $n \times m$ matrix with $m$ column vectors, each of which consists of $n$ elements, is represented by the following equation. \[ A = \left( \begin{array}{cccc} a_{11} & a_{12} & ... & a_{1m} \\ a_{21} & a_{22} & ... & a_{2m} \\ : & : & : & : \\ a_{n1} & a_{n2} & ... & a_{nm} \\ \end{array} \right) \] $i$-th element of a $m \times 1$ column vector $b$ is represented by $b_i$ ($i = 1, 2, ..., m$), and the element in $i$-th row and $j$-th column of a matrix $A$ is represented by $a_{ij}$ ($i = 1, 2, ..., n,$ $j = 1, 2, ..., m$). The product of a $n \times m$ matrix $A$ and a $m \times 1$ column vector $b$ is a $n \times 1$ column vector $c$, and $c_i$ is obtained by the following formula: \[ c_i = \sum_{j=1}^m a_{ij}b_j = a_{i1}b_1 + a_{i2}b_2 + ... + a_{im}b_m \] Input In the first line, two integers $n$ and $m$ are given. In the following $n$ lines, $a_{ij}$ are given separated by a single space character. In the next $m$ lines, $b_i$ is given in a line. Output The output consists of $n$ lines. Print $c_i$ in a line. Constraints $1 \leq n, m \leq 100$ $0 \leq b_i, a_{ij} \leq 1000$ Sample Input 3 4 1 2 0 1 0 3 0 1 4 1 1 0 1 2 3 0 Sample Output 5 6 9 | 35,500 |
Binary Tree Intersection And Union Given two binary trees, we consider the âintersectionâ and âunionâ of them. Here, we distinguish the left and right child of a node when it has only one child. The definitions of them are very simple. First of all, draw a complete binary tree (a tree whose nodes have either 0 or 2 children and leaves have the same depth) with sufficiently large depth. Then, starting from its root, write on it a number, say, 1 for each position of first tree, and draw different number, say, 2 for second tree. The âintersectionâ of two trees is a tree with nodes numbered both 1 and 2, and the âunionâ is a tree with nodes numbered either 1 or 2, or both. For example, the intersection of trees in Figures 1 and 2 is a tree in Figure 3, and the union of them is a tree in Figure 4. A node of a tree is expressed by a sequence of characters, â(,)â. If a node has a left child, the expression of the child is inserted between â(â and â,â. The expression of a right child is inserted between â,â and â)â. For exam- ple, the expression of trees in Figures 1 and 2 are â((,),(,))â and â((,(,)),)â, respectively. Input Each line of the input contains an operation. An operation starts with a character which specifies the type of operation, either âiâ or âuâ: âiâ means intersection, and âuâ means union. Following the character and a space, two tree expressions are given, separated by a space. It is assumed that 1 <= #nodes in a tree <= 100, and no tree expression contains spaces and syntax errors. Input is terminated by EOF. Output For each line of the input, output a tree expression, without any space, for the result of the operation. Sample Input i ((,),(,)) ((,(,)),) u ((,),(,)) ((,(,)),) Output for the Sample Input ((,),) ((,(,)),(,)) | 35,501 |
D: å ŽæåœãŠã²ãŒã åé¡ AORã€ã«ã¡ãã ãš ãããã ãã°ã©ãã䜿ã£ãå ŽæåœãŠã²ãŒã ãè¡ãïŒ æåã«ïŒAORã€ã«ã¡ãã ãæŽæ° $N$ ãæå®ãïŒãããã ã¯é ç¹æ° $N$ ã®ç¡åã°ã©ããçæããïŒ $N$ åã®é ç¹ã«ã¯ïŒ $1$ ~ $N$ ãŸã§ã®çªå·ãå²ãæ¯ãããŠããïŒãã®ç¡åã°ã©ãã䜿ã£ãŠïŒ$K$ åã²ãŒã ãè¡ãïŒ åã²ãŒã ã®ã¯ããã« AORã€ã«ã¡ãã ã¯é ç¹ã $1$ ã€éžã³ïŒãããã ããã®é ç¹ãåœãŠãïŒ ãããã 㯠AORã€ã«ã¡ãã ã«æå€§ $10$ åãŸã§è³ªåããããšãã§ããïŒ ãããã ãé ç¹çªå·ã $1$ 〠AORã€ã«ã¡ãã ã«äŒãããšïŒçªå·ã«åŸã AORã€ã«ã¡ãã ã¯ä»¥äžã®ãã¡ã©ãããçããïŒ AORã€ã«ã¡ãã ã®è¿äº æå³ Yes ãã®é ç¹ãåœãã Near Yesã§ã¯ãªãïŒãã®é ç¹ã«é£æ¥ããé ç¹ãåœãã No ããä»¥å€ $K$ åã®ã²ãŒã å
šãŠã§ $10$ å以å
ã«é ç¹ãåœãŠãããšãã§ããã°ïŒãããã ã®åã¡ã§ããïŒ ã©ãããŠãåã¡ãã ãããã ã¯ïŒããªãã«çµ¶å¯Ÿã«åãŠãããã°ã©ã ã®äœæããé¡ãããŠããïŒ å
¥åºå ãŸãïŒä»¥äžã®åœ¢åŒã§é ç¹æ° $N$ ãšã²ãŒã åæ° $K$ ãäžããããïŒ $N\ K$ 次ã«ïŒçæããç¡åã°ã©ãã以äžã®åœ¢åŒã§åºåããïŒ $M$ $a_{1} b_{1}$ $\vdots$ $a_{M} b_{M}$ ããã§ã $M$ ã¯çæããç¡åã°ã©ãã®èŸºã®æ¬æ°ã§ãã, $a_i$, $b_i$ ã¯ã°ã©ãã® $i$ æ¬ç®ã®èŸºãé ç¹ $a_i$ ãšé ç¹ $b_i$ ãç¹ãã§ããããšã瀺ã. ãªã, çæããç¡åã°ã©ã㯠$ 0 \leq M \leq \frac{N(N-1)}{2}$ ã〠$1 \leq a_i, b_i \leq N$ ãæºãããªããã°ãªããªã. ç¶ããŠïŒããªãã®ããã°ã©ã ã¯äœåãå¿çããã°ã©ã ã«è³ªåãããïŒè³ªåã®ãã©ãŒãããã¯ä»¥äžã®ãšããã§ããïŒ Num $Num$ 㯠$1$ ä»¥äž $N$ 以äžã®é ç¹çªå·ã§ããïŒ ãã®è³ªåã§ïŒ'Yes'ïŒ'Near'ïŒ'No'ã®ãã¡ïŒã©ãããæšæºå
¥åã« $1$ è¡ã§æž¡ãããïŒ 'Yes'ãæž¡ãããã°åå©ãšãªãïŒ$1$ åã®ã²ãŒã ãçµäºããïŒ $1$ åã®ã²ãŒã ãçµäºãããïŒããã«æ¬¡ã®ã²ãŒã ãå§ãŸãããšã«æ³šæããïŒ åã²ãŒã æå€§ $10$ å以å
ã®è³ªåã§åå©ããªããã°ãããªãïŒ ãã®ã²ãŒã ã $K$ åè¡ãïŒãã¹ãŠã®ã²ãŒã ã§åå©ããã°æ£çãšãªãïŒ ã²ãŒã ãçµäºããåŸïŒããªãã®ããã°ã©ã ã¯çŽã¡ã«çµäºããªããã°ãªããªãïŒçµäºããªãã£ãå Žåã®ãžã£ããžçµæã¯äžå®ã§ããïŒ ãŸãïŒããã以å€ã®ãã©ãŒãããã§åºåããå Žåã®ãžã£ããžçµæãäžå®ã§ããïŒ ãªãïŒã°ã©ãã®æ
å ±ã質åãå¿çããã°ã©ã ã«éã£ãããšãã©ãã·ã¥ããªããšTLEãšãªãããšãããïŒ ãã©ãã·ã¥ã¯Cã§ã¯ fflush(stdout); C++ã§ã¯ std::cout << endl; ã§è¡ãããšãã§ããïŒ fflush() 㯠stdio.h ãã€ã³ã¯ã«ãŒããããšäœ¿çšã§ããïŒ å¶çŽ $1 \leq N, K \leq 200$ å
¥åºåäŸ ããã°ã©ã ãžã®å
¥å ããã°ã©ã ã®åºå 3 2 2 1 2 2 3 1 No 3 Yes 2 Near 3 No 1 Yes | 35,502 |
Score : 600 points Problem Statement Takahashi has N balls with positive integers written on them. The integer written on the i -th ball is A_i . He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2 . Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed. Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t . Constraints 1 \leq N \leq 2\times 10^5 1 \leq A_i \leq 10^9 A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2 . Sample Input 1 3 1 2 3 Sample Output 1 1 We can form one pair whose sum of the written numbers is 4 by pairing the first and third balls. Note that we cannot pair the second ball with itself. Sample Input 2 5 3 11 14 5 13 Sample Output 2 2 | 35,503 |
åé¡ I å±± å顿 L æ°ã¯ããéœåžã®åžé·ã§ããïŒL æ°ã®åžé·ãšããŠã®æè
ã¯ãããŸããæãæ¢ãäžç¬ã«ããŠéœåžäžã«ééç¶²ãåŒãããïŒè²¡æ¿ã®èµ€åãäžå€ã«ããŠè«å€§ãªé»åã«ãããïŒã¯ãŠã¯å·šå€§ãªæªç£ãã©ããããšããªãåŒãã§ããã©ãŒãã³ã¹ã«äœ¿ãããšãããïŒ ãã㪠L æ°ã¯åå°ã®é£ãåã£ãè¡ãŸãã¯åå士ãäœåºŠãå
¥ãæ¿ããããšã§ã§ããŒããªåå°ã山圢ã«ãããšããéã³ãæè¿çºæããïŒåå°ã¯ HÃW åã®ãããã¯ã«åºåãããŠããïŒããã㯠(y,x) ã§ã¯æµ·é¢ããã®é«ãã h y,x ã§ãããšæž¬å®ãããŠããïŒå
¥ãæ¿ãåŸã®ããã㯠(y,x) ã®é«ãã h' y,x ãšæžãããšã«ããïŒãã®åå°ã山圢ã§ãããšã¯ïŒä»¥äžã®å³ã®ããã«ïŒããããã㯠(y^*,x^*) ããã£ãŠïŒãããå±±é ãšããŠå±±é ããé¢ããã«åŸã£ãŠé«ããå調æžå°ããŠãããã®ãããïŒ h' y^*-1, x^*-2 < h' y^*-1, x^*-1 < h' y^*-1, x^* > h' y^*-1, x^*+1 > h' y^*-1, x^*+2 â§ â§ â§ â§ â§ h' y^*, x^*-2 < h' y^*, x^*-1 < h' y^*, x^* > h' y^*, x^*+1 > h' y^*, x^*+2 âš âš âš âš âš h' y^*+1, x^*-2 < h' y^*+1, x^*-1 < h' y^*+1, x^* > h' y^*+1, x^*+1 > h' y^*+1, x^*+2 ãšããã§ïŒL æ°ã¯ãããããã°ã£ãŠã山圢ã«ã§ããªããããªåå°ãååšããæ°ãããïŒããã§ïŒåãã£ãŠã³ã³ãã¥ãŒã¿ã«ãã®åå°ã山圢ã«ã§ãããã©ããããã§ãã¯ãããããšã«ããïŒ å
¥ååœ¢åŒ æåã®è¡ã« H ãš W ãã¹ããŒã¹åºåãã§äžããããïŒ æ¬¡ã® H è¡ã«åå°ã®é«ããäžããããïŒ åè¡ã¯ W åã®æ°å€ãããªãïŒãããã察å¿ããå Žæã®é«ãã衚ãïŒ åºååœ¢åŒ åå°ã山圢ã«ã§ãããªã "YES" ïŒã§ããªããªã "NO" ãåºåããïŒ å¶çŽ 1 †H,W †1,000 0 †h y,x †10 8 å
šãŠã® h y,x ã¯çžç°ãªãïŒ å
¥åºåäŸ å
¥åäŸ 1 3 3 1 3 2 7 9 8 4 6 5 åºåäŸ 1 YES å
¥åäŸ 2 以äžã®äŸã§ã¯ 2 çªç®ã®åãš 3 çªç®ã®åãå
¥ãæ¿ããããšã«ããåå°ã山圢ã«ããããšãã§ããïŒ 3 3 9 3 6 8 2 5 7 1 4 åºåäŸ 2 YES å
¥åäŸ 3 1 1 100 åºåäŸ 3 YES å
¥åäŸ 4 3 3 1 3 2 4 6 5 7 8 9 åºåäŸ 4 NO è¬èŸ ãã®åé¡ã¯äº¬éœåžã®åšãã«å±±ãå€ãããšããäœãããïŒãã£ãŠäº¬éœåžã®åšãã®å±±ã«æè¬ã®æã衚ããïŒ | 35,504 |
Score : 300 points Problem Statement There is a box containing N balls. The i -th ball has the integer A_i written on it. Snuke can perform the following operation any number of times: Take out two balls from the box. Then, return them to the box along with a new ball, on which the absolute difference of the integers written on the two balls is written. Determine whether it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written. Constraints 1 \leq N \leq 10^5 1 \leq A_i \leq 10^9 1 \leq K \leq 10^9 All input values are integers. Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N Output If it is possible for Snuke to reach the state where the box contains a ball on which the integer K is written, print POSSIBLE ; if it is not possible, print IMPOSSIBLE . Sample Input 1 3 7 9 3 4 Sample Output 1 POSSIBLE First, take out the two balls 9 and 4 , and return them back along with a new ball, abs(9-4)=5 . Next, take out 3 and 5 , and return them back along with abs(3-5)=2 . Finally, take out 9 and 2 , and return them back along with abs(9-2)=7 . Now we have 7 in the box, and the answer is therefore POSSIBLE . Sample Input 2 3 5 6 9 3 Sample Output 2 IMPOSSIBLE No matter what we do, it is not possible to have 5 in the box. The answer is therefore IMPOSSIBLE . Sample Input 3 4 11 11 3 7 15 Sample Output 3 POSSIBLE The box already contains 11 before we do anything. The answer is therefore POSSIBLE . Sample Input 4 5 12 10 2 8 6 4 Sample Output 4 IMPOSSIBLE | 35,505 |
Score : 1300 points Problem Statement Takahashi has a string S of length N consisting of lowercase English letters. On this string, he will perform the following operation K times: Let T be the string obtained by reversing S , and U be the string obtained by concatenating S and T in this order. Let S' be some contiguous substring of U with length N , and replace S with S' . Among the strings that can be the string S after the K operations, find the lexicographically smallest possible one. Constraints 1 \leq N \leq 5000 1 \leq K \leq 10^9 |S|=N S consists of lowercase English letters. Input Input is given from Standard Input in the following format: N K S Output Print the lexicographically smallest possible string that can be the string S after the K operations. Sample Input 1 5 1 bacba Sample Output 1 aabca When S= bacba , T= abcab , U= bacbaabcab , and the optimal choice of S' is S'= aabca . Sample Input 2 10 2 bbaabbbaab Sample Output 2 aaaabbaabb | 35,506 |
Score : 1000 points Problem Statement There is a simple undirected graph with N vertices and M edges. The vertices are numbered 1 through N , and the edges are numbered 1 through M . Edge i connects Vertex U_i and V_i . Also, Vertex i has two predetermined integers A_i and B_i . You will play the following game on this graph. First, choose one vertex and stand on it, with W yen (the currency of Japan) in your pocket. Here, A_s \leq W must hold, where s is the vertex you choose. Then, perform the following two kinds of operations any number of times in any order: Choose one vertex v that is directly connected by an edge to the vertex you are standing on, and move to vertex v . Here, you need to have at least A_v yen in your pocket when you perform this move. Donate B_v yen to the vertex v you are standing on. Here, the amount of money in your pocket must not become less than 0 yen. You win the game when you donate once to every vertex. Find the smallest initial amount of money W that enables you to win the game. Constraints 1 \leq N \leq 10^5 N-1 \leq M \leq 10^5 1 \leq A_i,B_i \leq 10^9 1 \leq U_i < V_i \leq N The given graph is connected and simple (there is at most one edge between any pair of vertices). Input Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 : A_N B_N U_1 V_1 U_2 V_2 : U_M V_M Output Print the smallest initial amount of money W that enables you to win the game. Sample Input 1 4 5 3 1 1 2 4 1 6 2 1 2 2 3 2 4 1 4 3 4 Sample Output 1 6 If you have 6 yen initially, you can win the game as follows: Stand on Vertex 4 . This is possible since you have not less than 6 yen. Donate 2 yen to Vertex 4 . Now you have 4 yen. Move to Vertex 3 . This is possible since you have not less than 4 yen. Donate 1 yen to Vertex 3 . Now you have 3 yen. Move to Vertex 2 . This is possible since you have not less than 1 yen. Move to Vertex 1 . This is possible since you have not less than 3 yen. Donate 1 yen to Vertex 1 . Now you have 2 yen. Move to Vertex 2 . This is possible since you have not less than 1 yen. Donate 2 yen to Vertex 2 . Now you have 0 yen. If you have less than 6 yen initially, you cannot win the game. Thus, the answer is 6 . Sample Input 2 5 8 6 4 15 13 15 19 15 1 20 7 1 3 1 4 1 5 2 3 2 4 2 5 3 5 4 5 Sample Output 2 44 Sample Input 3 9 10 131 2 98 79 242 32 231 38 382 82 224 22 140 88 209 70 164 64 6 8 1 6 1 4 1 3 4 7 4 9 3 7 3 9 5 9 2 5 Sample Output 3 582 | 35,507 |
åé¡ D : 忢åé¡ Gââgle Code Jam 㯠Gââgle 瀟ã幎㫠1 床éå¬ããã³ã³ãã¹ãã§ããïŒ åªåè
㯠Gââgle ãžã®å
¥ç€Ÿãèš±ãããïŒäžçæé«å³°ã®ã³ã³ãã¹ãã ïŒ ãããå¿è«ïŒãã以å€ã®åå è
ã¯åž°ãã¬è
ãšãªãïŒ Gââgle Code Jam ã§ã¯èªåã®å¥œããªããã°ã©ãã³ã°èšèªãåŠçç³»ã䜿ãããšãã§ããïŒ å㯠Defunge ãšããèªããéçºããããã°ã©ãã³ã°èšèªã§åå ããããšã«ããïŒ ãã®èšèªã䜿ãã°ïŒèšç®å°é£ãªåé¡ã¯ãããïŒå€å®äžèœãªåé¡ã§ãã解決ã§ããæ°ãããŠããïŒ åé¡ äžããããããã°ã©ã ã忢ããããå€å®ããããã°ã©ã ãäœæããïŒ äžããããããã°ã©ã ã¯ïŒä»¥äžã§èª¬æããããã°ã©ãã³ã°èšèª Defunge ã§èšè¿°ãããŠããïŒ Defunge ã®ããã°ã©ã ã®åœä»€ã¯ 1 æåã§ããïŒ1 次å
ã®åã§ã¯ãªã 2 次å
ã®æ Œåç¶ã«äžŠãã§ããïŒ äžå³ã¯ïŒDefunge ã®ããã°ã©ã ã®äŸã§ãã: 6>--v. .^--_@ Defunge ã®èšèªä»æ§ã¯ä»¥äžã®ããã«ãªã£ãŠããïŒ Defunge ã®ããã°ã©ã ã¯ãå·Šäžã®ãã¹ããå³åãã§éå§ããïŒ ïŒå·Šäžã®ãã¹ã®åœä»€ãæåã«å®è¡ãããïŒïŒ åœä»€ã«ãã£ãŠé²ãåããäžäžå·Šå³ã«å€æŽãããããšãããïŒ ç«¯ã«éãããå察åŽã®ç«¯ãžãžã£ã³ãããïŒ ã¡ã¢ãªã¯ 0 ãã 15 ãŸã§ã® 1 ã€ã®æŽæ°ãèšæ¶ããããšãã§ããïŒ ã¡ã¢ãªã«ã¯ã¯ãã 0 ãèšæ¶ãããŠããïŒ Defunge ã®åœä»€ã¯ä»¥äžã®éãã§ããïŒ '<' ⊠å®è¡ã®åããå·Šã«ããïŒ '>' ⊠å®è¡ã®åããå³ã«ããïŒ '^' ⊠å®è¡ã®åããäžã«ããïŒ 'v' ⊠å®è¡ã®åããäžã«ããïŒ '_' ⊠ã¡ã¢ãªã®å€ã 0 ãªãã°å®è¡ã®åããå³ã«ïŒããã§ãªããã°å·Šã«ããïŒ '|' ⊠ã¡ã¢ãªã®å€ã 0 ãªãã°å®è¡ã®åããäžã«ïŒããã§ãªããã°äžã«ããïŒ '?' ⊠å®è¡ã®åããäžäžå·Šå³ã®ããããã«ã©ã³ãã ã«ç確çã§å€æŽãããïŒ '.' ⊠äœãããªãïŒ '@' ⊠ããã°ã©ã ã®å®è¡ã忢ããïŒ '0' - '9' ⊠ã¡ã¢ãªã®å€ãæå®ã®æ°å€ã«ããïŒ '+' ⊠ã¡ã¢ãªã®å€ã« 1 ãå ããïŒãã ãå€ã 15 ã ã£ãå Žå 0 ã«ããïŒ '-' ⊠ã¡ã¢ãªã®å€ãã 1 ãåŒãïŒãã ãå€ã 0 ã ã£ãå Žå 15 ã«ããïŒ å
¥å å
¥åã®æåã®è¡ã¯ 2 ã€ã®æŽæ° R, C ãå«ãïŒ ç¶ã R è¡ã¯ããã°ã©ã ã衚ãããããã C æåã®æååãå«ãã åºå ããã°ã©ã ã忢ããå¯èœæ§ãããå Žå㯠YES ãšåºåããïŒ ããã§ãªããšãïŒNO ãšåºåããïŒ å¶çŽ 1 †R †20 1 †C †20 å
¥åºåäŸ å
¥åºåäŸ 1 å
¥åäŸ 1: 2 6 6>--v. .^--_@ å
¥åäŸ 1 ã«å¯Ÿããåºå: YES å
¥åºåäŸ 2 å
¥åäŸ 2: 2 6 5>--v. .^--_@ å
¥åäŸ 2 ã«å¯Ÿããåºå: NO å
¥åºåäŸ 3 å
¥åäŸ 3: 2 6 .>--v. .^--?@ å
¥åäŸ 3 ã«å¯Ÿããåºå: YES è£è¶³ Defunge 㯠Befunge ãšé¡äŒŒããŠããïŒ Befunge ã®ç解㯠Defunge ã®çè§£ãå©ãããããããªããïŒ ç°ãªãç¹ãå€ãããïŒæ³šæããïŒ http://ja.wikipedia.org/wiki/Befunge | 35,508 |
Problem Statement You have just arrived in a small country. Unfortunately a huge hurricane swept across the country a few days ago. The country is made up of $n$ islands, numbered $1$ through $n$. Many bridges connected the islands, but all the bridges were washed away by a flood. People in the islands need new bridges to travel among the islands again. The problem is cost. The country is not very wealthy. The government has to keep spending down. They asked you, a great programmer, to calculate the minimum cost to rebuild bridges. Write a program to calculate it! Each bridge connects two islands bidirectionally. Each island $i$ has two parameters $d_i$ and $p_i$. An island $i$ can have at most $d_i$ bridges connected. The cost to build a bridge between an island $i$ and another island $j$ is calculated by $|p_i - p_j|$. Note that it may be impossible to rebuild new bridges within given limitations although people need to travel between any pair of islands over (a sequence of) bridges. Input The input is a sequence of datasets. The number of datasets is less than or equal to $60$. Each dataset is formatted as follows. $n$ $p_1$ $d_1$ $p_2$ $d_2$ : : $p_n$ $d_n$ Everything in the input is an integer. $n$ ($2 \leq n \leq 4{,}000$) on the first line indicates the number of islands. Then $n$ lines follow, which contain the parameters of the islands. $p_i$ ($1 \leq p_i \leq 10^9$) and $d_i$ ($1 \leq d_i \leq n$) denote the parameters of the island $i$. The end of the input is indicated by a line with a single zero. Output For each dataset, output the minimum cost in a line if it is possible to rebuild bridges within given limitations in the dataset. Otherwise, output $-1$ in a line. Sample Input 4 1 1 8 2 9 1 14 2 4 181 4 815 4 634 4 370 4 4 52 1 40 1 81 2 73 1 10 330 1 665 3 260 1 287 2 196 3 243 1 815 1 287 3 330 1 473 4 0 Output for the Sample Input 18 634 -1 916 | 35,509 |
Problem B : Grid r à c ã®2次å
ã°ãªããäžã®ïŒã€ã®åº§æš ( a 1 , a 2 ) ãš ( b 1 , b 2 ) ãäžããããã ãããã¹ (e,f) ãã (e+1,f)ã(e-1,f)ã(e,f+1)ã(e,f-1) ã®ã©ããã®ãã¹ã«ç§»åããã³ã¹ããïŒãšããã ãŸãã(e,c-1) ãš (e,0)ã(r-1,f) ãš (0,f) ã®éãã³ã¹ãïŒã§ç§»åããããšãã§ããã ãã®æã«ïŒã€ç®ã®åº§æšããïŒã€ç®ã®åº§æšãžæçã³ã¹ãã§ç§»åã§ããçµè·¯ã®æ°ãæ±ããã Input å
¥åã¯ä»¥äžã®ãã©ãŒãããã§äžããããã r c a 1 a 2 b 1 b 2 å
¥åã¯ä»¥äžã®å¶çŽãæºãã 1 †r , c †1,000 0 †a 1 , b 1 < r 0 †a 2 , b 2 < c Output çãã®å€ã100,000,007ã§å²ã£ãäœããåºåããã Sample Input 1 4 4 0 0 3 3 Sample Output 1 2 Sample Input 2 4 4 0 0 1 1 Sample Output 2 2 Sample Input 3 2 3 0 0 1 2 Sample Output 3 4 Sample Input 4 500 500 0 0 200 200 Sample Output 4 34807775 | 35,510 |
Score : 500 points Problem Statement Let N be a positive integer. There is a numerical sequence of length 3N , a = (a_1, a_2, ..., a_{3N}) . Snuke is constructing a new sequence of length 2N , a' , by removing exactly N elements from a without changing the order of the remaining elements. Here, the score of a' is defined as follows: ( the sum of the elements in the first half of a') - ( the sum of the elements in the second half of a') . Find the maximum possible score of a' . Constraints 1 †N †10^5 a_i is an integer. 1 †a_i †10^9 Partial Score In the test set worth 300 points, N †1000 . Input Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N} Output Print the maximum possible score of a' . Sample Input 1 2 3 1 4 1 5 9 Sample Output 1 1 When a_2 and a_6 are removed, a' will be (3, 4, 1, 5) , which has a score of (3 + 4) - (1 + 5) = 1 . Sample Input 2 1 1 2 3 Sample Output 2 -1 For example, when a_1 are removed, a' will be (2, 3) , which has a score of 2 - 3 = -1 . Sample Input 3 3 8 2 2 7 4 6 5 3 8 Sample Output 3 5 For example, when a_2 , a_3 and a_9 are removed, a' will be (8, 7, 4, 6, 5, 3) , which has a score of (8 + 7 + 4) - (6 + 5 + 3) = 5 . | 35,511 |
20XX幎, ICPC (Ikuta's Computer Pollutes Community) ååºè¡ã®çµå¶è
ãã¡ã¯å€§æ°æ±æã«æ©ãŸãããŠããããã€ãŠã®æŽ»æ°ãåãæ»ãããã«ã倧æ°ã®ç¶ºéºããäžå®ä»¥äžã«ããªããã°ãªããªãã ååºè¡ã®åºã¯äžåã«äžŠãã§ããã1ãã n ã§çªå·ä»ããããŠããã çŸåšããã®ãã®ã®åºã®ãŸããã®å€§æ°ã®ç¶ºéºã㯠p i ã§ããã ããªãã¯2ãã nâ1 çªç®ã®åºãéžãã§ããã®åšèŸºã®å€§æ°ã埪ç°ãããããšã§, ãã®åºãšåšå²ã®åºã®å€§æ°ã®ç¶ºéºãã倿Žããããšãã§ããã æ£ç¢ºã«ãããš, i ( 2 †i †nâ1 )çªç®ãéžãã ãšãã p iâ1 ãš p i+1 ã«ã¯ p i ã ãå ç®ãã, éã« p i ã«ã¯ 2p i ã ãæžç®ããããã€ãŸããæ°ãã倧æ°ã®ç¶ºéºã p' ã¯, p' iâ1 = p iâ1 + p i p' i = p i â 2 p i p' i+1 = p i+1 + p i ãšãªãã ãã®æäœãç¹°ãè¿ããŠããã¹ãŠã®åºã®å€§æ°ã®ç¶ºéºã p i ãã蚱容ã§ããæäœéã®å€§æ°ã®ç¶ºéºã l i 以äžã«ããããšãç®çã§ããã 倧æ°ã埪ç°ãããããã«ã¯å€å€§ãªè²»çšããããããããªãã¹ãå°ãªãåæ°ã§éæãããã ICPCååºè¡ã®æªæ¥ã®ããã«ãåã貞ããŠã»ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã n p 1 ... p n l 1 ... l n n ã¯åºã®æ°ã p i 㯠i çªç®ã®åºã®çŸåšã®å€§æ°ã®ç¶ºéºãã l i 㯠i çªç®ã®åºãéæãã¹ã倧æ°ã®ç¶ºéºãã衚ãã Constraints å
¥åäžã®å倿°ã¯ä»¥äžã®å¶çŽãæºããã 3 †n †10 5 â10 8 †p i †10 8 1 †l i †10 8 Output ãã¹ãŠã®åºã倧æ°ã®ç¶ºéºããéæããããã«å¿
èŠãª 倧æ°ã埪ç°ãããåæ°ã®æå°å€ã1è¡ã«åºåããã ã©ã®ããã«æäœããŠãéæã§ããªãå Žåã«ã¯ â1 ãåºåããã Sample Input 1 3 3 -1 4 2 1 3 Output for the Sample Input 1 1 åº2ãéžã¶ããšã§, åº1,2,3ã®å€§æ°ã®ç¶ºéºãã¯ãããã2, 1, 3ãšãªãã Sample Input 2 3 3 -1 4 2 1 5 Output for the Sample Input 2 -1 ã©ã®ããã«æäœããŠãåº3ã倧æ°ã®ç¶ºéºããéæã§ããªãã Sample Input 3 4 3 -1 -1 3 1 1 1 1 Output for the Sample Input 3 3 åº2, åº3, åº2ã®é çªã§å€§æ°ã埪ç°ããããšéæããããšãã§ããã | 35,512 |
Score : 200 points Problem Statement Niwango created a playlist of N songs. The title and the duration of the i -th song are s_i and t_i seconds, respectively. It is guaranteed that s_1,\ldots,s_N are all distinct. Niwango was doing some work while playing this playlist. (That is, all the songs were played once, in the order they appear in the playlist, without any pause in between.) However, he fell asleep during his work, and he woke up after all the songs were played. According to his record, it turned out that he fell asleep at the very end of the song titled X . Find the duration of time when some song was played while Niwango was asleep. Constraints 1 \leq N \leq 50 s_i and X are strings of length between 1 and 100 (inclusive) consisting of lowercase English letters. s_1,\ldots,s_N are distinct. There exists an integer i such that s_i = X . 1 \leq t_i \leq 1000 t_i is an integer. Input Input is given from Standard Input in the following format: N s_1 t_1 \vdots s_{N} t_N X Output Print the answer. Sample Input 1 3 dwango 2 sixth 5 prelims 25 dwango Sample Output 1 30 While Niwango was asleep, two songs were played: sixth and prelims . The answer is the total duration of these songs, 30 . Sample Input 2 1 abcde 1000 abcde Sample Output 2 0 No songs were played while Niwango was asleep. In such a case, the total duration of songs is 0 . Sample Input 3 15 ypnxn 279 kgjgwx 464 qquhuwq 327 rxing 549 pmuduhznoaqu 832 dagktgdarveusju 595 wunfagppcoi 200 dhavrncwfw 720 jpcmigg 658 wrczqxycivdqn 639 mcmkkbnjfeod 992 htqvkgkbhtytsz 130 twflegsjz 467 dswxxrxuzzfhkp 989 szfwtzfpnscgue 958 pmuduhznoaqu Sample Output 3 6348 | 35,513 |
森æäŒæ¡ (Deforestation) å顿 JOI çåœã«ã¯åºå€§ãªæ£®æãããïŒæ£®æã¯é·æ¹åœ¢ã®åœ¢ãããŠããïŒååã« H ãã¹ïŒæ±è¥¿ã« W ãã¹ã®ãã¹ç®ç¶ã«åããããŠããïŒåãã i ãã¹ç®ïŒè¥¿ãã j ãã¹ç®( 1 ⊠i ⊠H, 1 ⊠j ⊠W )ã®é åã«ã¯ A_{i,j} æ¬ã®æšãçããŠããïŒãã ãïŒå西ã®ç«¯ã®é åã«ã¯æšæå å·¥å·¥å ŽãããïŒæšãçããŠããªãïŒããªãã¡ïŒ A_{1,1}=0 ã§ããïŒ æšãçããŠããªãé åã«ã¯äººãç«ã¡å
¥ãããšãåºæ¥ãïŒãŸãäººã¯æ±è¥¿ååã«é£æ¥ããé åã«ïŒãã®é åã«æšãçããŠããªããã°ïŒç§»åããããšãã§ããïŒæ£®æã®å€ã«åºãããšã¯ã§ããªãïŒJOI å㯠JOI çåœã®å
Œ
±äºæ¥ãšããŠïŒæšãäŒæ¡ãïŒå西ã®ç«¯ã®é åãšåæ±ã®ç«¯ã®é åãïŒçžäºã«è¡ãæ¥å¯èœã«ãããïŒ æšã®äŒæ¡ã¯ä»¥äžã®ããã«ããŠè¡ãïŒã¯ããïŒJOI åã¯æšæå å·¥å·¥å Žã®ããå西ã®ç«¯ã®é åã«ããïŒJOI åã¯ïŒçŸåšããé åãšæ±è¥¿ååã«é£æ¥ããæšã®çããŠããªãé åã« 1 åã§ç§»åããããšãã§ããïŒãŸãïŒæ±è¥¿ååã«é£æ¥ããæšã®çããŠããé åããïŒ 1 åã§æšã 1 æ¬äŒæ¡ããããšãã§ããïŒãã ãïŒæšã 1 æ¬äŒæ¡ãããïŒãã®ãã³ã«å西ã®ç«¯ã®é åã«ããæšæå å·¥å·¥å ŽãŸã§äŒæ¡ããæšãéã°ãªããã°ãªããªãïŒæšãéãã§ããéãïŒJOI åã®ç§»åé床ã¯å€ãããªãïŒæšãéãã§ããéã¯ïŒä»ã®æšãäŒæ¡ããããšã¯ã§ããªãïŒ æ¡ä»¶ãæºããããã«æšãäŒæ¡ããã®ã«ãããæéã®æå°å€ãæ±ããïŒãã ãïŒäŒæ¡ã«ãããæéãšã¯ïŒæåŸã«äŒæ¡ããæšãïŒæšæå å·¥å·¥å Žã«éã¶ãŸã§ã®æéãšããïŒ å¶çŽ 1 \leq H \leq 30 1 \leq W \leq 30 (H, W) â (1, 1) 0 \leq A_{i,j} ⊠10000 ( 1 \leq i \leq H, 1 \leq j \leq W ) A_{1,1}=0 å
¥åã»åºå å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ H W A_{1,1} ... A_{1,W} : A_{H,1} ... A_{H,W} åºå æ¡ä»¶ãæºããããã«æšãäŒæ¡ããã®ã«ãããæéã®æå°å€ã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 2 3 0 1 2 3 4 5 åºåäŸ 1 32 åãã i ãã¹ç®ïŒè¥¿ãã j ãã¹ç®ã®é åã (i, j) ã§è¡šãïŒ ãŸã (1, 2) ã®æšãäŒæ¡ããïŒããã«ã¯ 1 åãããïŒ æ¬¡ã« (1, 3) ã®æšããã¹ãŠäŒæ¡ããïŒ 1 æ¬äŒæ¡ããã®ã«ïŒ (1,1) ããæ±ã« 1 ãã¹é²ã¿ïŒ (1, 3) ã®æšãäŒæ¡ãïŒè¥¿ã« 1 ãã¹é²ãã§ (1,1) ã«æ»ãã°ããã®ã§ïŒ 3 åãããïŒãã£ãŠããã«ã¯ 2 à 3 = 6 åãããïŒ æ¬¡ã« (2, 3) ã®æšããã¹ãŠäŒæ¡ããïŒ 1 æ¬äŒæ¡ããã®ã«ïŒ (1,1) ããæ±ã« 2 ãã¹é²ã¿ïŒ (2, 3) ã®æšãäŒæ¡ãïŒè¥¿ã« 2 ãã¹é²ãã§ (1,1) ã«æ»ãã°ããã®ã§ïŒ 5 åãããïŒãã£ãŠããã«ã¯ 5 à 5 = 25 åãããïŒ å
šéšã§ 1 + 6 + 25 = 32 åãããïŒããããå°ãªãæéã§ïŒæ¡ä»¶ãæºããããã«æšãäŒæ¡ããããšã¯ã§ããªãã®ã§ïŒ 32 ãåºåããïŒ å
¥åäŸ 2 2 5 0 5 0 0 0 0 0 0 9 1 åºåäŸ 2 13 (2, 5) ã®æšã®ã¿ãäŒæ¡ããã°ããïŒ å
¥åäŸ 3 2 5 0 2 0 0 0 0 0 0 9 1 åºåäŸ 3 11 ãŸãïŒ (1, 2) ã®æšãäŒæ¡ããŠïŒæ¬¡ã« (2, 5) ã®æšãäŒæ¡ããã°ããïŒ æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 17 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2017/2018 äºéžç«¶æèª²é¡ã | 35,514 |
Score : 400 points Problem Statement Given is an integer S . Find how many sequences there are whose terms are all integers greater than or equal to 3 , and whose sum is equal to S . The answer can be very large, so output it modulo 10^9 + 7 . Constraints 1 \leq S \leq 2000 All values in input are integers. Input Input is given from Standard Input in the following format: S Output Print the answer. Sample Input 1 7 Sample Output 1 3 3 sequences satisfy the condition: \{3,4\} , \{4,3\} and \{7\} . Sample Input 2 2 Sample Output 2 0 There are no sequences that satisfy the condition. Sample Input 3 1729 Sample Output 3 294867501 | 35,515 |
æ£æ¹åœ¢æ¢çŽ¢ 瞊㫠n è¡ã暪㫠n å䞊ã¹ããããåèš n à n ã®ãã¹ç®ããããŸããããã€ãã®ãã¹ç®ã«ã¯å°ãã€ããŠããŸããåãã¹ç®ã®å°ã®ç¶æ
ãèªã¿èŸŒã¿ãå°ã®ã€ããŠããªããã¹ç®ã ããããªãæå€§ã®æ£æ¹åœ¢ã®èŸºã®é·ããåºåãšããŠè¡šç€ºããããã°ã©ã ãäœæããŠãã ããã ããšãã°åããŒã¿ã»ããã§ä»¥äžã®ãããªããŒã¿ãäžããããŸãã 10 ...*....** .......... **....**.. ........*. ..*....... .......... .*........ .......... ....*..*** .*....*... å
¥åããŒã¿ã®äžè¡ããäžè¡ã®ãã¹ç®ã衚çŸããŸããå
¥åããŒã¿ã®æååã®ãã¡ã.ïŒããªãªãïŒã¯å°ã®ã€ããŠããªããã¹ç®ã*ïŒã¢ã¹ã¿ãªã¹ã¯ïŒã¯å°ã®ã€ããŠãããã¹ç®ã瀺ããŠããŸãã äžèšã®äŸã§ã¯ãäžå³ã® 0 ã§ç€ºãããæ£æ¹åœ¢ãæå€§ãšãªããŸãã ...*....** .......... **....**.. ...00000*. ..*00000.. ...00000.. .*.00000.. ...00000.. ....*..*** .*....*... ãã£ãŠã5 ãšåºåããã°æ£è§£ã«ãªããŸãã ãªãããã¹ãŠã®ãã¹ç®ã«å°ãã€ããŠããå Žåã«ã¯ã0 ãåºåããŠãã ããã Input äžèšåœ¢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸãã n ã 0 ã®ãšãå
¥åã®æåŸãšããŸãã n 㯠1000 以äžãšããŸããå
¥åããŒã¿ã®æååã«ã¯ãããªãªããã¢ã¹ã¿ãªã¹ã¯ãæ¹è¡ä»¥å€ã®æåã¯å«ãŸããŸãããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output åããŒã¿ã»ããã«å¯Ÿããæå€§ã®æ£æ¹åœ¢ã®èŸºã®é·ãïŒæŽæ°ïŒãïŒè¡ã«åºåããŠäžããã Sample Input 10 ...*....** .......... **....**.. ........*. ..*....... .......... .*........ .......... ....*..*** .*....*... 10 ****.***** *..*.*.... ****.*.... *....*.... *....***** .......... ****.***** *..*...*.. ****...*.. *..*...*.. 0 Output for the Sample Input 5 3 | 35,516 |
éžäžç«¶æå€§äŒ éžäžç«¶æå€§äŒ 200M ã®æºæ±ºå 3 çµã®ã¬ãŒã¹ãè¡ãããŸãããããããã®çµã« 8 åïŒèš 24 åïŒã®éžæãåºå ŽããŸããåçµäžäœ 2 äœãŸã§ã®éžæãšãåçµã® 3 äœä»¥äžã®å
šéžæã®äžããäžäœ 2 åã®èš 8 åãæ±ºåã«é²åºããŸãã éžæçªå·ãšã¿ã€ã ãå
¥åãšããæ±ºåé²åºè
8 åã®çªå·ãšãã®ã¿ã€ã ãåºåããããã°ã©ã ãäœæããŠãã ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã p 1 t 1 p 2 t 2 : p 24 t 24 1 è¡ç®ãã 8 è¡ç®ã«ïŒçµç®ã®éžæçªå· p i (æŽæ°ã1 †p i †10000) ãšã¿ã€ã t i (1/100 ãŸã§èšæž¬ãã宿°ã1 †t i †100)ã9 è¡ç®ãã 16 è¡ç®ã«ïŒçµç®ã®éžæçªå· p i ãšã¿ã€ã t i ã17 è¡ç®ãã 24 è¡ç®ã«ïŒçµç®ã®éžæçªå· p i ãšã¿ã€ã t i ãäžããããŸããåãéžæçªå·ã®éžæãåã¿ã€ã ã®éžæã¯ããªããã®ãšããŸãã Output 以äžã®é çªã§ã決åé²åºè
ã®éžæçªå·ãšã¿ã€ã ã空çœåºåãã§ããããïŒè¡ã«åºåããŠãã ããã 1 çµç®ã® 1 äœã®éžæ 1 çµç®ã® 2 äœã®éžæ 2 çµç®ã® 1 äœã®éžæ 2 çµç®ã® 2 äœã®éžæ 3 çµç®ã® 1 äœã®éžæ 3 çµç®ã® 2 äœã®éžæ åçµã§ 3 äœä»¥äžã®éžæã®äžã§ã¿ã€ã ã 1 äœã®éžæ åçµã§ 3 äœä»¥äžã®éžæã®äžã§ã¿ã€ã ã 2 äœã®éžæ Sample Input 18 25.46 16 26.23 3 23.00 10 24.79 5 22.88 11 23.87 19 23.90 1 25.11 23 23.88 4 23.46 7 24.12 12 22.91 13 21.99 14 22.86 21 23.12 9 24.09 17 22.51 22 23.49 6 23.02 20 22.23 24 21.89 15 24.14 8 23.77 2 23.42 Output for the Sample Input 5 22.88 3 23.00 13 21.99 14 22.86 24 21.89 20 22.23 17 22.51 12 22.91 | 35,517 |
Problem H: Zombie Hunter Problem ãã£ã¡ãåã¯äººæ°ã®ã²ãŒã ãZombie Hunterã«ç±äžããŠããããã®ã²ãŒã ã«ã¯ãé ãèŽãè
ãè
°ãè¶³å°çšã®5çš®é¡ã®é²å
·ãããããã£ã¡ãåãæäœãããã¬ã€ã€ãŒãã£ã©ã¯ã¿ãŒ(PC)ã¯ãäœã®åéšã«å¯Ÿå¿ããé²å
·ãããããæå€§1ã€ãŸã§è£
åããããšãã§ããã ãŸããåé²å
·ã«ã¯éããšé²åŸ¡åãèšå®ãããŠãããPCã®è£
åããŠããé²å
·ã®éãã®åèšã A ä»¥äž B 以äžã§ããããã€é²åŸ¡åã®åèšã A ä»¥äž B 以äžã§ãããšãããã®PCã¯ã¹ãã«ãçºåããããšãã§ããã ãã£ã¡ãå㯠N åã®é²å
·ãææããŠãããè£
åããé²å
·ãé©åã«éžã¶ããšã§ãPCãã¹ãã«ãçºåããããšãã§ãããã調ã¹ãŠæ¬²ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N A B t 1 x 1 y 1 t 2 x 2 y 2 ... t N x N y N å
¥åã¯ãã¹ãп޿°ã§äžããããã 1è¡ç®ã«ãã£ã¡ãåãææããŠããé²å
·ã®æ° N , ã¹ãã«ã®çºåæ¡ä»¶ã«çšããããïŒã€ã®æŽæ° A ãš B ãäžããããã 2è¡ç®ããç¶ã N è¡ã«ã N åã®é²å
·ã®æ
å ±ãäžããããã t i , x i , y i ã¯ãããã i çªç®ã®é²å
·ã®çš®é¡ãéããé²åŸ¡åã衚ãã é²å
·ã®çš®é¡ t i ã®å€ã¯ããããã1ã®ãšãé ã®é²å
·ã2ã®ãšãèŽã®é²å
·ã3ã®ãšãè
ã®é²å
·ã4ã®ãšãè
°ã®é²å
·ã5ã®ãšãè¶³ã®é²å
·ã§ããããšã瀺ãã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã 1 †N †500 1 †A †B †10 12 1 †t i †5 â10 12 †x i , y i †10 12 Output ã¹ãã«ãçºåããããšãã§ããå Žåã¯âYesâãã§ããªãå Žåã¯âNoâã1è¡ã«åºåããã Sample Input 1 7 10 11 1 1 0 1 0 1 2 2 2 3 3 5 4 1 3 5 1 3 5 5 -1 Sample Output 1 Yes é ã«(0,1) èŽã«(2,2) è
ã«(3,5) è
°ã«(1,3) è¶³ã«(5,-1) ã®é²å
·ãè£
åãããšãéãã®åã 0+2+3+1+5 = 11ãå®ååã®åã 1+2+5+3+1 = 10 ãšãªããäž¡æ¹ã®å€ãA以äžã§ãã€B以äžãšãªãã®ã§ã¹ãã«ãçºåãããããšãã§ããã Sample Input 2 7 10 10 1 1 0 1 0 1 2 2 2 3 3 5 4 1 3 5 1 3 5 5 -1 Sample Output 2 No | 35,518 |
Problem C: Seishun 18 Kippu R倧åŠã®ãšããåŠçsirokurostoneã¯A接倧åŠã§è¡ãããå宿ã«åå ããããšããŠããã ä»ã®ã¡ã³ããŒã¯æ°å¹¹ç·ã䜿çšããäºå®ãªã®ã ããsirokurostoneã¯éæ¥18å笊ã䜿ã£ãŠåããããšããŠããã åãã鿥18å笊䜿ãã®ãšãã2D奜ããªäººç©ãå宿ã«åå ããããšããŠããã ã©ãããªããšäžç·ã«è¡ãããšèããsirokurostoneã¯éäžã®é§
ã§2D奜ããªåœŒãæŸã£ãŠåããããšèããã sirokurostoneã¯R倧åŠãåºãåã«é
å»¶ç¶æ³ã確èªããŠãããã§ãæéã®ããããªãã«ãŒããéã£ãŠA接倧åŠã®ããé§
ã«çããããšèããŠããã sirokurostoneã¯ã«ãŒãã確å®ããåŸã«2D奜ããªåœŒã«ããã®æ
å ±ãäŒããã€ããã§ããã ããããsirokurostoneã¯é
å»¶ç¶æ³ãèŠãŠãã©ã®ã«ãŒããéãã°æ©ãA接倧åŠã®ããé§
ã«å°çã§ãããåãããå°ã£ãŠããã ããã§ãããªãã®ä»äºã¯sirokurostoneã«ä»£ãã£ãŠé
å»¶ç¶æ³ããã©ããããã§A接倧åŠã®ããé§
ã«çãã®ããæ±ããããšã§ããã åé§
éã«ã¯ãé§
éã®è·é¢ãšé
å»¶äºæ³æéãããã é»è»ã¯åãå§ããŠãã40km/hãç¶æãããã®ãšããã å°ç¹aãšå°ç¹bã®éã®ç§»åæéã¯ã è·é¢/40+é
å»¶äºæ³æé ã§æ±ããããšãã§ããã åé§
ã§ã®åè»æéã¯ç¡èŠããŠãããã®ãšããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããã ããŒã¿ã»ããæ°ã¯50以äžã§ããããšãä¿éãããŠããã åããŒã¿ã»ããã¯ã次ã®åœ¢åŒãããŠããã n m s p g a 1 b 1 d 1 t 1 ... a i b i d i t i ... a m b m d m t m æŽæ° n ( 3 †n †500 )ãš m ( 2 †m †5000 )ã¯ãããããé§
ã®æ°ãåé§
éã®ç·è·¯ã®æ°ã®åèšã衚ãã s ã p ã g ã¯ãããããsirokurostoneãä¹ãé§
ã2D奜ããªäººç©ãä¹ãé§
ãA接倧åŠãããé§
ã®å Žæã瀺ãæååã§ããã s ã p ã g ã¯ããããéãæååã§ããã ç¶ã m è¡ã¯ãé§
éæ
å ±ã衚ãã a i ã b i ã¯ãç·è·¯ãã€ãªãé§
ã瀺ãæååã§ããã a i ãš b i ã¯ãåæ¹åã«è¡ãæ¥ããããšãã§ããã a i ãš b i ãäžèŽããããšã¯ãªãã æŽæ° d i ( 40 †d i †10000 )ã¯ã a i ãš b i ã®è·é¢ã衚ãã d i ã¯40ã®åæ°ã§ããããšãä¿èšŒãããŠããã æŽæ° t i ( 0 †t i †20 )ã¯ã a i ãš b i ã®éã®é
å»¶äºæ³æéã瀺ãã é§
åã衚ãæååã¯ãå
šãŠã¢ã«ãã¡ãããã®å°æåããã³å€§æåãããªã20æå以äžã®æååã§ããããããã é§
ãšé§
ã®éã®ç·è·¯ã¯é«ã
1æ¬ã§ããã å
¥åã®çµããã¯2ã€ã®ãŒããå«ãè¡ã§è¡šãããã Output å
¥åããŒã¿ã»ããããšã«ãA接倧åŠãããé§
ãžã®å°éæé(åäœ:æé)ãåºåããã sirokurostoneãä¹ãé§
ãã2D奜ããªäººãä¹ãé§
ãŸã§ã®çµè·¯ãšã2D奜ããªäººç©ãä¹ãé§
ããA接倧åŠãããé§
ã®å ŽæãŸã§ã®çµè·¯ãããããšãä¿èšŒãããŠããã Sample Input 4 4 A B G A B 40 3 B C 80 0 A G 40 0 B G 80 0 5 6 Kusatsu Tokyo Aizu Tokyo Nagoya 120 3 Kusatsu Nagoya 40 0 Kusatsu Kanazawa 40 0 Kanazawa Aizu 40 0 Tokyo Kanazawa 40 0 Tokyo Aizu 80 4 0 0 Output for Sample Input 5 4 | 35,519 |
String Compression Problem ã¢ã«ãã¡ãããã®å°æåãšæ°åãããªãæåå S ãäžãããããæ¬¡ã®æé ã§æåå S ã®é·ããå§çž®ããã æååå
ã®æåã®é çªãä»»æã®é çªã«å
¥ãæ¿ããã äŸ: "0ig3he12fz99" â "efghiz012399" æ¬¡ã®æäœãä»»æã®åæ°è¡ãã æååå
ã«ããã"abcdefghijklmnopqrstuvwxyz"ã®é£ç¶ããéšåæååãéžã³ã(å
é ã®æå)'-'(æ«å°Ÿã®æå)ã«çœ®ãæããã äŸ: "efghiz012399" â "e-iz012399" æååå
ã«ãããå
¬å·®ã1ã§ãããããªæ°åå("0123456789"ã®é£ç¶ããéšåæåå)ãéžã³ã(å
é ã®æ°å)'-'(æ«å°Ÿã®æ°å)ã«çœ®ãæããã äŸ: "e-iz012399" â "e-iz0-399" æåå S ãå§çž®ããŠåŸãããæååã®é·ãã®æå°å€ãæ±ããã Input æåå S ãïŒè¡ã§äžããããã Constraints 1 †| S | †100 æåå S ã¯ã¢ã«ãã¡ãããã®å°æåãšæ°åã®ã¿ãå«ã Output æåå S ãå§çž®ããŠåŸãããæååã®é·ãã®æå°å€ã1è¡ã«åºåãããå§çž®ã§ããªãå Žåã¯å
ã®æåå S ã®é·ããåºåããã Sample Input 1 0ig3he12fz99 Sample Output 1 9 Sample Input 2 1122334455 Sample Output 2 6 | 35,520 |
Score : 100 points Problem Statement We have an N \times N square grid. We will paint each square in the grid either black or white. If we paint exactly A squares white, how many squares will be painted black? Constraints 1 \leq N \leq 100 0 \leq A \leq N^2 Inputs Input is given from Standard Input in the following format: N A Outputs Print the number of squares that will be painted black. Sample Input 1 3 4 Sample Output 1 5 There are nine squares in a 3 \times 3 square grid. Four of them will be painted white, so the remaining five squares will be painted black. Sample Input 2 19 100 Sample Output 2 261 Sample Input 3 10 0 Sample Output 3 100 As zero squares will be painted white, all the squares will be painted black. | 35,521 |
ã¿ããªã§ãžã§ã®ã³ã° èµ€ãã³å°åŠæ ¡ã§ã¯ãçåŸå
šå¡ãåå ãããã¡ãã£ãšå€ãã£ããžã§ã®ã³ã°ãããŸããçåŸã¯ãããããç¬èªã®åšåã³ãŒã¹ããèªåã®ããŒã¹ã§èµ°ããŸããããããèªåã®ã³ãŒã¹ã 1 åšãããšå°åŠæ ¡ã«æ»ã£ãŠããŸããå
šå¡ãå°åŠæ ¡ãåæã«ã¹ã¿ãŒãããŠãããå
šå¡ãåæã«å°åŠæ ¡ã§æåã«åºäŒãã®ã¯ãããããäœåšãããšãã§ãããã? çåŸã®äººæ° n ãåçåŸã®ã³ãŒã¹ã® 1 åšã®è·é¢ d (km) ãåçåŸã®èµ°ãéã v (km/æé)ãå
¥åãšããå
šå¡ãå°åŠæ ¡ãåæã«ã¹ã¿ãŒãããŠããæ¬¡ã«åæã«å°åŠæ ¡ã«äœçœ®ããã®ã¯ãåçåŸãããããäœåšãããšãããåºåããããã°ã©ã ãäœæããŠãã ããããªããåçåŸã¯ 2 31 -1 åšãè¶
ããŠèµ°ãããšã¯ãããŸããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n d 1 v 1 d 2 v 2 : d n v n 1 è¡ç®ã«çåŸã®äººæ° n (2 †n †10) ãäžããããŸããç¶ã n è¡ã« i 人ç®ã®çåŸã®ã³ãŒã¹ã®ïŒåšã®è·é¢ d i (1 †d i †10000) ãšèµ°ãéã v i (1 †v i †10000) ãäžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 2000 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ãåçåŸã®åšåæ°ãåºåããŸããåçåŸã®åšåæ°ã¯å
¥åã®é çªã«åŸã£ãŠããããïŒè¡ã«åºåããŠãã ããã Sample Input 2 4 3 5 4 5 789 289 166 46 9 4 617 252 972 303 2 8 5 32 20 0 Output for the Sample Input 15 16 1598397732 1209243492 1939462992 1782294192 1360317793 1 1 | 35,522 |
Librarian's Work Japanese Animal Girl Library (JAG Library) is famous for a long bookshelf. It contains $N$ books numbered from $1$ to $N$ from left to right. The weight of the $i$-th book is $w_i$. One day, naughty Fox Jiro shuffled the order of the books on the shelf! The order has become a permutation $b_1, ..., b_N$ from left to right. Fox Hanako, a librarian of JAG Library, must restore the original order. She can rearrange a permutation of books $p_1, ..., p_N$ by performing either operation A or operation B described below, with arbitrary two integers $l$ and $r$ such that $1 \leq l < r \leq N$ holds. Operation A: A-1. Remove $p_l$ from the shelf. A-2. Shift books between $p_{l+1}$ and $p_r$ to $left$. A-3. Insert $p_l$ into the $right$ of $p_r$. Operation B: B-1. Remove $p_r$ from the shelf. B-2. Shift books between $p_l$ and $p_{r-1}$ to $right$. B-3. Insert $p_r$ into the $left$ of $p_l$. This picture illustrates the orders of the books before and after applying operation A and B for $p = (3,1,4,5,2,6), l = 2, r = 5$. Since the books are heavy, operation A needs $\sum_{i=l+1}^r w_{p_i} + C \times (r-l) \times w_{p_l}$ units of labor and operation B needs $\sum_{i=l}^{r-1} w_{p_i} + C \times (r-l) \times w_{p_r}$ units of labor, where $C$ is a given constant positive integer. Hanako must restore the initial order from $b_i, ..., b_N$ by performing these operations repeatedly. Find the minimum sum of labor to achieve it. Input The input consists of a single test case formatted as follows. $N$ $C$ $b_1$ $w_{b_1}$ : $b_N$ $w_{b_N}$ The first line conists of two integers $N$ and $C$ ($1 \leq N \leq 10^5, 1 \leq C \leq 100$). The ($i+1$)-th line consists of two integers $b_i$ and $w_{b_i}$ ($1 \leq b_i \leq N, 1 \leq w_{b_i} \leq 10^5$). The sequence ($b_1, ..., b_N$) is a permutation of ($1, ..., N$). Output Print the minimum sum of labor in one line. Sample Input 1 3 2 2 3 3 4 1 2 Output for Sample Input 1 15 Performing operation B with $l = 1, r = 3$, i.e. removing book 1 then inserting it into the left of book 2 is an optimal solution. It costs $(3+4)+2\times2\times2=15$ units of labor. Sample Input 2 3 2 1 2 2 3 3 3 Output for Sample Input 2 0 Sample Input 3 10 5 8 3 10 6 5 8 2 7 7 6 1 9 9 3 6 2 4 5 3 5 Output for Sample Input 3 824 | 35,523 |
Problem E: Huge Family Mr. Dango's family has extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in near future. They all have warm and gracious personality and are close each other. They usually communicate by a phone. Of course, They are all taking a family plan. This family plan is such a thing: when a choose b , and b choose a as a partner, a family plan can be applied between them and then the calling fee per unit time between them discounted to f ( a , b ), which is cheaper than a default fee. Each person can apply a family plan at most 2 times, but no same pair of persons can apply twice. Now, choosing their partner appropriately, all members of Mr. Dango's family applied twice. Since there are huge number of people, it is very difficult to send a message to all family members by a phone call. Mr. Dang have decided to make a phone calling network that is named ' clan ' using the family plan. Let us present a definition of clan . Let S be an any subset of all phone calls that family plan is applied. Clan is S such that: For any two persons (let them be i and j ), if i can send a message to j through phone calls that family plan is applied (directly or indirectly), then i can send a message to j through only phone calls in S (directly or indirectly). Meets condition 1 and a sum of the calling fee per unit time in S is minimized. Clan allows to send a message efficiently. For example, we suppose that one have sent a message through all calls related to him in the clan. Additionaly we suppose that every people follow a rule, "when he/she receives a message through a call in clan, he/she relays the message all other neibors in respect to clan." Then, we can prove that this message will surely be derivered to every people that is connected by all discounted calls, and that the message will never be derivered two or more times to same person. By the way, you are given information about application of family plan of Mr. Dango's family. Please write a program that calculates that in how many ways a different clan can be constructed. You should output the answer modulo 10007 because it may be very big. Input The input consists of several datasets. The first line of each dataset contains an integer n , which indicates the number of members in the family. Next n lines represents information of the i -th member with four integers. The first two integers respectively represent b [0] (the partner of i ) and f( i , b [0]) (the calling fee per unit time between i and b [0]). The following two integers represent b [1] and f ( i , b [1]) in the same manner. Input terminates with a dataset where n = 0. Output For each dataset, output the number of clan modulo 10007. Constraints 3 †n †100,000 Sample Input 3 1 1 2 3 0 1 2 2 1 2 0 3 7 1 2 2 1 0 2 3 2 0 1 3 1 2 1 1 2 5 3 6 2 4 3 6 1 4 2 5 1 0 Output for the Sample Input 1 2 | 35,524 |
Dice IV Write a program which reads $n$ dices constructed in the same way as Dice I , and determines whether they are all different. For the determination, use the same way as Dice III . Input In the first line, the number of dices $n$ is given. In the following $n$ lines, six integers assigned to the dice faces are given respectively in the same way as Dice III . Output Print " Yes " if given dices are all different, otherwise " No " in a line. Constraints $2 \leq n \leq 100$ $0 \leq $ the integer assigned to a face $ \leq 100$ Sample Input 1 3 1 2 3 4 5 6 6 2 4 3 5 1 6 5 4 3 2 1 Sample Output 1 No Sample Input 2 3 1 2 3 4 5 6 6 5 4 3 2 1 5 4 3 2 1 6 Sample Output 2 Yes | 35,525 |
Score : 200 points Problem Statement You are going to take the entrance examination of Kyoto University tomorrow and have decided to memorize a set of strings S that is expected to appear in the examination. Since it is really tough to memorize S as it is, you have decided to memorize a single string T that efficiently contains all the strings in S . You have already confirmed the following conditions for S and T are satisfied. Every string in S is a consecutive subsequence (1) in T . For every pair of strings x , y (x \neq y) in S , x is not a subsequence (2) of y . Note that (1) is ''consecutive subsequence'', while (2) is ''subsequence''. The next day, you opened the problem booklet at the examination and found that you can get a full score only if you remember S . However, You have forgot how to reconstruct S from T . Since all you remember is that T satisfies the above conditions, first you have decided to find the maximum possible number of elements in S . Constraints 1 \leq |T| \leq 10^5 T consists of only lowercase letters. Partial points 30 points will be awarded for passing the test set satisfying the condition: 1 \leq |T| \leq 50 . Another 30 points will be awarded for passing the test set satisfying the condition: 1 \leq |T| \leq 10^3 . Input The input is given from Standard Input in the following format: T The input only consists of T on one line. Output Print the maximum number of elements in S . Sample Input 1 abcabc Sample Output 1 3 In this case, ab ïŒ ca and bc are an example of the optimum answers. Sample Input 2 abracadabra Sample Output 2 7 Sample Input 3 abcbabbcabbc Sample Output 3 8 Sample Input 4 bbcacbcbcabbabacccbbcacbaaababbacabaaccbccabcaabba Sample Output 4 44 | 35,526 |
Score: 100 points Problem Statement Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K , while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print OK ; if he cannot, print NG . Constraints All values in input are integers. 1 \leq A \leq B \leq 1000 1 \leq K \leq 1000 Input Input is given from Standard Input in the following format: K A B Output If he can achieve the objective, print OK ; if he cannot, print NG . Sample Input 1 7 500 600 Sample Output 1 OK Among the multiples of 7 , for example, 567 lies between 500 and 600 . Sample Input 2 4 5 7 Sample Output 2 NG No multiple of 4 lies between 5 and 7 . Sample Input 3 1 11 11 Sample Output 3 OK | 35,527 |
Cycle Detection for a Directed Graph Find a cycle in a directed graph G(V, E) . Input A directed graph G is given in the following format: |V| |E| s 0 t 0 s 1 t 1 : s |E|-1 t |E|-1 |V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., |V| -1 respectively. s i and t i represent source and target nodes of i -th edge (directed). Output Print 1 if G has cycle(s), 0 otherwise. Constraints 1 †|V| †100 0 †|E| †1,000 s i â t i Sample Input 1 3 3 0 1 0 2 1 2 Sample Output 1 0 Sample Input 2 3 3 0 1 1 2 2 0 Sample Output 2 1 | 35,528 |
Day of Week The 9th day of September 2017 is Saturday. Then, what day of the week is the X-th of September 2017? Given a day in September 2017, write a program to report what day of the week it is. Input The input is given in the following format. X The input line specifies a day X (1 †X †30) in September 2017. Output Output what day of the week it is in a line. Use the following conventions in your output: " mon " for Monday, " tue " for Tuesday, " wed " for Wednesday, " thu " for Thursday, " fri " for Friday, " sat " for Saturday, and " sun " for Sunday. Sample Input 1 1 Sample Output 1 fri Sample Input 2 9 Sample Output 2 sat Sample Input 3 30 Sample Output 3 sat | 35,529 |
H - Bit Operation Game N é ç¹ã®æ ¹ä»ãæšãäžããããã é ç¹ã«ã¯ 0 ãã N â 1 ã®çªå·ãã€ããŠããã 0 çªç®ã®é ç¹ãæ ¹ã衚ãã æ ¹ã«ã¯ T = 0 ãããã以å€ã®é ç¹ã«ã¯ T=T&X T=T&Y T=T|X T=T|Y T=T^X T=T^Y ã®ããããã®æäœãæžãããŠããã ããã§ã®æŒç®å &, |, ^ ã¯ãããããããæŒç®å and, or, xor, ãæå³ããã AåãšBåã¯ãã®æšã䜿ã£ãŠä»¥äžã®ã²ãŒã ã M åè¡ã£ãã äºäººã¯æ ¹ããã¹ã¿ãŒãããåé ç¹ãéžã³é²ããšããæäœããAåããå§ãèã«å°éãããŸã§äº€äºã«è¡ãã éã£ãããŒãã«æžãããŠããæäœããéã£ãé ã«é©çšããæã®ãæçµç㪠T ã®å€ãã¹ã³ã¢ã«ãªãã Båã¯ã§ããã ãã¹ã³ã¢ãå°ããããããšèããŠããããŸãAåã¯å€§ããããããšèããŠããã Måã®ã²ãŒã ã® X , Y ã®å€ãäžããããã®ã§ãäºäººãæé©ãªéžæãããæã®åã²ãŒã ã®ã¹ã³ã¢ãåºåããã Constraints 1 †N †100000 1 †M †100000 0 †X, Y < 2^{16} Input Format å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã N M o_1 o_2 ... o_{Nâ1} u_1 v_1 u_2 v_2 ... u_{Nâ1} v_{Nâ1} X_1 Y_1 X_2 Y_2 ... X_M Y_M 1 è¡ç®ã«ã¯æšã®é ç¹æ° N ãšãè¡ãããã²ãŒã æ°ãè¡šãæŽæ° M ãå
¥åãããã 2 è¡ç®ãã N è¡ç®ã«ãããŠã 1 ... Nâ1 çªç®ã®é ç¹ã«æžãããŠããæäœãå
¥åãããã ããã«ç¶ã㊠Nâ1 è¡ã«ãå蟺ã«ããç¹ããã 2 é ç¹ã®çªå·ãå
¥åãããã æåŸã« M åã®ã²ãŒã ã«ããã X , Y ã®å€ã M è¡ã«æž¡ãå
¥åãããã Output Format åã²ãŒã ã§ã®æçµç㪠T ã®å€ããããã M è¡ã«åºåããã Sample Input 1 6 3 T=T|X T=T|Y T=T|Y T=T^Y T=T&X 0 1 0 2 1 3 1 4 2 5 5 6 3 5 0 0 Sample Output 1 4 6 0 X = 5, Y = 6 ã®å Žåãé ç¹ 0 -> 2 -> 5 ãšé²ã¿ãT = 5 & 6 = 4 ã«ãªããŸã X = 3, Y = 5 ã®å Žåãé ç¹ 0 -> 1 -> 4 ãšé²ã¿ãT = 3 ^ 5 = 6 ã«ãªããŸã X = 0, Y = 0 ã®å Žåãã©ããéã£ãŠã T 㯠0 ããå€åããŸãã | 35,530 |
Score : 1400 points Problem Statement Given are a positive integer N and a sequence of length 2^N consisting of 0 s and 1 s: A_0,A_1,\ldots,A_{2^N-1} . Determine whether there exists a closed curve C that satisfies the condition below for all 2^N sets S \subseteq \{0,1,\ldots,N-1 \} . If the answer is yes, construct one such closed curve. Let x = \sum_{i \in S} 2^i and B_S be the set of points \{ (i+0.5,0.5) | i \in S \} . If there is a way to continuously move the closed curve C without touching B_S so that every point on the closed curve has a negative y -coordinate, A_x = 1 . If there is no such way, A_x = 0 . For instruction on printing a closed curve, see Output below. Notes C is said to be a closed curve if and only if: C is a continuous function from [0,1] to \mathbb{R}^2 such that C(0) = C(1) . We say that a closed curve C can be continuously moved without touching a set of points X so that it becomes a closed curve D if and only if: There exists a function f : [0,1] \times [0,1] \rightarrow \mathbb{R}^2 that satisfies all of the following. f is continuous. f(0,t) = C(t) . f(1,t) = D(t) . f(x,t) \notin X . Constraints 1 \leq N \leq 8 A_i = 0,1 \quad (0 \leq i \leq 2^N-1) A_0 = 1 Input Input is given from Standard Input in the following format: N A_0A_1 \cdots A_{2^N-1} Output If there is no closed curve that satisfies the condition, print Impossible . If such a closed curve exists, print Possible in the first line. Then, print one such curve in the following format: L x_0 y_0 x_1 y_1 : x_L y_L This represents the closed polyline that passes (x_0,y_0),(x_1,y_1),\ldots,(x_L,y_L) in this order. Here, all of the following must be satisfied: 0 \leq x_i \leq N , 0 \leq y_i \leq 1 , and x_i, y_i are integers. ( 0 \leq i \leq L ) |x_i-x_{i+1}| + |y_i-y_{i+1}| = 1 . ( 0 \leq i \leq L-1 ) (x_0,y_0) = (x_L,y_L) . Additionally, the length of the closed curve L must satisfy 0 \leq L \leq 250000 . It can be proved that, if there is a closed curve that satisfies the condition in Problem Statement, there is also a closed curve that can be expressed in this format. Sample Input 1 1 10 Sample Output 1 Possible 4 0 0 0 1 1 1 1 0 0 0 When S = \emptyset , we can move this curve so that every point on it has a negative y -coordinate. When S = \{0\} , we cannot do so. Sample Input 2 2 1000 Sample Output 2 Possible 6 1 0 2 0 2 1 1 1 0 1 0 0 1 0 The output represents the following curve: Sample Input 3 2 1001 Sample Output 3 Impossible Sample Input 4 1 11 Sample Output 4 Possible 0 1 1 | 35,531 |
Enclosing Circles A number of circles are given. A circle may be disjoint from other circles, overlapping with some other circles, or even totally surrounding or surrounded by another circle. Figure 1. given circles Figure 2. rope layout We want to enclose all these circles by a rope. Of course, the length of the rope should be minimized. For example, given circles of Figure 1, the rope should run as shown in Figure 2. Your job is to write a program which finds the rope layout, and computes the minimum length of the rope. The thickness of the rope is negligible. Input The input consists of multiple data sets. Each data set is given in the following format. n x 1 y 1 r 1 x 2 y 2 r 2 ... x n y n r n The first line of a data set contains an integer n , which is the number of circles. n is positive, and does not exceed 100. The following n lines are descriptions of circles. Three values in a line are x -coordinate and y -coordinate of the center, and radius (called r in the rest of the problem) of the circle, in this order. Each value is given by a decimal fraction, with 3 digits after the decimal point. Values are separated by a space character. Each of x , y and r is never less than 0.01, and is never greater than 100.0. Two circles are never the same. Speaking more precisely, at least one of x , y or r of two circles has a difference larger than 0.01. The end of the input is indicated by a line containing a zero. Output For each data set, the minimum length of the rope should be printed, each in a separate line. The printed values should have 5 digits after the decimal point. They may not have an error greater than 0.00001. Sample Input 1 10.000 10.000 10.000 4 10.000 10.000 5.000 30.000 10.000 5.000 30.000 30.000 5.000 10.000 30.000 5.000 6 10.000 20.000 10.000 20.000 50.000 5.000 30.000 40.000 2.000 1.000 2.000 3.000 10.000 20.000 20.000 20.000 40.000 1.500 0 Output for the Sample Input 62.83185 111.41593 153.16052 | 35,532 |
Score : 600 points Problem Statement Snuke has a blackboard and a set S consisting of N integers. The i -th element in S is S_i . He wrote an integer X on the blackboard, then performed the following operation N times: Choose one element from S and remove it. Let x be the number written on the blackboard now, and y be the integer removed from S . Replace the number on the blackboard with x \bmod {y} . There are N! possible orders in which the elements are removed from S . For each of them, find the number that would be written on the blackboard after the N operations, and compute the sum of all those N! numbers modulo 10^{9}+7 . Constraints All values in input are integers. 1 \leq N \leq 200 1 \leq S_i, X \leq 10^{5} S_i are pairwise distinct. Input Input is given from Standard Input in the following format: N X S_1 S_2 \ldots S_{N} Output Print the answer. Sample Input 1 2 19 3 7 Sample Output 1 3 There are two possible orders in which we remove the numbers from S . If we remove 3 and 7 in this order, the number on the blackboard changes as follows: 19 \rightarrow 1 \rightarrow 1 . If we remove 7 and 3 in this order, the number on the blackboard changes as follows: 19 \rightarrow 5 \rightarrow 2 . The output should be the sum of these: 3 . Sample Input 2 5 82 22 11 6 5 13 Sample Output 2 288 Sample Input 3 10 100000 50000 50001 50002 50003 50004 50005 50006 50007 50008 50009 Sample Output 3 279669259 Be sure to compute the sum modulo 10^{9}+7 . | 35,533 |
åŒè¶ã 倪éåã¯åŒã£è¶ããããããšã«ãªããŸããã倪éåã¯ããããã®è·ç©ãæã£ãŠããã®ã§ãè·ç©ã®éæ¬ãåŒã£è¶ãæ¥è
ã«é Œãããšã«ããŸãããè·ç©ã¯ãããããªéãã®ç©ãããã®ã§ãããããããããã«è»œãæ¹ããé çªã«äžŠã¹ãŠçœ®ããŠãããããã«é Œã¿ãŸããããåŒã£è¶ãæ¥è
ã®äººã¯ã°ãã°ãã®é çªã§è·ç©ã眮ããŠãã£ãŠããŸããŸãããããã§å€ªéåã¯è·ç©ãäžŠã¹æ¿ããããšããŸããããè·ç©ã¯éãã®ã§éã¶ã®ã«ã¯äœåãå¿
èŠã§ããããããã®è·ç©ã¯ä»ããå Žæããä»ã®è·ç©ã®éãè·ç©ã®ç«¯ãªã©å¥œããªå Žæã«éã¶ããšãã§ããŸãããããè·ç©ãéã¶ã«ã¯ãã®è·ç©ã®éããšåãã ãäœåã䜿ããŸãã倪éåã¯ããŸãäœåããªãã®ã§ãã§ããã ãäœåã䜿ããã«è·ç©ãè»œãæ¹ããé çªã«äžŠã¹ãæ¹æ³ãèããããšã«ããŸããã Input n x 1 x 2 ... x n n ã¯å€ªéåã®æã£ãŠããè·ç©ã®æ°ã衚ã x 1 ãã x n ã¯ããããã®è·ç©ã®éãã衚ããçŸåšã¯ x 1 ã x 2 ãâŠã x n ã®é ã«äžŠãã§ãã Constraints 1 †n †10 5 1 †x i †n (1 †i †n) x i â x j ( 1 †i, j †n ã〠i â j ) å
¥åã¯ãã¹ãп޿°ã§äžãããã Output S è·ç©ãè»œãæ¹ããé çªã«äžŠã¹ãã®ã«å¿
èŠãªæå°ã®äœåã®åèš S ãåºåããããã ãæåŸã«æ¹è¡ãåºåãã Sample Input 1 4 1 4 2 3 Output for the Sample Input 1 4 éã4ã®è·ç©ãå³ç«¯ã«éã¶ãšéãã®è»œãé ã«ãªããŸã Sample Input 2 5 1 5 3 2 4 Output for the Sample Input 2 7 éã2ã®è·ç©ãéã1ã®è·ç©ã®å³åŽã«éã³ãéã5ã®è·ç©ãå³ç«¯ã«éã¶ãšéãã®è»œãé ã«ãªããŸã Sample Input 3 7 1 2 3 4 5 6 7 Output for the Sample Input 3 0 æåããéãã®è»œãé ã«äžŠãã§ããŸã Sample Input 4 8 6 2 1 3 8 5 4 7 Output for the Sample Input 4 19 | 35,534 |
Score : 200 points Problem Statement Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i -th candidate is D_i . There must be M problems in the problem set, and the difficulty of the i -th problem must be T_i . Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems. Constraints 1 \leq N \leq 200,000 1 \leq D_i \leq 10^9 1 \leq M \leq 200,000 1 \leq T_i \leq 10^9 All numbers in the input are integers. Partial Score 100 points will be awarded for passing the test set satisfying N \leq 100 and M \leq 100 . Input Input is given from Standard Input in the following format: N D_1 D_2 ... D_N M T_1 T_2 ... T_M Output Print YES if Rng can complete the problem set without creating new candidates of problems; print NO if he cannot. Sample Input 1 5 3 1 4 1 5 3 5 4 3 Sample Output 1 YES Sample Input 2 7 100 200 500 700 1200 1600 2000 6 100 200 500 700 1600 1600 Sample Output 2 NO Not enough 1600 s. Sample Input 3 1 800 5 100 100 100 100 100 Sample Output 3 NO Sample Input 4 15 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 9 5 4 3 2 1 2 3 4 5 Sample Output 4 YES | 35,535 |
Expression Mining Consider an arithmetic expression built by combining single-digit positive integers with addition symbols + , multiplication symbols * , and parentheses ( ) , defined by the following grammar rules with the start symbol E . E ::= T | E '+' T T ::= F | T '*' F F ::= '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '(' E ')' When such an arithmetic expression is viewed as a string, its substring, that is, a contiguous sequence of characters within the string, may again form an arithmetic expression. Given an integer n and a string s representing an arithmetic expression, let us count the number of its substrings that can be read as arithmetic expressions with values computed equal to n . Input The input consists of multiple datasets, each in the following format. n s A dataset consists of two lines. In the first line, the target value n is given. n is an integer satisfying 1 †n †10 9 . The string s given in the second line is an arithmetic expression conforming to the grammar defined above. The length of s does not exceed 2Ã10 6 . The nesting depth of the parentheses in the string is at most 1000. The end of the input is indicated by a line containing a single zero. The sum of the lengths of s in all the datasets does not exceed 5Ã10 6 . Output For each dataset, output in one line the number of substrings of s that conform to the above grammar and have the value n . The same sequence of characters appearing at different positions should be counted separately. Sample Input 3 (1+2)*3+3 2 1*1*1+1*1*1 587 1*(2*3*4)+5+((6+7*8))*(9) 0 Output for the Sample Input 4 9 2 | 35,536 |
Score : 400 points Problem Statement Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9) . The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6 , respectively. Constraints All values in input are integers. 2 \leq N \leq 10^4 1 \leq M \leq 9 1 \leq A_i \leq 9 A_i are all different. There exists an integer that can be formed by exactly N matchsticks under the conditions. Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M Output Print the largest integer that can be formed with exactly N matchsticks under the conditions in the problem statement. Sample Input 1 20 4 3 7 8 4 Sample Output 1 777773 The integer 777773 can be formed with 3 + 3 + 3 + 3 + 3 + 5 = 20 matchsticks, and this is the largest integer that can be formed by 20 matchsticks under the conditions. Sample Input 2 101 9 9 8 7 6 5 4 3 2 1 Sample Output 2 71111111111111111111111111111111111111111111111111 The output may not fit into a 64 -bit integer type. Sample Input 3 15 3 5 4 6 Sample Output 3 654 | 35,537 |
Score : 500 points Problem Statement We have a sequence of N integers: A_1, A_2, \cdots, A_N . You can perform the following operation between 0 and K times (inclusive): Choose two integers i and j such that i \neq j , each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j , possibly producing a negative element. Compute the maximum possible positive integer that divides every element of A after the operations. Here a positive integer x divides an integer y if and only if there exists an integer z such that y = xz . Constraints 2 \leq N \leq 500 1 \leq A_i \leq 10^6 0 \leq K \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_{N-1} A_{N} Output Print the maximum possible positive integer that divides every element of A after the operations. Sample Input 1 2 3 8 20 Sample Output 1 7 7 will divide every element of A if, for example, we perform the following operation: Choose i = 2, j = 1 . A becomes (7, 21) . We cannot reach the situation where 8 or greater integer divides every element of A . Sample Input 2 2 10 3 5 Sample Output 2 8 Consider performing the following five operations: Choose i = 2, j = 1 . A becomes (2, 6) . Choose i = 2, j = 1 . A becomes (1, 7) . Choose i = 2, j = 1 . A becomes (0, 8) . Choose i = 2, j = 1 . A becomes (-1, 9) . Choose i = 1, j = 2 . A becomes (0, 8) . Then, 0 = 8 \times 0 and 8 = 8 \times 1 , so 8 divides every element of A . We cannot reach the situation where 9 or greater integer divides every element of A . Sample Input 3 4 5 10 1 2 22 Sample Output 3 7 Sample Input 4 8 7 1 7 5 6 8 2 6 5 Sample Output 4 5 | 35,538 |
Digits Are Not Just Characters Mr. Manuel Majorana Minore made a number of files with numbers in their names. He wants to have a list of the files, but the file listing command commonly used lists them in an order different from what he prefers, interpreting digit sequences in them as ASCII code sequences, not as numbers. For example, the files file10 , file20 and file3 are listed in this order. Write a program which decides the orders of file names interpreting digit sequences as numeric values. Each file name consists of uppercase letters (from ' A ' to ' Z '), lowercase letters (from ' a ' to ' z '), and digits (from ' 0 ' to ' 9 '). A file name is looked upon as a sequence of items, each being either a letter or a number. Each single uppercase or lowercase letter forms a letter item. Each consecutive sequence of digits forms a number item. Two item are ordered as follows. Number items come before letter items. Two letter items are ordered by their ASCII codes. Two number items are ordered by their values when interpreted as decimal numbers. Two file names are compared item by item, starting from the top, and the order of the first different corresponding items decides the order of the file names. If one of them, say $A$, has more items than the other, $B$, and all the items of $B$ are the same as the corresponding items of $A$, $B$ should come before. For example, three file names in Sample Input 1, file10 , file20 , and file3 all start with the same sequence of four letter items f , i , l , and e , followed by a number item, 10, 20, and 3, respectively. Comparing numeric values of these number items, they are ordered as file3 $<$ file10 $<$ file20 . Input The input consists of a single test case of the following format. $n$ $s_0$ $s_1$ : $s_n$ The integer $n$ in the first line gives the number of file names ($s_1$ through $s_n$) to be compared with the file name given in the next line ($s_0$). Here, $n$ satisfies $1 \leq n \leq 1000$. The following $n + 1$ lines are file names, $s_0$ through $s_n$, one in each line. They have at least one and no more than nine characters. Each of the characters is either an uppercase letter, a lowercase letter, or a digit. Sequences of digits in the file names never start with a digit zero (0). Output For each of the file names, $s_1$ through $s_n$, output one line with a character indicating whether it should come before $s_0$ or not. The character should be " - " if it is to be listed before $s_0$; otherwise, it should be " + ", including cases where two names are identical. Sample Input 1 2 file10 file20 file3 Sample Output 1 + - Sample Input 2 11 X52Y X X5 X52 X52Y X52Y6 32 ABC XYZ x51y X8Y X222 Sample Output 2 - - - + + - - + + - + | 35,539 |
Score : 300 points Problem Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1 , Island 2 , ..., Island N . There are M kinds of regular boat services between these islands. Each service connects two islands. The i -th service connects Island a_i and Island b_i . Cat Snuke is on Island 1 now, and wants to go to Island N . However, it turned out that there is no boat service from Island 1 to Island N , so he wants to know whether it is possible to go to Island N by using two boat services. Help him. Constraints 3 †N †200 000 1 †M †200 000 1 †a_i < b_i †N (a_i, b_i) \neq (1, N) If i \neq j , (a_i, b_i) \neq (a_j, b_j) . Input Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M Output If it is possible to go to Island N by using two boat services, print POSSIBLE ; otherwise, print IMPOSSIBLE . Sample Input 1 3 2 1 2 2 3 Sample Output 1 POSSIBLE Sample Input 2 4 3 1 2 2 3 3 4 Sample Output 2 IMPOSSIBLE You have to use three boat services to get to Island 4 . Sample Input 3 100000 1 1 99999 Sample Output 3 IMPOSSIBLE Sample Input 4 5 5 1 3 4 5 2 3 2 4 1 4 Sample Output 4 POSSIBLE You can get to Island 5 by using two boat services: Island 1 -> Island 4 -> Island 5 . | 35,540 |
åé¡ E : ãã¡ãŒã¹ãã¢ã¯ã»ãã¿ã³ã¹ ããã°ã©ãã³ã°ã³ã³ãã¹ãã§ã¯ïŒååé¡ã«é¢ããŠïŒ ãã®åé¡ãæåã«æ£è§£ãã人ã®ååãæ£è§£æéãïŒ ãã¡ãŒã¹ãã¢ã¯ã»ãã¿ã³ã¹ïŒæåã®æ£è§£ïŒãšããŠè§£èª¬çã§ãã°ãã°èšåãããïŒ ä¹
ãã¶ãã«ããã°ã©ãã³ã°ã³ã³ãã¹ãã«åå ãããšã¯ããïŒäºéžã§èœã¡ããšã¯å°åºæããªãïŒ ãªãã°ïŒæåã®ãã¡ã¯ïŒå€å°é«ãã¹ã³ã¢ãåãããšãç®æããããïŒ ãã¡ãŒã¹ãã¢ã¯ã»ãã¿ã³ã¹ãå€ãç²åŸãïŒååšãã¢ããŒã«ããã»ããè¯ãã®ã§ã¯ãªããïŒ èªåã®å®åãæã£ãŠããã°ïŒååé¡ãèŠãç¬éã«ïŒ ãã®åé¡ãèªåãäœåã§è§£ãããšãã§ããããšïŒ ãã®åé¡ãéå§åŸäœåã§èªå以å€ã®åå è
ã«ãã£ãŠæåã«è§£ããããããããïŒ ãããã®æ
å ±ãçšããŠïŒ ã©ã®çšåºŠãã¡ãŒã¹ãã¢ã¯ã»ãã¿ã³ã¹ãç²åŸã§ããããèšç®ããããã°ã©ã ãäœã£ãŠãããïŒ åé¡ N åã®åé¡ããæãããã°ã©ãã³ã°ã³ã³ãã¹ããèããïŒ åé¡ i ãèªåãè§£ãã«ã¯ A i ç§ã®æéããããïŒ ãŸãïŒåé¡ i ã¯éå§åŸ B i ç§ã§èªå以å€ã®åå è
ã«ãã£ãŠæåã«è§£ããããšããïŒ èªåãåé¡ãè§£ãé çªã¯èªç±ã«æ±ºãããããïŒ 1 ã€ã®åé¡ãè§£ãå§ãããïŒè§£ãçµãããŸã§ãã®åé¡ããããã®ãšããïŒ åé¡ãè§£ãçµã次ã®åé¡ã«åããããéãªã©ã®ïŒ åé¡ãè§£ããŠããæé以å€ã®æéã¯ååå°ãããšèãïŒç¡èŠããŠèããããšã«ããïŒ ãŸãïŒå
šãŠã®åé¡ã¯çµäºãŸã§ã« 1 人以äžã®èªå以å€ã®åå è
ã«ãã£ãŠè§£ããããã®ãšèããïŒ èªå以å€ã®åå è
ã«ãã£ãŠæåã«è§£ããããããæ©ãïŒ ãããã¯åæã«åé¡ i ãèªåãè§£ããããæïŒ åé¡ i ã®ãã¡ãŒã¹ãã¢ã¯ã»ãã¿ã³ã¹ãç²åŸã§ããïŒ ããªãã¡ïŒåé¡ i ãèªåãéå§åŸ t i ç§ã«è§£ãçµãããšãããšãïŒ t i †B i ã§ããã°ïŒåé¡ i ã®ãã¡ãŒã¹ãã¢ã¯ã»ãã¿ã³ã¹ãç²åŸã§ããïŒ æå€§ã§äœåã®åé¡ã«é¢ããŠãã¡ãŒã¹ãã¢ã¯ã»ãã¿ã³ã¹ãç²åŸã§ããããèšç®ããããã°ã©ã ãäœæããïŒ å
¥å å
¥åã®æåã®è¡ã¯ 1 ã€ã®æŽæ° N ãå«ãïŒ ç¶ã N è¡ã«ã¯ïŒååé¡ã«é¢ããæ
å ±ãäžããããïŒ ãããã®è¡ã®ãã¡ã® i è¡ç®ã«ã¯ 2 åã®æ°å A i , B i ãæžãããŠããïŒ åºå æå€§ã§ç²åŸããããšã®ã§ãããã¡ãŒã¹ãã¢ã¯ã»ãã¿ã³ã¹ã®æ°ãåºåããïŒ å¶çŽ 1 †N †1000 1 †A i †10 6 ( 1 †i †N ) 1 †B i †10 6 ( 1 †i †N ) éšåç¹ ãã®åé¡ã®å€å®ã«ã¯ïŒ20 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒ ãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã®å
¥åã¯ä»¥äžãæºããïŒ 1 †N †16 å
¥åºåäŸ å
¥åºåäŸ 1 å
¥åäŸ 1: 3 3 5 5 9 10 20 å
¥åäŸ 1 ã«å¯ŸããåºåäŸ: 3 å
¥åºåäŸ 2 å
¥åäŸ 2: 3 3 2 5 15 10 12 å
¥åäŸ 2 ã«å¯ŸããåºåäŸ: 2 | 35,541 |
Score : 800 points Problem Statement Niwango-kun, an employee of Dwango Co., Ltd., likes Niconico TV-chan, so he collected a lot of soft toys of her and spread them on the floor. Niwango-kun has N black rare soft toys of Niconico TV-chan and they are spread together with ordinary ones. He wanted these black rare soft toys to be close together, so he decided to rearrange them. In an infinitely large two-dimensional plane, every lattice point has a soft toy on it. The coordinates (x_i,y_i) of N black rare soft toys are given. All soft toys are considered to be points (without a length, area, or volume). He may perform the following operation arbitrarily many times: Put an axis-aligned square with side length D , rotate the square by 90 degrees with four soft toys on the four corners of the square. More specifically, if the left bottom corner's coordinate is (x, y) , rotate four points (x,y) \rightarrow (x+D,y) \rightarrow (x+D,y+D) \rightarrow (x,y+D) \rightarrow (x,y) in this order. Each of the four corners of the square must be on a lattice point. Let's define the scatteredness of an arrangement by the minimum side length of an axis-aligned square enclosing all black rare soft toys. Black rare soft toys on the edges or the vertices of a square are considered to be enclosed by the square. Find the minimum scatteredness after he performs arbitrarily many operations. Constraints 2 \leq N \leq 10^5 1 \leq D \leq 1000 0 \leq x_i, y_i \leq 10^9 Given coordinates are pairwise distinct All numbers given in input are integers Partial Scores 500 points will be awarded for passing the test set satisfying 1 \leq D \leq 30 . Input Input is given from Standard Input in the following format: N D x_1 y_1 : x_N y_N Output Print the answer. Sample Input 1 3 1 0 0 1 0 2 0 Sample Output 1 1 Sample Input 2 19 2 1 3 2 3 0 1 1 1 2 1 3 1 4 4 5 4 6 4 7 4 8 4 8 3 8 2 8 1 8 0 7 0 6 0 5 0 4 0 Sample Output 2 4 Sample Input 3 8 3 0 0 0 3 3 0 3 3 2 2 2 5 5 2 5 5 Sample Output 3 4 | 35,542 |
Score : 800 points Problem Statement Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string: The 0 key: a letter 0 will be inserted to the right of the string. The 1 key: a letter 1 will be inserted to the right of the string. The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted. Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s . Find the number of such ways to press the keys, modulo 10^9 + 7 . Constraints 1 ⊠N ⊠5000 1 ⊠|s| ⊠N s consists of the letters 0 and 1 . Partial Score 400 points will be awarded for passing the test set satisfying 1 ⊠N ⊠300 . Input The input is given from Standard Input in the following format: N s Output Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7 . Sample Input 1 3 0 Sample Output 1 5 We will denote the backspace key by B . The following 5 ways to press the keys will cause the editor to display the string 0 in the end: 00B , 01B , 0B0 , 1B0 , BB0 . In the last way, nothing will happen when the backspace key is pressed. Sample Input 2 300 1100100 Sample Output 2 519054663 Sample Input 3 5000 01000001011101000100001101101111011001000110010101110010000 Sample Output 3 500886057 | 35,543 |
E: ãžã£ã (Jam) åé¡ ããåœã«ã¯ N åã®è¡ãããã 1,\ 2,\ ...,\ N ã®çªå·ãã€ããããŠããŸãããããã®è¡ã¯ M æ¬ã®éã§åæ¹åã«çµã°ããŠããã i çªç®ã®éã䜿ããšè¡ u_i ãš v_i ã®éãæé t_i ã§ç§»åããããšãã§ããŸãããŸããã©ã® 2 ã€ã®è¡ãããã€ãã®éã䜿ãããšã§è¡ãæ¥ããããšãã§ããŸãã ããããã®è¡ã§ã¯é£ãã³ã売ãããŠãããè¡ i ã§å£²ãããŠããé£ãã³ã®çŸå³ãã㯠P_i ã§ãã ããã«ããã®åœã«ã¯ K çš®é¡ã®å³ã®ãžã£ã ããããè¡ i ã§ã¯å³ c_i ã§çŸå³ãã J_i ã®ãžã£ã ãè²·ãããšãã§ããŸãã è¡ 1 ã«äœãã§ããã»ãã¡ããã¯ããããããã³ãšãžã£ã ã 1 ã€ãã€è²·ãã«ãåºããããããšã«ããŸãããã»ãã¡ããã¯ãããã€ãã®è¡ãç§»åããŠãã³ãšãžã£ã ãè²·ã£ãŠè¡ 1 ã«æ»ã£ãŠããŸããããæ£ç¢ºã«ã¯ãããè¡ u ã«ç§»åããŠãã³ãè²·ããããè¡ v ãéžãã§ãžã£ã ãè²·ããè¡ 1 ã«æ»ã£ãŠããŸãããã®éã u=v ã u=1 ã v=1 ã§ãæ§ããŸããã ãè²·ãç©ãçµããã»ãã¡ããã®å¹žçŠåºŠã¯ããè²·ã£ããã³ãšãžã£ã ã®çŸå³ããã®åèšããŒãç§»åã«ããã£ãæéãã§ãã K çš®é¡ããããã®ãžã£ã ã«ã€ããŠããã®å³ã®ãžã£ã ãšãã³ãè²·ãã«è¡ããšãã®å¹žçŠåºŠãšããŠèããããæå€§å€ãèšç®ããŠãã ããã å
¥ååœ¢åŒ N M K P_1 P_2 ... P_N c_1 c_2 ... c_N J_1 J_2 ... J_N u_1 v_1 t_1 u_2 v_2 t_2 : u_M v_M t_M å¶çŽ 1\leq N\leq 10^5 1\leq M\leq 2\times 10^5 1\leq K\leq N 1\leq P_i, J_i\leq 10^9 1\leq c_i\leq K 1\leq u_i, v_i \leq N 1\leq t_i \leq 10^9 ãã¹ãŠã® i\ (1\leq i\leq K) ã«ã€ããŠã c_j=i ãšãªã j\ (1\leq j\leq N) ãååšãã äžããããã°ã©ãã¯å€é蟺ãèªå·±ã«ãŒããå«ãŸãªãé£çµãªã°ã©ãã§ãã å
¥åã¯ãã¹ãп޿°ã§äžãããã åºååœ¢åŒ K è¡åºåããŠãã ããã i è¡ç®ã«ã¯ãã³ãšå³ i ã®ãžã£ã ãè²·ãã«è¡ãå Žåã®å¹žçŠåºŠã®æå€§å€ãåºåããŠãã ããã å
¥åäŸ 1 4 4 3 3 6 1 6 1 1 2 3 6 1 5 5 1 2 1 2 3 1 1 3 1 1 4 1 åºåäŸ 1 10 8 9 å³ 1 ã®ãžã£ã ãè²·ãå Žå è¡ 1 ã§ãžã£ã ãè²·ããè¡ 2 ã«ç§»åããŠãã³ãè²·ããè¡ 1 ã«æ»ã£ãŠãããšã幞çŠåºŠã¯ 6+6-2=10 ãšãªããããæé©ã§ãã å³ 2 ã®ãžã£ã ãè²·ãå Žå è¡ 2 ã«ç§»åããŠãã³ãè²·ããè¡ 3 ã«ç§»åããŠãžã£ã ãè²·ããè¡ 1 ã«æ»ã£ãŠãããšã幞çŠåºŠã¯ 6+5-3=8 ãšãªããŸãã å³ 3 ã®ãžã£ã ãè²·ãå Žå è¡ 4 ã«ç§»åããŠãã³ãšãžã£ã ã®äž¡æ¹ãè²·ã£ãŠè¡ 1 ã«æ»ã£ãŠãããšã幞çŠåºŠã¯ 6+5-2=9 ãšãªããŸãã å
¥åäŸ 2 2 1 2 1 1 1 2 1 1 1 2 1000000000 åºåäŸ 2 2 -1999999998 ãã³ããžã£ã ã®çŸå³ããã«æ¯ã¹ãŠè·é¢ãé ãããã®ã§ã»ãã¡ããã¯äžæºããã§ãã å
¥åäŸ 3 6 8 3 31 41 59 26 53 58 1 2 3 1 2 3 27 18 28 18 28 46 1 2 3 2 3 7 2 4 8 3 6 9 3 5 3 4 5 3 1 5 15 4 6 7 åºåäŸ 3 66 61 68 | 35,544 |
Advanced Algorithm Class In the advanced algorithm class, n 2 students sit in n rows and n columns. One day, a professor who teaches this subject comes into the class, asks the shortest student in each row to lift up his left hand, and the tallest student in each column to lift up his right hand. What is the height of the student whose both hands are up ? The student will become a target for professorâs questions. Given the size of the class, and the height of the students in the class, you have to print the height of the student who has both his hands up in the class. Input The input will consist of several cases. the first line of each case will be n(0 < n < 100), the number of rows and columns in the class. It will then be followed by a n-by-n matrix, each row of the matrix appearing on a single line. Note that the elements of the matrix may not be necessarily distinct. The input will be terminated by the case n = 0. Output For each input case, you have to print the height of the student in the class whose both hands are up. If there is no such student, then print 0 for that case. Sample Input 3 1 2 3 4 5 6 7 8 9 3 1 2 3 7 8 9 4 5 6 0 Output for the Sample Input 7 7 | 35,545 |
Structured Programming In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops. Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto. Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements. void call(int n){ int i = 1; CHECK_NUM: int x = i; if ( x % 3 == 0 ){ cout << " " << i; goto END_CHECK_NUM; } INCLUDE3: if ( x % 10 == 3 ){ cout << " " << i; goto END_CHECK_NUM; } x /= 10; if ( x ) goto INCLUDE3; END_CHECK_NUM: if ( ++i <= n ) goto CHECK_NUM; cout << endl; } Input An integer n is given in a line. Output Print the output result of the above program for given integer n . Constraints 3 †n †10000 Sample Input 30 Sample Output 3 6 9 12 13 15 18 21 23 24 27 30 Put a single space character before each element. | 35,546 |
Problem C: Palindrome Problem 倪éåã¯ããããã®é·ãã L ã®æååã N åæã£ãŠããã倪éåã¯åæã倧奜ããªã®ã§ã N åã®ãã¡ããã€ãã®æååãéžãã§å¥œããªé çªã«äžŠã¹ãããšã§ãã§ããã ãé·ãåæãäœãããã 倪éåãäœãããšã®ã§ããåæã®äžã§ãæé·ã®ãã®ãæ±ãããè€æ°ããå Žåã¯ããã®ãã¡èŸæžé ã§æå°ã®ãã®ãåºåãããã©ã®ããã«éžãã§äžŠã¹ãŠãåæãäœããªãå Žåã¯ã空è¡ãåºåããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N L s 1 s 2 . . . s N 1è¡ç®ã«ãæååã®æ° N ãšæååã®é·ã L ãäžãããããç¶ã2è¡ç®ãã N + 1è¡ç®ã«å€ªéåãæã£ãŠããæåå s_i ãäžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã 1 †N †1000 1 †L †30 s_i ã¯è±å°æåãããªãæååã§ããã Output æé·ã®åæã®äžã§èŸæžé æå°ã®ãã®ãåºåãããåæãäœããªãå Žåã¯ç©ºè¡ãåºåããã Sample Input 1 4 2 oi io rr rr Sample Output 1 iorrrroi Sample Input 2 5 1 a b c a c Sample Output 2 acbca Sample Input 3 3 3 uki uku uke Sample Output 3 uku | 35,547 |
æ€çŽ¢ãšã³ãžã³ ã€ã³ã¿ãŒãããã®æ€çŽ¢ãšã³ãžã³ãäŸãã°ãGoogle ãªã©ã§ã¯ãäžçäžã®ãŠã§ãããŒãžãèªåã§åæšããŠåé¡ãã巚倧ãªããŒã¿ããŒã¹ãäœæããŸãããŸãããŠãŒã¶ãå
¥åããæ€çŽ¢ããŒã¯ãŒããè§£æããŠãããŒã¿ããŒã¹æ€çŽ¢ã®ããã®åãåããæãäœæããŸãã ãããã®å Žåããå¹ççãªæ€çŽ¢ãå®çŸããããã«è€éãªåŠçãè¡ã£ãŠããŸããããšããããã®åºæ¬ã¯å
šãŠæç« ããã®åèªã®åãåºãã§ãã ãšããããšã§ãæç« ããã®åèªã®åãåºãã«ææŠããŠãã ãããä»åã¯ä»¥äžã®éããåèªåºåããæç¢ºãªè±èªã®æç« ã察象ãšããŸãã 察象ãšãªãæç« ïŒ æ¹è¡ãå«ãŸãªã 1024 æå以äžã®è±èªã®æç« åºåãæå ïŒ ããããåè§ã§ç©ºçœãããªãªããã«ã³ãã®ã¿ åãåºãåèª ïŒ 3 ãã 6 æåã®åèªïŒ2æå以äžã7æå以äžã®åèªã¯ç¡èŠïŒ å
¥å åºåãæååã³è±æ°åã§æ§æãããè±æãïŒè¡ïŒãã¹ãŠåè§ïŒã«äžããããŸãã åºå ç©ºçœæåïŒæåïŒåè§ïŒã§åºåãããåèªãïŒè¡ã«åºåããŠãã ããã Sample Input Rain, rain, go to Spain. Output for the Sample Input Rain rain Spain Sample Input 2 Win today's preliminary contest and be qualified to visit University of Aizu. Output for the Sample Input 2 Win and visit Aizu | 35,548 |
Score : 800 points Problem Statement There are N points on a number line, i -th of which is placed on coordinate X_i . These points are numbered in the increasing order of coordinates. In other words, for all i ( 1 \leq i \leq N-1 ), X_i < X_{i+1} holds. In addition to that, an integer K is given. Process Q queries. In the i -th query, two integers L_i and R_i are given. Here, a set s of points is said to be a good set if it satisfies all of the following conditions. Note that the definition of good sets varies over queries. Each point in s is one of X_{L_i},X_{L_i+1},\ldots,X_{R_i} . For any two distinct points in s , the distance between them is greater than or equal to K . The size of s is maximum among all sets that satisfy the aforementioned conditions. For each query, find the size of the union of all good sets. Constraints 1 \leq N \leq 2 \times 10^5 1 \leq K \leq 10^9 0 \leq X_1 < X_2 < \cdots < X_N \leq 10^9 1 \leq Q \leq 2 \times 10^5 1 \leq L_i \leq R_i \leq N All values in input are integers. Input Input is given from Standard Input in the following format: N K X_1 X_2 \cdots X_N Q L_1 R_1 L_2 R_2 \vdots L_Q R_Q Output For each query, print the size of the union of all good sets in a line. Sample Input 1 5 3 1 2 4 7 8 2 1 5 1 2 Sample Output 1 4 2 In the first query, you can have at most 3 points in a good set. There exist two good sets: \{1,4,7\} and \{1,4,8\} . Therefore, the size of the union of all good sets is |\{1,4,7,8\}|=4 . In the second query, you can have at most 1 point in a good set. There exist two good sets: \{1\} and \{2\} . Therefore, the size of the union of all good sets is |\{1,2\}|=2 . Sample Input 2 15 220492538 4452279 12864090 23146757 31318558 133073771 141315707 263239555 350278176 401243954 418305779 450172439 560311491 625900495 626194585 891960194 5 6 14 1 8 1 13 7 12 4 12 Sample Output 2 4 6 11 2 3 | 35,549 |
Score : 1100 points Problem Statement Niwango bought a piece of land that can be represented as a half-open interval [0, X) . Niwango will lay out N vinyl sheets on this land. The sheets are numbered 1,2, \ldots, N , and they are distinguishable. For Sheet i , he can choose an integer j such that 0 \leq j \leq X - L_i and cover [j, j + L_i) with this sheet. Find the number of ways to cover the land with the sheets such that no point in [0, X) remains uncovered, modulo (10^9+7) . We consider two ways to cover the land different if and only if there is an integer i (1 \leq i \leq N) such that the region covered by Sheet i is different. Constraints 1 \leq N \leq 100 1 \leq L_i \leq X \leq 500 All values in input are integers. Input Input is given from Standard Input in the following format: N X L_1 L_2 \ldots L_N Output Print the answer. Sample Input 1 3 3 1 1 2 Sample Output 1 10 If we ignore whether the whole interval is covered, there are 18 ways to lay out the sheets. Among them, there are 4 ways that leave [0, 1) uncovered, and 4 ways that leave [2, 3) uncovered. Each of the other ways covers the whole interval [0,3) , so the answer is 10 . Sample Input 2 18 477 324 31 27 227 9 21 41 29 50 34 2 362 92 11 13 17 183 119 Sample Output 2 134796357 Find the number of ways modulo (10^9+7) . | 35,550 |
Score : 400 points Problem Statement You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health , and the health of the i -th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below. Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows: Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A , and the health of each of the other monsters will decrease by B . Here, A and B are predetermined parameters, and A > B holds. At least how many explosions do you need to cause in order to vanish all the monsters? Constraints All input values are integers. 1 †N †10^5 1 †B < A †10^9 1 †h_i †10^9 Input Input is given from Standard Input in the following format: N A B h_1 h_2 : h_N Output Print the minimum number of explosions that needs to be caused in order to vanish all the monsters. Sample Input 1 4 5 3 8 7 4 2 Sample Output 1 2 You can vanish all the monsters in two explosion, as follows: First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3 , 4 , 1 and -1 , respectively, and the last monster vanishes. Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0 , -1 and -2 , respectively, and all the monsters are now vanished. Sample Input 2 2 10 4 20 20 Sample Output 2 4 You need to cause two explosions centered at each monster, for a total of four. Sample Input 3 5 2 1 900000000 900000000 1000000000 1000000000 1000000000 Sample Output 3 800000000 | 35,551 |
One-Way Conveyors You are working at a factory manufacturing many different products. Products have to be processed on a number of different machine tools. Machine shops with these machines are connected with conveyor lines to exchange unfinished products. Each unfinished product is transferred from a machine shop to another through one or more of these conveyors. As the orders of the processes required are not the same for different types of products, the conveyor lines are currently operated in two-way. This may induce inefficiency as conveyors have to be completely emptied before switching their directions. Kaizen (efficiency improvements) may be found here! Adding more conveyors is too costly. If all the required transfers are possible with currently installed conveyors operating in fixed directions, no additional costs are required. All the required transfers, from which machine shop to which, are listed at hand. You want to know whether all the required transfers can be enabled with all the conveyors operated in one-way, and if yes, directions of the conveyor lines enabling it. Input The input consists of a single test case of the following format. $n$ $m$ $x_1$ $y_1$ . . . $x_m$ $y_m$ $k$ $a_1$ $b_1$ . . . $a_k$ $b_k$ The first line contains two integers $n$ ($2 \leq n \leq 10 000$) and $m$ ($1 \leq m \leq 100 000$), the number of machine shops and the number of conveyors, respectively. Machine shops are numbered $1$ through $n$. Each of the following $m$ lines contains two integers $x_i$ and $y_i$ ($1 \leq x_i < y_i \leq n$), meaning that the $i$-th conveyor connects machine shops $x_i$ and $y_i$. At most one conveyor is installed between any two machine shops. It is guaranteed that any two machine shops are connected through one or more conveyors. The next line contains an integer $k$ ($1 \leq k \leq 100 000$), which indicates the number of required transfers from a machine shop to another. Each of the following $k$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i \leq n$, $1 \leq b_i \leq n$, $a_i \ne b_i$), meaning that transfer from the machine shop $a_i$ to the machine shop $b_i$ is required. Either $a_i \ne a_j$ or $b_i \ne b_j$ holds for $i \ne j$. Output Output â No â if it is impossible to enable all the required transfers when all the conveyors are operated in one-way. Otherwise, output â Yes â in a line first, followed by $m$ lines each of which describes the directions of the conveyors. All the required transfers should be possible with the conveyor lines operated in these directions. Each direction should be described as a pair of the machine shop numbers separated by a space, with the start shop number on the left and the end shop number on the right. The order of these $m$ lines do not matter as far as all the conveyors are specified without duplicates or omissions. If there are multiple feasible direction assignments, whichever is fine. Sample Input 1 3 2 1 2 2 3 3 1 2 1 3 2 3 Sample Output 1 Yes 1 2 2 3 Sample Input 2 3 2 1 2 2 3 3 1 2 1 3 3 2 Sample Output 2 No Sample Input 3 4 4 1 2 1 3 1 4 2 3 7 1 2 1 3 1 4 2 1 2 3 3 1 3 2 Sample Output 3 Yes 1 2 2 3 3 1 1 4 | 35,552 |
JAG-channel ãã€ãµã³ã»Oã»ãã€ãã¹ã¯JAG-channelãšããé»åæ²ç€ºæ¿ãéå¶ããŠããïŒ åœŒã¯çŸåšïŒã¹ã¬ãããã¥ãŒãšããæ°æ©èœã®è¿œå ã«åãçµãã§ããïŒ ä»ã®å€ãã®é»åæ²ç€ºæ¿ãšåãããã«ïŒJAG-channelã¯ã¹ã¬ããããŒã¹ã§ããïŒ ããã§ïŒã¹ã¬ãããšã¯ïŒäžé£ã®æçš¿ãããªãäžã€ã®äŒè©±ã®ãŸãšãŸããæãïŒ æçš¿ã«ã¯ïŒä»¥äžã®2çš®é¡ãååšããïŒ æ°ããã¹ã¬ãããäœãæåã®æçš¿ ãã§ã«ããã¹ã¬ããã®éå»ã®æçš¿ãžã®è¿ä¿¡ ã¹ã¬ãããã¥ãŒã¯ïŒæçš¿éã®è¿ä¿¡ã»è¢«è¿ä¿¡é¢ä¿ã«ããè«ççãªæ§é ã衚ãïŒããªãŒç¶ã®ãã¥ãŒã§ããïŒ ããããã®æçš¿ã¯ããªãŒã®ããŒããšãªãïŒãã®æçš¿ã«å¯Ÿããè¿ä¿¡ãåããŒããšããŠæã€ïŒ ããæçš¿ã«å¯ŸããçŽæ¥ã»éæ¥ã®è¿ä¿¡ãïŒå
šäœãšããŠéšåæšãšãªãããšã«æ³šæããŠã»ããïŒ äŸãèŠãŠã¿ããïŒäŸãã°ïŒ " hoge "ãšããæåã®æçš¿ã«å¯Ÿã㊠" fuga "ãš" piyo "ãšãã2ã€ã®è¿ä¿¡ãä»ãïŒ " fuga "ã«å¯ŸããŠããã«" foobar "ãš" jagjag "ãšããè¿ä¿¡ãä»ãïŒ " jagjag "ã«å¯ŸããŠ" zigzag "ãšããè¿ä¿¡ãä»ãããšããïŒ ãã®ã¹ã¬ããã®ããªãŒã¯æ¬¡ã®ããã«ãªãïŒ hoge ââfuga â ââfoobar â ââjagjag â ââzigzag ââpiyo ãã€ãµã³ã»Oã»ãã€ãã¹ã¯ããã°ã©ããŒãéã£ãŠæ©èœãå®è£
ãããŠãããïŒãã®ããã°ã©ããŒãæåŸã®æ®µéã§å€±èžªããŠããŸã£ãïŒ ãã®ããã°ã©ããŒã¯ïŒã¹ã¬ããã®ããªãŒãäœãïŒãããç°¡æãã©ãŒãããã§è¡šç€ºãããšãããŸã§å®æãããŠããïŒ ãã®ç°¡æãã©ãŒãããã§ã¯ïŒè¿ä¿¡ã®æ·±ãã ' . ' (åè§ããã) ã§è¡šããïŒããæçš¿ã«å¯Ÿããè¿ä¿¡ã¯ïŒå
ã®æçš¿ãã1ã€å€ãã® ' . ' ãå·Šã«ã€ãïŒãŸãïŒããæçš¿ã«å¯Ÿããè¿ä¿¡ã¯å¿
ãå
ã®æçš¿ãããäžã«æ¥ãïŒè¿ä¿¡å
ã®æçš¿ãšè¿ä¿¡ã®éã«ã¯ïŒè¿ä¿¡å
ã®æçš¿ã«å¯Ÿããä»ã®è¿ä¿¡ (ããã³ïŒããã«å¯ŸããçŽæ¥ã»éæ¥ã®è¿ä¿¡) ãçŸããããšããããïŒãã以å€ã®æçš¿ãäž¡è
ã®éã«çŸããããšã¯ãªãïŒ äžã®ããªãŒã®ç°¡æãã©ãŒãããè¡šç€ºã¯æ¬¡ã®ããã«ãªãïŒ hoge .fuga ..foobar ..jagjag ...zigzag .piyo ããªãã®ä»äºã¯ïŒãã®ç°¡æãã©ãŒããã衚瀺ãåãåãïŒèŠãããæŽåœ¢ããããšã§ããïŒ ããªãã¡ïŒ åæçš¿ã®ããå·Šã® ' . ' (åæçš¿ã®å·Šã«ã€ãã ' . ' ã®ãã¡ïŒãã£ãšãå³ã®ãã®) ã ' + ' (åè§ãã©ã¹)ïŒ åãæçš¿ã«å¯ŸããçŽæ¥ã®è¿ä¿¡ã«ã€ããŠïŒããããã®ããå·Šã«ãã ' + ' ã®éã«äœçœ®ãã ' . ' ã ' | ' (åè§çžŠç·)ïŒ ãã以å€ã® ' . ' 㯠' ' (åè§ã¹ããŒã¹) ã«çœ®ãæããŠæ¬²ããïŒ äžã®ç°¡æãã©ãŒããã衚瀺ã«å¯ŸããæŽåœ¢æžã¿ã®è¡šç€ºã¯æ¬¡ã®ããã«ãªãïŒ hoge +fuga |+foobar |+jagjag | +zigzag +piyo Input å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æãããïŒåããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããïŒ $n$ $s_1$ $s_2$ ... $s_n$ $n$ ã¯ç°¡æãã©ãŒããã衚瀺ã®è¡æ°ãè¡šãæŽæ°ã§ããïŒ$1$ ä»¥äž $1{,}000$ 以äžãšä»®å®ããŠããïŒ ç¶ã $n$ è¡ã«ã¯ã¹ã¬ããããªãŒã®ç°¡æãã©ãŒããã衚瀺ãèšèŒãããŠããïŒ $s_i$ ã¯ç°¡æãã©ãŒããã衚瀺㮠$i$ è¡ç®ã衚ãïŒããã€ãã® ' . ' ãšïŒããã«ç¶ã $1$ æåä»¥äž $50$ æå以äžã®ã¢ã«ãã¡ãããå°æåã§æ§æãããæååãããªãïŒ $s_1$ ã¯ã¹ã¬ããã®æåã®æçš¿ã§ããïŒ' . ' ãå«ãŸãªãïŒ $s_2$, ..., $s_n$ ã¯ãã®ã¹ã¬ããã§ã®è¿ä¿¡ã§ããïŒå¿
ã1ã€ä»¥äžã® ' . ' ãå«ãïŒ $n=0$ ã¯å
¥åã®çµããã瀺ãïŒããã¯ããŒã¿ã»ããã«ã¯å«ããªãïŒ Output åããŒã¿ã»ããã«å¯ŸããæŽåœ¢æžã¿ã®è¡šç€ºãå $n$ è¡ã§åºåããïŒ Sample Input 6 hoge .fuga ..foobar ..jagjag ...zigzag .piyo 8 jagjag .hogehoge ..fugafuga ...ponyoponyo ....evaeva ....pokemon ...nowawa .buhihi 8 hello .goodmorning ..howareyou .goodafternoon ..letshavealunch .goodevening .goodnight ..gotobed 3 caution .themessagelengthislessthanorequaltofifty ..sothelengthoftheentirelinecanexceedfiftycharacters 0 Output for Sample Input hoge +fuga |+foobar |+jagjag | +zigzag +piyo jagjag +hogehoge |+fugafuga | +ponyoponyo | |+evaeva | |+pokemon | +nowawa +buhihi hello +goodmorning |+howareyou +goodafternoon |+letshavealunch +goodevening +goodnight +gotobed caution +themessagelengthislessthanorequaltofifty +sothelengthoftheentirelinecanexceedfiftycharacters | 35,553 |
Score : 200 points Problem Statement You are given a positive integer X . Find the largest perfect power that is at most X . Here, a perfect power is an integer that can be represented as b^p , where b is an integer not less than 1 and p is an integer not less than 2 . Constraints 1 †X †1000 X is an integer. Input Input is given from Standard Input in the following format: X Output Print the largest perfect power that is at most X . Sample Input 1 10 Sample Output 1 9 There are four perfect powers that are at most 10 : 1 , 4 , 8 and 9 . We should print the largest among them, 9 . Sample Input 2 1 Sample Output 2 1 Sample Input 3 999 Sample Output 3 961 | 35,554 |
Watch Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively. Input An integer $S$ is given in a line. Output Print $h$, $m$ and $s$ separated by ':'. You do not need to put '0' for a value, which consists of a digit. Constraints $0 \leq S \leq 86400$ Sample Input 1 46979 Sample Output 1 13:2:59 | 35,555 |
Problem K: Rearranging Seats Haruna is a high school student. She must remember the seating arrangements in her class because she is a class president. It is too difficult task to remember if there are so many students. That is the reason why seating rearrangement is depress task for her. But students have a complaint if seating is fixed. One day, she made a rule that all students must move but they don't move so far as the result of seating rearrangement. The following is the rule. The class room consists of r*c seats. Each r row has c seats. The coordinate of the front row and most left is (1,1). The last row and right most is ( r , c ). After seating rearrangement, all students must move next to their seat. If a student sit ( y , x ) before seating arrangement, his/her seat must be ( y , x +1) , ( y , x -1), ( y +1, x ) or ( y -1, x ). The new seat must be inside of the class room. For example (0,1) or ( r +1, c ) is not allowed. Your task is to check whether it is possible to rearrange seats based on the above rule. Input Input consists of multiple datasets. Each dataset consists of 2 integers. The last input contains two 0. A dataset is given by the following format. r c Input satisfies the following constraint. 1 †r †19, 1 †c †19 Output Print "yes" without quates in one line if it is possible to rearrange the seats, otherwise print "no" without quates in one line. Sample Input 1 1 2 2 0 0 Sample Output no yes Hint For the second case, before seat rearrangement, the state is shown as follows. 1 2 3 4 There are some possible arrangements. For example 2 4 1 3 or 2 1 4 3 is valid arrangement. | 35,556 |
Score : 150 points Problem Statement There is a long blackboard with 2 rows and N columns in a classroom of Kyoto University. This blackboard is so long that it is impossible to tell which cells are already used and which unused. Recently, a blackboard retrieval device was installed at the classroom. To use this device, you type a search query that forms a rectangle with 2 rows and any length of columns, where each cell is used or unused. When you input a query, the decive answers whether the rectangle that corresponds to the query exists in the blackboard. Here, for a rectangle that corresponds to a search query, if two integer i, j ( i < j ) exist and the rectangle equals to the partial blackboard between column i and j , the rectangle is called a sub-blackboard of the blackboard. You are currently preparing for a presentation at this classroom. To make the presentation go well, you decided to write a program to detect the status of the whole blackboard using the retrieval device. Since it takes time to use the device, you want to use it as few times as possible. The status of the whole blackboard is already determined at the beginning and does not change while you are using the device. Input The first input is given in the following format: N N (1 \leq N \leq 100) is an integer that represents the length of the blackboard. After this input value, your program must print search queries. A search query has the following format. s_1 s_2 Here, s_1 represents the upper part of the blackboard and s_2 represents the lower. # in s_1 and s_2 represents the cell is already used and . represents the cell is still unused. The lengths of s_1 and s_2 are arbitrary, but they must be the same. Make sure to insert a line break at the end of the lines. Every time your program prints a search query, a string that represents the search result of the device is returned in the followin format. r r is either T or F . The meaning of each character is as follows. T represents that the sub-blackboard that corresponds to the search query exists in the blackboard. F represents that the sub-blackboard that corresponds to the search query does not exist in the blackboard. If the search query equals to the whole blackboard or the number of the search queries exceeds the limit, string end is given instead of r . Once you receive this string, exit your program immediately. If your program prints the whole blackboard as a search query before exceedin the limit, it is judged as Accepted . Note that the search query that represents the whole blackboard is also counted as the number of search queries. Note that the output needs to be flushed every time the output is printed. For example, In C/C++, search query s1 , s2 can be printed as follows. printf("%s\n%s\n", s1, s2); fflush(stdout); Make sure your program receive all the input from the device. Otherwise, the result may be Time Limit Exceeded . Query Limit The maximun number of search queries is 420 . If the number of queries exceeds the limit, the result will be Query Limit Exceeded . Sample Input and Output The following is an example where N=3 and the blackboard is as follows. .#. ... Note that your program does not know the state of the blackboard. Output of your program Input to your program Explanation 3 The length of the blackboard is given .. ## Output a search query F The sub-blackboard does not exist . . Output a search query T The sub-blackboard exists .. .. Output a search query F The sub-blackboard does not exist .# .. Output a search query T The sub-blackboard exists .#. ... Output a search query end Exit your program because the above sub-blackboard equals to the whole blackboard. | 35,557 |
Star in Parentheses You are given a string $S$, which is balanced parentheses with a star symbol ' * ' inserted. Any balanced parentheses can be constructed using the following rules: An empty string is balanced. Concatenation of two balanced parentheses is balanced. If $T$ is balanced parentheses, concatenation of ' ( ', $T$, and ' ) ' in this order is balanced. For example, ' ()() ' and ' (()()) ' are balanced parentheses. ' )( ' and ' )()(() ' are not balanced parentheses. Your task is to count how many matching pairs of parentheses surround the star. Let $S_i$be the $i$-th character of a string $S$. The pair of $S_l$ and $S_r$ ($l < r$) is called a matching pair of parentheses if $S_l$ is ' ( ', $S_r$ is ' ) ' and the surrounded string by them is balanced when ignoring a star symbol. Input The input consists of a single test case formatted as follows. $S$ $S$ is balanced parentheses with exactly one ' * ' inserted somewhere. The length of $S$ is between 1 and 100, inclusive. Output Print the answer in one line. Sample Input 1 ((*)()) Output for Sample Input 1 2 Sample Input 2 (*) Output for Sample Input 2 1 Sample Input 3 (()())* Output for Sample Input 3 0 Sample Input 4 ()*() Output for Sample Input 4 0 Sample Input 5 ((((((((((*)))))))))) Output for Sample Input 5 10 Sample Input 6 * Output for Sample Input 6 0 | 35,558 |
ããã㯠A ããã®å®¶ã«èŠªæã® B åããã£ãŠããŸããã圌㯠3 æ³ã§ãããã¯ã倧奜ãã§ãã圌ãæã£ãŠãããããã¯ã¯å³ 1 ã®ãããªåœ¢ãããŠããŸãã å³1 B åã¯ããŒãã®äžã«ãããã¯ãæ·ãè©°ããŠããŸãã圌ã«ãäœãäœã£ãŠããã®?ããšèããšã圌ã¯ãè¿·è·¯!!ããšå
æ°ããçããŸããã圌ã®èšãè¿·è·¯ãšã¯ãã¹ã¿ãŒããããŽãŒã«ãŸã§åŽé¢ãæ¥ããŠãããåãè²ã®ãããã¯ã ãã§ãã©ãããšãã§ãããããã¯ã®é
眮ã®ããšã ããã§ããå³ 2 ã¯é»è²ã®ãããã¯ã«ãããå·Šäž(ã¹ã¿ãŒã)ããå³äž(ãŽãŒã«)ãžè¿·è·¯ãã§ããŠããããšã衚ããŠããŸãã å³2 ç¡éªæ°ã«éãã§ãã B åãæšªç®ã«ãããã°ã©ããŒã§ããããªãã¯ããããã¯ã®äžŠã³ãè¿·è·¯ãšãªã£ãŠãããã確ãããŠã¿ãããšã«ããŸããã ãããã¯ã®æ
å ±ãšã¹ã¿ãŒãããŽãŒã«ã®åº§æšãå
¥åãšãããããã¯ãè¿·è·¯ãšãªã£ãŠããã° OK ããªã£ãŠããªããã° NG ãåºåããããã°ã©ã ãäœæããŠãã ããã ããŒãã¯æšªæ¹åã« w ã瞊æ¹åã« h ã®å€§ããããã¡ã å·Šäžã®åº§æšã¯(1 , 1)ãå³äžã®åº§æšã¯( w, h )ãšããŸãããããã¯ã¯ 2 à 4 ã®é·æ¹åœ¢ã§ãã¹ãŠåã倧ããã§ãããããã¯ã®è² c 㯠1 (çœ)ã2 (é»)ã3 (ç·)ã4 (é)ã5 (èµ€) ã®ããããã§ãããããã¯ã®ããŒãäžã§ã®åã d 㯠暪æ¹åã«é·ãå Žå 0 ã 瞊æ¹åã«é·ãå Žå 1 ãšããŸãã ãããã¯ã®äœçœ®ã¯ãããã¯ã®å·Šäžã®åº§æš ( x, y ) ã«ãã£ãŠè¡šãããŸãããªãããããã¯ã®äœçœ®ã¯ä»ã®ãããã¯ãšéãªãããšã¯ç¡ããããŒãããã¯ã¿åºãããšããããŸããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸãã å
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã w h xs ys xg yg n c 1 d 1 x 1 y 1 c 2 d 2 x 2 y 2 : c n d n x n y n 1 è¡ç®ã«ããŒãã®å€§ãã w, h (4 †w, h †100) ãäžããããŸãã2 è¡ç®ã«ã¹ã¿ãŒãã®åº§æš xs, ys ã3 è¡ç®ã«ãŽãŒã«ã®åº§æš xg, yg ãäžããããŸãã 4 è¡ç®ã«ãããã¯ã®åæ° n ãäžããããŸããç¶ã n è¡ã« i çªç®ã®ãããã¯ã®è² c i ãåã d i ãäœçœ® x i , y i ãäžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 30 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ãå€å¥çµæãïŒè¡ã«åºåããŸãã Sample Input 20 20 1 1 9 9 7 2 0 1 1 5 1 1 3 2 1 3 3 1 1 5 2 5 1 7 3 2 0 2 7 2 0 6 8 20 20 9 9 1 1 6 2 0 1 1 1 0 5 1 2 1 1 3 5 0 1 7 3 1 5 5 4 1 8 5 0 0 Output for the Sample Input OK NG | 35,559 |
Score : 1600 points Problem Statement A + B balls are arranged in a row. The leftmost A balls are colored red, and the rightmost B balls are colored blue. You perform the following operation: First, you choose two integers s, t such that 1 \leq s, t \leq A + B . Then, you repeat the following step A + B times: In each step, you remove the first ball or the s -th ball (if it exists) or the t -th ball (if it exists, all indices are 1-based) from left in the row, and give it to Snuke. In how many ways can you give the balls to Snuke? Compute the answer modulo 10^9 + 7 . Here, we consider two ways to be different if for some k , the k -th ball given to Snuke has different colors. In particular, the choice of s, t doesn't matter. Also, we don't distinguish two balls of the same color. Constraints 1 \leq A, B \leq 2000 Input Input is given from Standard Input in the following format: A B Output Print the answer. Sample Input 1 3 3 Sample Output 1 20 There are 20 ways to give 3 red balls and 3 blue balls. It turns out that all of them are possible. Here is an example of the operation ( r stands for red, b stands for blue): You choose s = 3, t = 4 . Initially, the row looks like rrrbbb . You remove 3 rd ball ( r ) and give it to Snuke. Now the row looks like rrbbb . You remove 4 th ball ( b ) and give it to Snuke. Now the row looks like rrbb . You remove 1 st ball ( r ) and give it to Snuke. Now the row looks like rbb . You remove 3 rd ball ( b ) and give it to Snuke. Now the row looks like rb . You remove 1 st ball ( r ) and give it to Snuke. Now the row looks like b . You remove 1 st ball ( b ) and give it to Snuke. Now the row is empty. This way, Snuke receives balls in the order rbrbrb . Sample Input 2 4 4 Sample Output 2 67 There are 70 ways to give 4 red balls and 4 blue balls. Among them, only bbrrbrbr , brbrbrbr , and brrbbrbr are impossible. Sample Input 3 7 9 Sample Output 3 7772 Sample Input 4 1987 1789 Sample Output 4 456315553 | 35,560 |
Problem J: Yu-kun Likes a lot of Money Background äŒæŽ¥å€§åŠä»å±å¹Œçšåã¯ããã°ã©ãã³ã°ã倧奜ããªåäŸãéãŸã幌çšåã§ãããåå
ã®äžäººã§ããããåã¯ãããã°ã©ãã³ã°ãšåãããããéã倧奜ãã ãããåã¯ã仿¥ããéã皌ãããã«è²¡å®ã®ç ãå³¶ã蚪ãããããåã¯äºåã«è²¡å®ã®ãããã®æãããå°å³ãæã«å
¥ããŠããããã®å°å³ãããšã«åºæ¥ãã ãå€ãã®ãéã皌ããããããåã¯æå€§ã§ã©ã®ããããéãæã«å
¥ããããšãã§ããã ãããïŒ Problem å°å³ãããåã®åæäœçœ®ã財å®ã®çš®é¡ãšãããããåŸããããéããããŠå°ãã岩ãç Žå£ããããã«å¿
èŠãªè²»çšã®æ
å ±ãäžãããããå°å³ã®æ
å ±ã¯ h ãã¹ Ã w ãã¹ã®ãã£ãŒã«ããšããŠäžãããããå°å³ã®åãã¹ã«æžãããŠããæåãšãã®æå³ã¯æ¬¡ã®éãã§ããã '@' : ããåãæåã«ããäœçœ®ã衚ããããåãç§»åããåŸã¯éãšåãããã«æ±ãã '.' : éã衚ãããã®ãã¹ã¯èªç±ã«éãããšãã§ãè²»çšãããããªãã '#' : 倧ããªå²©ã衚ãããã®ãã¹ã¯éãããšãã§ããªãã '*' : å°ããªå²©ã衚ããäžå®ã®éé¡ãæ¯æãããšã§å£ãããšãã§ãããå£ããåŸã¯éã«ãªãã '0','1',...,'9','a','b',...,'z','A','B',...,'Z' : 財å®ããããã¹ã衚ãããã®ãã¹ã蚪ããããšã§ããã«æžãããŠããæåã«å¯Ÿå¿ãã財å®ã®éé¡åã®ãéãåŸãããã ããéãåŸãããšãåºæ¥ãã®ã¯æåã«èšªããæã®ã¿ã§ããã ããåã¯ïŒåã®ç§»åã§é£æ¥ããäžäžå·Šå³ã®ããããã®ãã¹ã«ç§»åããããšãã§ããã ãã ããå°å³ã®å€ãžåºããããªç§»åã¯ã§ããªãã åŸæããããããšãã§ãããããå°ããªå²©ãå£ãéã«ããã«å¿
èŠãªéé¡ããã®æã«ææããŠããå¿
èŠã¯ãªãããã®ãããããåã¯æçµçã«å°ããªå²©ãå£ãéã«ããã£ãéé¡ã®ç·å以äžã®ãéãåŸãŠããå¿
èŠãããã ããåãåŸãããæå€§ã®éé¡ãåºåããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã h w n r c 1,1 c 1,2 ⊠c 1,w c 2,1 c 2,2 ⊠c 2,w ⊠c h,1 c h,2 ⊠c h,w m 1 v 1 m 2 v 2 ⊠m n v n ïŒè¡ç®ã«å°å³ã®çžŠã®é·ã h ,暪ã®é·ã w ,å°å³ã«å«ãŸãã財å®ã®æ° n ,å°ããªå²©ãç Žå£ããããã«ãããè²»çš r ã空çœåºåãã§äžããããã ç¶ã h è¡ã«å°å³ã衚ãåãã¹ã®æ
å ± c i,j ã w åäžããããã ( 1 †i †h , 1 †j †w ) ç¶ã n è¡ã«è²¡å®ã®çš®é¡ m k ãšãã®è²¡å®ã®éé¡ v k ã空çœåºåãã§äžããããã ( 1 †k †n ) Constraints å
¥åã¯ä»¥äžã®å¶çŽãæºããã 1 †h , w †8 0 †n †min( h à w -1,62) ãã ããmin( a , b )㯠a , b ã®æå°å€ã衚ã 1 †v i †10 5 ( 1 †i †n ) 1 †r †10 5 c j,k , m l ãé€ãå
šãŠã®å
¥åã¯æŽæ°ãšããŠäžãããã ( 1 †j †h , 1 †k †w , 1 †l †n ) å°å³ã«ã¯ã¡ããã©ã²ãšã€'@'ãæžãããŠãã å°å³ã«ã¯ã¡ããã© n åã®è²¡å®ãæžãããŠãã å°å³ã«æžãããŠãã財å®ã®çš®é¡ã¯å
¥åã§äžãããã m l ã®ããããã§ãã å°å³ã«åãçš®é¡ã®è²¡å®ãïŒã€ä»¥äžçŸããããšã¯ãªã Output ããåãåŸãããæå€§ã®ãéã®éé¡ã1è¡ã«åºåããã Sample Input1 3 3 1 10 @0. ... ... 0 100 Sample Output1 100 Sample Input2 3 3 1 10 @#b .#. .#. b 100 Sample Output2 0 Sample Input3 3 3 1 20 @*C ..* ... C 10 Sample Output3 0 | 35,561 |
J: Tiles are Colorful ICPC ã§è¯ãæçžŸãåããã«ã¯ä¿®è¡ãæ¬ ãããªãïŒããã㯠ICPC ã§åã¡ããã®ã§ïŒä»æ¥ãä¿®è¡ãããããšã«ããïŒ ä»æ¥ã®ä¿®è¡ã¯ïŒæµè¡ãã®ããºã«ããã°ããè§£ããŠïŒç¬çºåãéããããšãããã®ã§ããïŒä»æ¥ææŠããã®ã¯ïŒè²ãšãã©ãã®ã¿ã€ã«ã䞊ãã§ããŠããããäžæãæ¶ããŠããããºã«ã åæç¶æ
ã§ã¯ïŒã°ãªããäžã®ããã€ãã®ãã¹ã«ã¿ã€ã«ã眮ãããŠããïŒåã¿ã€ã«ã«ã¯è²ãã€ããŠããïŒãã¬ã€ã€ãŒã¯ã²ãŒã éå§åŸïŒä»¥äžã®æé ã§ç€ºãããæäœãäœåãè¡ãããšãã§ããïŒ ã¿ã€ã«ã眮ãããŠããªããã¹ã 1 ã€éžæãïŒãã®ãã¹ãå©ãïŒ å©ãããã¹ããäžã«é ã«èŸ¿ã£ãŠããïŒã¿ã€ã«ã眮ãããŠãããã¹ã«è³ã£ããšããã§ãã®ã¿ã€ã«ã«çç®ããïŒã¿ã€ã«ã眮ãããŠãããã¹ããªããŸãŸç€é¢ã®ç«¯ã«èŸ¿ãçãããäœã«ãçç®ããªãïŒ åæ§ã®æäœãå©ãããã¹ããäžã»å·Šã»å³æ¹åã«å¯ŸããŠè¡ãïŒæå€§ 4 æã®ã¿ã€ã«ãçç®ãããããšã«ãªãïŒ çç®ããã¿ã€ã«ã®äžã§åãè²ã®ãã®ãããã°ïŒãããã®ã¿ã€ã«ãç€é¢ããåãé€ãïŒåãè²ã®ã¿ã€ã«ã®çµã 2 çµããã°ïŒãããäž¡æ¹ãåãé€ãïŒ ã¿ã€ã«ãåãé€ããææ°ãšåãå€ã®åŸç¹ãå
¥ãïŒ çç®ããããïŒ ããšãã°ïŒä»¥äžã®ãããªç¶æ³ãèãããïŒã¿ã€ã«ã眮ãããŠããªããã¹ã¯ããªãªãã§ïŒã¿ã€ã«ã®è²ã¯ã¢ã«ãã¡ããã倧æåã§è¡šãããŠããïŒ ..A....... .......B.. .......... ..B....... ..A.CC.... ããã§äžãã 2 è¡ç®ïŒå·Šãã 3 åç®ã®ãã¹ãå©ãæäœãèããïŒçç®ããããšã«ãªãã¿ã€ã«ã¯ A , B , B ã® 3 æã§ããããïŒ B ã® 2 æãæ¶ããŠç€é¢ã¯ä»¥äžã®ããã«ãªãïŒ2 ç¹ãåŸãïŒ ..A....... .......... .......... .......... ..A.CC.... ãã®ããºã«ã¯ãã£ããããŠãããšæéåãã«ãªã£ãŠããŸãïŒç€é¢ã®äžéšãèŠããªããªãã©ã®ãããä¿®è¡ãè¶³ããªãã£ãã®ããããããªããªã£ãŠããŸãïŒ åè²ã®ã¿ã€ã«ã¯ 2 æãã€çœ®ãããŠãããïŒãããããã¹ãŠæ¶ãããšã¯éããªãã®ã§ïŒäºãããã°ã©ã ã«åŸç¹ã®æå€§å€ãèšç®ãããŠããããïŒ Input M N C 1,1 C 1,2 ... C 1, N C 2,1 C 2,2 ... C 2, N ... C M ,1 C M ,2 ... C M , N æŽæ° M , N ã¯ç€ã 瞊 M à 暪 N ã®ãã¹ç®ã§ããããšã衚ãïŒ C i , j ã¯ã¢ã«ãã¡ããã倧æåãŸãã¯ããªãªã ( . ) ã§ããïŒäžãã i è¡ç®ïŒå·Šãã j åç®ã®ãã¹ã«ã€ããŠïŒã¢ã«ãã¡ããã倧æåã®å Žåã¯çœ®ãããŠããã¿ã€ã«ã®è²ã衚ãïŒããªãªãã®å Žåã¯ãã®ãã¹ã«ã¿ã€ã«ã眮ãããŠããªãããšã衚ãïŒ 1 †M †500ïŒ1 †N †500 ãæºããïŒåã¢ã«ãã¡ããã倧æåã¯å
¥åäžã« 0 åãŸã㯠2 åçŸããïŒ Output åŸç¹ã®æå€§å€ã 1 è¡ã«åºåããïŒ Sample Input 1 5 10 ..A....... .......B.. .......... ..B....... ..A.CC.... Sample Output 1 4 Sample Input 2 3 3 ABC D.D CBA Sample Output 2 4 Sample Input 3 5 7 NUTUBOR QT.SZRQ SANAGIP LMDGZBM KLKIODP Sample Output 3 34 | 35,562 |
A Garden with Ponds Mr. Gardiner is a modern garden designer who is excellent at utilizing the terrain features. His design method is unique: he first decides the location of ponds and design them with the terrain features intact. According to his unique design procedure, all of his ponds are rectangular with simple aspect ratios. First, Mr. Gardiner draws a regular grid on the map of the garden site so that the land is divided into cells of unit square, and annotates every cell with its elevation. In his design method, a pond occupies a rectangular area consisting of a number of cells. Each of its outermost cells has to be higher than all of its inner cells. For instance, in the following grid map, in which numbers are elevations of cells, a pond can occupy the shaded area, where the outermost cells are shaded darker and the inner cells are shaded lighter. You can easily see that the elevations of the outermost cells are at least three and those of the inner ones are at most two. A rectangular area on which a pond is built must have at least one inner cell. Therefore, both its width and depth are at least three. When you pour water at an inner cell of a pond, the water can be kept in the pond until its level reaches that of the lowest outermost cells. If you continue pouring, the water inevitably spills over. Mr. Gardiner considers the larger capacity the pond has, the better it is. Here, the capacity of a pond is the maximum amount of water it can keep. For instance, when a pond is built on the shaded area in the above map, its capacity is (3 â 1) + (3 â 0) + (3 â 2) = 6, where 3 is the lowest elevation of the outermost cells and 1, 0, 2 are the elevations of the inner cells. Your mission is to write a computer program that, given a grid map describing the elevation of each unit square cell, calculates the largest possible capacity of a pond built in the site. Note that neither of the following rectangular areas can be a pond. In the left one, the cell at the bottom right corner is not higher than the inner cell. In the right one, the central cell is as high as the outermost cells. Input The input consists of at most 100 datasets, each in the following format. d w e 1, 1 ... e 1, w ... e d , 1 ... e d, w The first line contains d and w , representing the depth and the width, respectively, of the garden site described in the map. They are positive integers between 3 and 10, inclusive. Each of the following d lines contains w integers between 0 and 9, inclusive, separated by a space. The x -th integer in the y -th line of the d lines is the elevation of the unit square cell with coordinates ( x, y ). The end of the input is indicated by a line containing two zeros separated by a space. Output For each dataset, output a single line containing the largest possible capacity of a pond that can be built in the garden site described in the dataset. If no ponds can be built, output a single line containing a zero. Sample Input 3 3 2 3 2 2 1 2 2 3 1 3 5 3 3 4 3 3 3 1 0 2 3 3 3 4 3 2 7 7 1 1 1 1 1 0 0 1 0 0 0 1 0 0 1 0 1 1 1 1 1 1 0 1 0 1 0 1 1 1 1 1 1 0 1 0 0 1 0 0 0 1 0 0 1 1 1 1 1 6 6 1 1 1 1 2 2 1 0 0 2 0 2 1 0 0 2 0 2 3 3 3 9 9 9 3 0 0 9 0 9 3 3 3 9 9 9 0 0 Output for the Sample Input 0 3 1 9 | 35,563 |
åé¡å ç®±æ ¹é§
äŒ æ¥æ¬ã®ãæ£æã®é¢šç©è©©ã«ç®±æ ¹é§
äŒããããŸããç®±æ ¹é§
äŒã¯ãåããŒã 10 人ã®èµ°è
ãäžç¶æããšã«è¥·ãã€ãªããªãããŽãŒã«ãç®æããšãããã®ã§ãããã¬ãã®æŸéã§ã¯äžç¶æã§åããŒã ã®ééé äœãšå
±ã«åã®äžç¶æããã®é äœå€åã衚瀺ãããŸããããã§ããããèŠãŠåã®äžç¶æã®åããŒã ã®ééé ãšããŠèãããããã®ãäœéããããçããŠãã ãããããããééé ã®æ°ã¯éåžžã«å€§ãããªãããã®ã§ã1,000,000,007 ã§å²ã£ãäœãã§çããŠäžããã Input å
¥åã¯ä»¥äžã®åœ¢ã§äžããããŸã n c 1 c 2 ... c n 1è¡ç®ã«ã¯ããŒã æ°ãè¡šãæ°å n ( 1 †n †200 ) ããç¶ã n è¡ã«ã¯ 1 äœããé ã«åã®äžç¶æããã®é äœå€å c i (' D ' ãªãé äœãèœã¡ãŠãã' U ' ãªãé äœãäžãã£ãŠãã' - ' ãªãé äœãå€ãã£ãŠãªã) ãæžããŠãããŸãã Output åã®äžç¶æã§ããããééé ãäœéãããã 1,000,000,007 ã§å²ã£ãããŸãã§ 1 è¡ã§åºåããŠäžããã Sample Input 1 3 - U D Output for the Sample Input 1 1 ãã®äžç¶æã 1 äœã 2 äœã 3 äœã§ééããããŒã ã®ããŒã åããããã A, B, C ãšãããšãåã®äžç¶æã®ééé ãšããŠèããããã®ã¯ 1 äœïŒããŒã A, 2 äœïŒããŒã C, 3 äœïŒããŒã B ã® 1 éãã®ã¿ã§ãã Sample Input 2 5 U U - D D Output for the Sample Input 2 5 ãã®äžç¶æã®ééé ã«ããŒã åã A, B, C, D, E ãšãããšãåã®äžç¶æã®ééé ãšããŠèããããã®ã¯ {D, E, C, A, B}, {D, E, C, B, A}, {E, D, C, A, B}, {E, D, C, B, A}, {D, A, C, E, B} ã®5éãã§ãã Sample Input 3 8 U D D D D D D D Output for the Sample Input 3 1 Sample Input 4 10 U D U D U D U D U D Output for the Sample Input 4 608 Sample Input 5 2 D U Output for the Sample Input 5 0 | 35,564 |
Score : 1800 points Problem Statement We have a round pizza. Snuke wants to eat one third of it, or something as close as possible to that. He decides to cut this pizza as follows. First, he divides the pizza into N pieces by making N cuts with a knife. The knife can make a cut along the segment connecting the center of the pizza and some point on the circumference of the pizza. However, he is very poor at handling knives, so the cuts are made at uniformly random angles, independent from each other. Then, he chooses one or more consecutive pieces so that the total is as close as possible to one third of the pizza, and eat them. (Let the total be x of the pizza. He chooses consecutive pieces so that |x - 1/3| is minimized.) Find the expected value of |x - 1/3| . It can be shown that this value is rational, and we ask you to print it modulo 10^9 + 7 , as described in Notes. Notes When you print a rational number, first write it as a fraction \frac{y}{x} , where x, y are integers and x is not divisible by 10^9 + 7 (under the constraints of the problem, such representation is always possible). Then, you need to print the only integer z between 0 and 10^9 + 6 , inclusive, that satisfies xz \equiv y \pmod{10^9 + 7} . Constraints 2 \leq N \leq 10^6 Input Input is given from Standard Input in the following format: N Output Print the expected value of |x - 1/3| modulo 10^9 + 7 , as described in Notes. Sample Input 1 2 Sample Output 1 138888890 The expected value is \frac{5}{36} . Sample Input 2 3 Sample Output 2 179012347 The expected value is \frac{11}{162} . Sample Input 3 10 Sample Output 3 954859137 Sample Input 4 1000000 Sample Output 4 44679646 | 35,565 |
Problem C: Unit Fraction Partition A fraction whose numerator is 1 and whose denominator is a positive integer is called a unit fraction. A representation of a positive rational number p / q as the sum of finitely many unit fractions is called a partition of p / q into unit fractions. For example, 1/2 + 1/6 is a partition of 2/3 into unit fractions. The difference in the order of addition is disregarded. For example, we do not distinguish 1/6 + 1/2 from 1/2 + 1/6. For given four positive integers p , q , a , and n , count the number of partitions of p / q into unit fractions satisfying the following two conditions. The partition is the sum of at most n many unit fractions. The product of the denominators of the unit fractions in the partition is less than or equal to a . For example, if ( p , q , a , n ) = (2,3,120,3), you should report 4 since enumerates all of the valid partitions. Input The input is a sequence of at most 1000 data sets followed by a terminator. A data set is a line containing four positive integers p , q , a , and n satisfying p , q <= 800, a <= 12000 and n <= 7. The integers are separated by a space. The terminator is composed of just one line which contains four zeros separated by a space. It is not a part of the input data but a mark for the end of the input. Output The output should be composed of lines each of which contains a single integer. No other characters should appear in the output. The output integer corresponding to a data set p , q , a , n should be the number of all partitions of p / q into at most n many unit fractions such that the product of the denominators of the unit fractions is less than or equal to a . Sample Input 2 3 120 3 2 3 300 3 2 3 299 3 2 3 12 3 2 3 12000 7 54 795 12000 7 2 3 300 1 2 1 200 5 2 4 54 2 0 0 0 0 Output for the Sample Input 4 7 6 2 42 1 0 9 3 | 35,566 |
Problem K Runner and Sniper You are escaping from an enemy for some reason. The enemy is a sniper equipped with a high-tech laser gun, and you will be immediately defeated if you get shot. You are a very good runner, but just wondering how fast you have to run in order not to be shot by the sniper. The situation is as follows: You and the sniper are on the $xy$-plane whose $x$-axis and $y$-axis are directed to the right and the top, respectively. You can assume that the plane is infinitely large, and that there is no obstacle that blocks the laser or your movement. The sniper and the laser gun are at $(0, 0)$ and cannot move from the initial location. The sniper can continuously rotate the laser gun by at most $\omega$ degrees per unit time, either clockwise or counterclockwise, and can change the direction of rotation at any time. The laser gun is initially directed $\theta$ degrees counterclockwise from the positive direction of the $x$-axis. You are initially at ($x$, $y$) on the plane and can move in any direction at speed not more than $v$ (you can arbitrarily determine the value of $v$ since you are a very good runner). You will be shot by the sniper exactly when the laser gun is directed toward your position, that is, you can ignore the time that the laser reaches you from the laser gun. Assume that your body is a point and the laser is a half-line whose end point is (0, 0). Find the maximum speed $v$ at which you are shot by the sniper in finite time when you and the sniper behave optimally. Input The input consists of a single test case. The input contains four integers in a line, $x$, $y$, $\theta$ and $\omega$. The two integers $x$ and $y$ $(0 \leq |x|, |y| \leq 1,000$, ($x$, $y$) $\ne$ (0, 0)) represent your initial position on the $xy$-plane. The integer $\theta$ $(0 \leq \theta < 360)$ represents the initial direction of the laser gun: it is the counterclockwise angle in degrees from the positive direction of the $x$-axis. The integer $\omega$ $(1 \leq \omega \leq 100)$ is the angle which the laser gun can rotate in unit time. You can assume that you are not shot by the sniper at the initial position. Output Display a line containing the maximum speed $v$ at which you are shot by the sniper in finite time. The absolute error or the relative error should be less than $10^{-6}$. Sample Input 1 100 100 0 1 Output for the Sample Input 1 1.16699564 | 35,567 |
æçåŒæå€§å N åã®ç°ãªãèªç¶æ°ãäžããããããã®äžããç°ãªãïŒã€ãéžãã§ããããã $A$, $B$, $C$, $D$ ãšãããšããæ¬¡ã®æ°åŒ $\frac{A + B}{C - D}$ ã®æå€§å€ãæ±ãããã N åã®ç°ãªãèªç¶æ°ãäžãããããšãããã®äžããç°ãªãïŒã€ãéžãã§ãäžã®æ°åŒã®æå€§å€ãæ±ããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N a 1 a 2 ... a N ïŒè¡ç®ã«èªç¶æ°ã®åæ° N (4 †N †1000) ãäžãããããïŒè¡ç®ã«åèªç¶æ°ã®å€ a i (1 †a i †10 8 ) ãäžããããããã ããåãèªç¶æ°ãéè€ããŠçŸããããšã¯ãªãïŒ i â j ã«ã€ã㊠a i â a j )ã Output äžãããã N åã®èªç¶æ°ã«å¯ŸããŠãäžã®æ°åŒã®æå€§å€ã宿°ã§åºåããããã ãã誀差ããã©ã¹ãã€ãã¹ 10 -5 ãè¶
ããŠã¯ãªããªãã Sample Input 1 10 1 2 3 4 5 6 7 8 9 10 Sample Output 1 19.00000 å
¥åäŸïŒã§ã¯ã$A=9$, $B=10$, $C=2$, $D=1$ ãªã©ã®çµã¿åããã§æå€§ã«ãªãã Sample Input 2 5 22 100 42 3 86 Sample Output 2 9.78947 å
¥åäŸïŒã§ã¯ã$A=100$, $B=86$, $C=22$, $D=3$ ãªã©ã®çµã¿åããã§æå€§ã«ãªãã Sample Input 3 6 15 21 36 10 34 5 Sample Output 3 18.00000 å
¥åäŸïŒã§ã¯ã$A=21$, $B=15$, $C=36$, $D=34$ ãªã©ã®çµã¿åããã§æå€§ã«ãªãã Sample Input 4 4 100000 99999 8 1 Sample Output 4 28571.285714 | 35,568 |
Score : 500 points Problem Statement There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: For each block, use one of the M colors, Color 1 through Color M , to paint it. It is not mandatory to use all the colors. There may be at most K pairs of adjacent blocks that are painted in the same color. Since the count may be enormous, print it modulo 998244353 . Constraints All values in input are integers. 1 \leq N, M \leq 2 \times 10^5 0 \leq K \leq N - 1 Input Input is given from Standard Input in the following format: N M K Output Print the answer. Sample Input 1 3 2 1 Sample Output 1 6 The following ways to paint the blocks satisfy the conditions: 112 , 121 , 122 , 211 , 212 , and 221 . Here, digits represent the colors of the blocks. Sample Input 2 100 100 0 Sample Output 2 73074801 Sample Input 3 60522 114575 7559 Sample Output 3 479519525 | 35,569 |
Score : 100 points Problem Statement You are given a trapezoid. The lengths of its upper base, lower base, and height are a , b , and h , respectively. An example of a trapezoid Find the area of this trapezoid. Constraints 1âŠaâŠ100 1âŠbâŠ100 1âŠhâŠ100 All input values are integers. h is even. Input The input is given from Standard Input in the following format: a b h Output Print the area of the given trapezoid. It is guaranteed that the area is an integer. Sample Input 1 3 4 2 Sample Output 1 7 When the lengths of the upper base, lower base, and height are 3 , 4 , and 2 , respectively, the area of the trapezoid is (3+4)Ã2/2 = 7 . Sample Input 2 4 4 4 Sample Output 2 16 In this case, a parallelogram is given, which is also a trapezoid. | 35,570 |
éçå€§äŒ éçã®åœå¥å¯ŸææŠ WBC ã§ãæ¥æ¬ã2é£èŠéæ!! éç人æ°ãé«ãŸãäžãäŒæŽ¥åŠå髿 ¡ãäŒå Žã«éç倧äŒãè¡ãããŸããããã®å€§äŒã§ã¯ãç·åœãã®ãªãŒã°æŠãè¡ãã以äžã®ãããªæ¹æ³ã§é äœã決ããããšã«ãªããŸããã åã¡æ°ã®å€ãããŒã ãäžäœãšãã åã¡æ°ãåæ°ã®å Žåã¯è² ãæ°ã®å°ãªãããŒã ãäžäœãšãã åããŒã ã®æçžŸãå
¥åãšããããŒã åãäžäœã®ããŒã ããé ã«åºåããããã°ã©ã ãäœæããŠãã ãããåé äœã®ããŒã ãååšããå Žåã¯ãå
¥åé ã«åºåããŠãã ããããã ããããŒã æ° n 㯠2 ä»¥äž 10 以äžã®æŽæ°ãããŒã å t 㯠1 æåã®åè§è±åãè©Šåæ¯ã®æçžŸ r 㯠n - 1 åã®æ°åã§è¡šãããåã¡ã®å Žå㯠0 ãè² ãã®å Žå㯠1 ãåŒãåãã®å Žå㯠2 ãšããŸãããŸããããŒã åã«éè€ã¯ãªããã®ãšããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n score 1 score 2 : score n 1 è¡ç®ã«ããŒã ã®æ° n (2 †n †10) ãç¶ã n è¡ã«ç¬¬ i ã®ããŒã ã®æçžŸ score i ãäžããããŸããåæçžŸã¯æ¬¡ã®åœ¢åŒã§äžããããŸãã t r 1 r 2 ... r nâ1 ããŒã å t (ïŒæåã®åè§è±å)ã t ã®è©Šåæ¯ã®æçžŸ r i (0, 1, ãŸã㯠2) ã空çœåºåãã§äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«ãããŒã åãäžäœã®ããŒã ããé ã«åºåããŸãã Sample Input 6 A 1 0 0 2 0 B 0 0 1 1 0 C 1 1 1 1 1 D 1 0 0 1 2 E 2 0 0 0 0 F 1 1 0 2 1 4 g 1 1 1 h 0 1 2 w 0 0 0 b 0 2 1 0 Output for the Sample Input E A B D F C w h b g | 35,571 |
Binary Search For a given sequence $A = \{a_0, a_1, ..., a_{n-1}\}$ which is sorted by ascending order, find a specific value $k$ given as a query. Input The input is given in the following format. $n$ $a_0 \; a_1 \; ,..., \; a_{n-1}$ $q$ $k_1$ $k_2$ : $k_q$ The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $k_i$ are given as queries. Output For each query, print 1 if any element in $A$ is equivalent to $k$, and 0 otherwise. Constraints $1 \leq n \leq 100,000$ $1 \leq q \leq 200,000$ $0 \leq a_0 \leq a_1 \leq ... \leq a_{n-1} \leq 1,000,000,000$ $0 \leq k_i \leq 1,000,000,000$ Sample Input 1 4 1 2 2 4 3 2 3 5 Sample Output 1 1 0 0 | 35,572 |
F: Swap åé¡ é·ã $N$ ã®æåå $S,\ T$ ãäžããããŸãïŒ$S,\ T$ ã¯ãããã 'o' , '.' ã®äºçš®é¡ã®æåã ãã§æ§æãããŠããŸãïŒ ããªã㯠$S$ ã«å¯ŸããŠïŒä»¥äžã®æäœãè¡ãããšãã§ããŸãïŒ ä»¥äžã®æ¡ä»¶ãå
šãŠæºããæŽæ°å¯Ÿ $(l, r)$ ãéžæããïŒãã®åŸïŒ$S[l]$ ãš $S[l + 1]ïŒS[r - 1]$ ãš $S[r]$ ãããããã¹ã¯ããããïŒ $1 \leq l, r \leq N$ $r - l \geq 3$ $S[l] = S[r] =$ '.' $S[l + 1] = S[l + 2] = \dots = S[r - 1] =$ 'o' äœåãæäœãç¹°ãè¿ããããš(0åã§ãå¯)ïŒæåå S ã T ã«å€åœ¢ããããšãå¯èœãå€å®ããŠãã ããïŒ å¶çŽ $1 \leq N \leq 100000$ $|S| = |T| = N \ \ \ \ \ \ \ |S|$ , $|T|$ ã¯æååã®é·ã $S$ , $T$ 㯠'o', '.' ã®äºçš®é¡ã®æåããã®ã¿æ§æãããã å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $S$ $T$ åºå æäœãäœåãé©çšåŸ( $0$ åã§ãå¯)ïŒ $S$ ã $T$ ã«å€åœ¢ããããšãå¯èœãªãã° YesïŒã©ã®ããã«æäœããŠãäžå¯èœãªãã° No ãåºåããŠãã ããïŒãŸããæ«å°Ÿã«æ¹è¡ãåºåããŠãã ããïŒ ãµã³ãã« ãµã³ãã«å
¥å 1 8 .oo.ooo. o.o.oo.o ãµã³ãã«åºå 1 Yes 以äžã®æé ã§æäœãè¡ãããšã§éæã§ããŸãïŒ $S$ = ".oo.ooo." : $(l, r) = (1, 4)$ ãéžæããïŒ $S$ = "o..oooo." : $(l, r) = (4, 9)$ ãéžæããïŒ $S$ = "o.o.oo.o" : $T$ ãšäžèŽãïŒç®çãéæïŒ ãµã³ãã«å
¥å 2 7 .ooooo. oo.o.oo ãµã³ãã«åºå 2 Yes 以äžã®æé ã§æäœãè¡ãããšã§éæã§ããŸãïŒ $S$ = ".ooooo." : $(l, r) = (1, 7)$ ãéžæããïŒ $S$ = "o.ooo.o" : $(l, r) = (2, 6)$ ãéžæããïŒ $S$ = "oo.o.oo" : $T$ ãšäžèŽãïŒç®çãéæïŒ ãµã³ãã«å
¥å 3 6 o.o.o. ooo... ãµã³ãã«åºå 3 No æäœãé©çšã§ãã $(l, r)$ ãååšããªãããïŒ$S$ ãå€åœ¢ã㊠$T$ ã«ããããšãã§ããŸããïŒ ãµã³ãã«å
¥å 4 9 .oo.oooo. .oo.oooo. ãµã³ãã«åºå 4 Yes $1$ åãå€åœ¢ãããã«ç®çãéæã§ããŸã ãµã³ãã«å
¥å 5 11 .oooo.oooo. oo.oo.oo.oo ãµã³ãã«åºå 5 Yes | 35,573 |
Problem B: The Sorcerer's Donut Your master went to the town for a day. You could have a relaxed day without hearing his scolding. But he ordered you to make donuts dough by the evening. Loving donuts so much, he can't live without eating tens of donuts everyday. What a chore for such a beautiful day. But last week, you overheard a magic spell that your master was using. It was the time to try. You casted the spell on a broomstick sitting on a corner of the kitchen. With a flash of lights, the broom sprouted two arms and two legs, and became alive. You ordered him, then he brought flour from the storage, and started kneading dough. The spell worked, and how fast he kneaded it! A few minutes later, there was a tall pile of dough on the kitchen table. That was enough for the next week. \OK, stop now." You ordered. But he didn't stop. Help! You didn't know the spell to stop him! Soon the kitchen table was filled with hundreds of pieces of dough, and he still worked as fast as he could. If you could not stop him now, you would be choked in the kitchen filled with pieces of dough. Wait, didn't your master write his spells on his notebooks? You went to his den, and found the notebook that recorded the spell of cessation. But it was not the end of the story. The spell written in the notebook is not easily read by others. He used a plastic model of a donut as a notebook for recording the spell. He split the surface of the donut-shaped model into square mesh (Figure B.1), and filled with the letters (Figure B.2). He hid the spell so carefully that the pattern on the surface looked meaningless. But you knew that he wrote the pattern so that the spell "appears" more than once (see the next paragraph for the precise conditions). The spell was not necessarily written in the left-to-right direction, but any of the 8 directions, namely left-to-right, right-to-left, top-down, bottom-up, and the 4 diagonal directions. You should be able to find the spell as the longest string that appears more than once. Here, a string is considered to appear more than once if there are square sequences having the string on the donut that satisfy the following conditions. Each square sequence does not overlap itself. (Two square sequences can share some squares.) The square sequences start from different squares, and/or go to different directions. Figure B.1: The Sorcerer's Donut Before Filled with Letters, Showing the Mesh and 8 Possible Spell Directions Figure B.2: The Sorcerer's Donut After Filled with Letters Note that a palindrome (i.e., a string that is the same whether you read it backwards or forwards) that satisfies the first condition "appears" twice. The pattern on the donut is given as a matrix of letters as follows. ABCD EFGH IJKL Note that the surface of the donut has no ends; the top and bottom sides, and the left and right sides of the pattern are respectively connected. There can be square sequences longer than both the vertical and horizontal lengths of the pattern. For example, from the letter F in the above pattern, the strings in the longest non-self-overlapping sequences towards the 8 directions are as follows. FGHE FKDEJCHIBGLA FJB FIDGJAHKBELC FEHG FALGBIHCJEDK FBJ FCLEBKHAJGDI Please write a program that finds the magic spell before you will be choked with pieces of donuts dough. Input The input is a sequence of datasets. Each dataset begins with a line of two integers h and w , which denote the size of the pattern, followed by h lines of w uppercase letters from A to Z, inclusive, which denote the pattern on the donut. You may assume 3 †h †10 and 3 †w †20. The end of the input is indicated by a line containing two zeros. Output For each dataset, output the magic spell. If there is more than one longest string of the same length, the first one in the dictionary order must be the spell. The spell is known to be at least two letters long. When no spell is found, output 0 (zero). Sample Input 5 7 RRCABXT AABMFAB RROMJAC APTADAB YABADAO 3 13 ABCDEFGHIJKLM XMADAMIMADAMY ACEGIKMOQSUWY 3 4 DEFG ACAB HIJK 3 6 ABCDEF GHIAKL MNOPQR 10 19 JFZODYDXMZZPEYTRNCW XVGHPOKEYNZTQFZJKOD EYEHHQKHFZOVNRGOOLP QFZOIHRQMGHPNISHXOC DRGILJHSQEHHQLYTILL NCSHQMKHTZZIHRPAUJA NCCTINCLAUTFJHSZBVK LPBAUJIUMBVQYKHTZCW XMYHBVKUGNCWTLLAUID EYNDCCWLEOODXYUMBVN 0 0 Output for the Sample Input ABRACADABRA MADAMIMADAM ABAC 0 ABCDEFGHIJKLMNOPQRSTUVWXYZHHHHHABCDEFGHIJKLMNOPQRSTUVWXYZ | 35,574 |
H - RLE Replacement Problem Statement In JAG Kingdom, ICPC (Intentionally Compressible Programming Code) is one of the common programming languages. Programs in this language only contain uppercase English letters and the same letters often appear repeatedly in ICPC programs. Thus, programmers in JAG Kingdom prefer to compress ICPC programs by Run Length Encoding in order to manage very large-scale ICPC programs. Run Length Encoding (RLE) is a string compression method such that each maximal sequence of the same letters is encoded by a pair of the letter and the length. For example, the string "RRRRLEEE" is represented as "R4L1E3" in RLE. Now, you manage many ICPC programs encoded by RLE. You are developing an editor for ICPC programs encoded by RLE, and now you would like to implement a replacement function. Given three strings $A$, $B$, and $C$ that are encoded by RLE, your task is to implement a function replacing the first occurrence of the substring $B$ in $A$ with $C$, and outputting the edited string encoded by RLE. If $B$ does not occur in $A$, you must output $A$ encoded by RLE without changes. Input The input consists of three lines. $A$ $B$ $C$ The lines represent strings $A$, $B$, and $C$ that are encoded by RLE, respectively. Each of the lines has the following format: $c_1$ $l_1$ $c_2$ $l_2$ $\ldots$ $c_n$ $l_n$ \$ Each $c_i$ ($1 \leq i \leq n$) is an uppercase English letter ( A - Z ) and $l_i$ ($1 \leq i \leq n$, $1 \leq l_i \leq 10^8$) is an integer which represents the length of the repetition of $c_i$. The number $n$ of the pairs of a letter and an integer satisfies $1 \leq n \leq 10^3$. A terminal symbol $ indicates the end of a string encoded by RLE. The letters and the integers are separated by a single space. It is guaranteed that $c_i \neq c_{i+1}$ holds for any $1 \leq i \leq n-1$. Output Replace the first occurrence of the substring $B$ in $A$ with $C$ if $B$ occurs in $A$, and output the string encoded by RLE. The output must have the following format: $c_1$ $l_1$ $c_2$ $l_2$ $\ldots$ $c_m$ $l_m$ \$ Here, $c_i \neq c_{i+1}$ for $1 \leq i \leq m-1$ and $l_i \gt 0$ for $1 \leq i \leq m$ must hold. Sample Input 1 R 100 L 20 E 10 \$ R 5 L 10 \$ X 20 \$ Output for the Sample Input 1 R 95 X 20 L 10 E 10 \$ Sample Input 2 A 3 B 3 A 3 \$ A 1 B 3 A 1 \$ A 2 \$ Output for the Sample Input 2 A 6 \$ | 35,575 |
Score: 300 points Problem Statement In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc. The pyramid had center coordinates (C_X, C_Y) and height H . The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0) . Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information: C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1 . Additionally, he obtained N pieces of information. The i -th of them is: "the altitude of point (x_i, y_i) is h_i ." This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above. Constraints N is an integer between 1 and 100 (inclusive). x_i and y_i are integers between 0 and 100 (inclusive). h_i is an integer between 0 and 10^9 (inclusive). The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different. The center coordinates and the height of the pyramid can be uniquely identified. Input Input is given from Standard Input in the following format: N x_1 y_1 h_1 x_2 y_2 h_2 x_3 y_3 h_3 : x_N y_N h_N Output Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between. Sample Input 1 4 2 3 5 2 1 5 1 2 5 3 2 5 Sample Output 1 2 2 6 In this case, the center coordinates and the height can be identified as (2, 2) and 6 . Sample Input 2 2 0 0 100 1 1 98 Sample Output 2 0 0 100 In this case, the center coordinates and the height can be identified as (0, 0) and 100 . Note that C_X and C_Y are known to be integers between 0 and 100 . Sample Input 3 3 99 1 191 100 1 192 99 0 192 Sample Output 3 100 0 193 In this case, the center coordinates and the height can be identified as (100, 0) and 193 . | 35,576 |
Score : 600 points Problem Statement Given is a directed graph G with N vertices and M edges. The vertices are numbered 1 to N , and the i -th edge is directed from Vertex A_i to Vertex B_i . It is guaranteed that the graph contains no self-loops or multiple edges. Determine whether there exists an induced subgraph (see Notes) of G such that the in-degree and out-degree of every vertex are both 1 . If the answer is yes, show one such subgraph. Here the null graph is not considered as a subgraph. Notes For a directed graph G = (V, E) , we call a directed graph G' = (V', E') satisfying the following conditions an induced subgraph of G : V' is a (non-empty) subset of V . E' is the set of all the edges in E that have both endpoints in V' . Constraints 1 \leq N \leq 1000 0 \leq M \leq 2000 1 \leq A_i,B_i \leq N A_i \neq B_i All pairs (A_i, B_i) are distinct. All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 : A_M B_M Output If there is no induced subgraph of G that satisfies the condition, print -1 . Otherwise, print an induced subgraph of G that satisfies the condition, in the following format: K v_1 v_2 : v_K This represents the induced subgraph of G with K vertices whose vertex set is \{v_1, v_2, \ldots, v_K\} . (The order of v_1, v_2, \ldots, v_K does not matter.) If there are multiple subgraphs of G that satisfy the condition, printing any of them is accepted. Sample Input 1 4 5 1 2 2 3 2 4 4 1 4 3 Sample Output 1 3 1 2 4 The induced subgraph of G whose vertex set is \{1, 2, 4\} has the edge set \{(1, 2), (2, 4), (4, 1)\} . The in-degree and out-degree of every vertex in this graph are both 1 . Sample Input 2 4 5 1 2 2 3 2 4 1 4 4 3 Sample Output 2 -1 There is no induced subgraph of G that satisfies the condition. Sample Input 3 6 9 1 2 2 3 3 4 4 5 5 6 5 1 5 2 6 1 6 2 Sample Output 3 4 2 3 4 5 | 35,577 |
Score : 200 points Problem Statement You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1 . Constraints Each character in s is a lowercase English letter. 1â€|s|â€10^5 Input The input is given from Standard Input in the following format: s Output Print the string obtained by concatenating all the characters in the odd-numbered positions. Sample Input 1 atcoder Sample Output 1 acdr Extract the first character a , the third character c , the fifth character d and the seventh character r to obtain acdr . Sample Input 2 aaaa Sample Output 2 aa Sample Input 3 z Sample Output 3 z Sample Input 4 fukuokayamaguchi Sample Output 4 fkoaaauh | 35,578 |
Problem F: KULASIS Description KULASISãšã¯ïŒå
šåŠå
±éç§ç®ã«é¢ããæ
å ±ãWebåãïŒåŠçã»æå¡ãžã®æ¯æŽããµãŒãã¹ã®åäžãç®çã«ïŒé«çæè²ç ç©¶éçºæšé²æ©æ§ã§éçºã»éçšããŠããã·ã¹ãã ã®åç§°ã§ãã KULASISã¯2003幎床ã®ãªã³ã©ã€ã³ã·ã©ãã¹éçºããå§ãŸãïŒWebæ²ç€ºæ¿ã»å±¥ä¿®ç»é²ã»æçžŸé¢ä¿ïŒæ¡ç¹ç»é²ã»åŠçããã®æ¡ç¹ç¢ºèªïŒãšé 次ã·ã¹ãã ãæ¡å
ããŠããŸããã åŠçã¯ããœã³ã³ã»æºåž¯é»è©±ããåŠå
å€ãåããïŒæåæ
å ±ïŒäŒè¬ã»ææ¥å€æŽã»ã¬ããŒãïŒã®ç¢ºèªã»å±¥ä¿®ç»é²ã»æ¡ç¹ç¢ºèªçã®æ©èœãå©çšããããšãã§ããŸãããã°ã€ã³ä»¶æ°ã¯å€ãæ¥ã«ã¯10,000ä»¶ãè¶
ãïŒäº¬éœå€§åŠã®æåæ
å ±ã·ã¹ãã ãšããŠæµžéãïŒå
šåŠå
±éç§ç®ã履修ããããã«ã¯æ¬ ãããªããã®ãšãªã£ãŠããŸãããã®KULASISãå
šåŠå
±éç§ç®ã®ã¿ã«ãšã©ãŸããïŒåŠéšå°é課çšã倧åŠé¢ã«ãé©çšã§ãããã éçºãé²ããŠããŸãã http://www.z.k.kyoto-u.ac.jp/introduction_kulasis.html 京倧çã®Qã¯åŸæã®ã·ã©ãã¹ãçµãããã«KULASISã«ãã°ã€ã³ããŠããïŒ ã©ã®ç§ç®ãå
¥ããããšããŠãããæ©ãã§ãããšïŒçªç¶KULASISãç©ãå
ãæŸã¡ïŒå¥ã®ããŒãžãžãšé·ç§»ããïŒ é·ç§»ããå
ã®ããŒãžã¯äžå³ã®ãããªãã®ã§ãã£ãïŒ5x5ã®ãã¹ã«ã¯ç§ç®åãšè©äŸ¡(äžå¯ïŒå¯ïŒè¯ïŒåª)ãæžãããŠããïŒæ Œåäžã«ã¯ â ã®ãã¿ã³ã16åé
眮ãããŠããïŒ ãã£ãããªã«ãèµ·ããã®ãåãããªãã£ãQã ã£ããïŒã©ãããæ Œåäžã«ãã â ã®ãã¿ã³ãæŒããšïŒãã®å³äžïŒå³äžïŒå·ŠäžïŒå·Šäžã«ãããã¹ã®ç§ç®ã®è©äŸ¡ããããã äžå¯âå¯ïŒå¯âè¯ïŒè¯âåªïŒåªâäžå¯ ãšå
¥ãæ¿ããããã§ãã£ãïŒ â ã®ãã¿ã³ã¯äœåºŠã§ãæŒãããšãã§ããïŒ KULASISãäœè
ãã«ãã£ãŠæžãæããããŠããŸã£ãã®ãèªåã倢ãèŠãŠããã®ãããåãããªããïŒããã§æçžŸã確å®ã§ãããªãã°ïŒåºæ¥ãã ãè¯ãæçžŸãåŸãããšQã¯èããïŒ åäœãå€ãéããŠããããšã«èªä¿¡ããã£ãQã¯ïŒåäœã®æ°ãã®ãã®ãããå幎åŸã®ç 究宀é
å±ã«åã㊠æŠéå ãæå€§ã«ãããããšã«ããïŒ æŠéå ãšã¯åç§ç®ã®è©äŸ¡ãïŒäžå¯â0ç¹ïŒå¯â60ç¹ïŒè¯â70ç¹ïŒåªâ80ç¹ãšæç®ããŠåèšããå€ã®ããšã§ïŒããã¯ç 究宀é
å±ã®éã«èªåãã©ã®çšåºŠåªäœãªã®ãã衚ããš(Qã®åŠç§ã§ã¯)æãããŠããïŒ ããŸïŒKULASISã®ç»é¢ã®è¡šç€ºãããŠããç§ç®ãšãã®è©äŸ¡ãäžããããã®ã§ïŒåŸãããšãåºæ¥ã æŠéå ã®æå€§å€ãåºåããããã°ã©ã ãèšããŠã»ããïŒ Input å
¥åã®1è¡ç®ã«ã¯ãã¹ãã±ãŒã¹ã®åæ°ãäžããããïŒãã¹ãã±ãŒã¹ã®æ°ã¯100å以äžã§ããããšãä¿éãããŠããïŒ 2è¡ç®ä»¥éã¯5x5ã®æ°åã䞊ã³ïŒKULASISã®ç»é¢ã«è¡šç€ºãããŠããç§ç®ã®è©äŸ¡ãäžãããïŒ1,2,3,4ãããããäžå¯ïŒå¯ïŒè¯ïŒåªã«å¯Ÿå¿ããïŒ 0ãªãã°ãã®ã³ãã«ã¯ç§ç®ã¯ç»é²ãããŠããªãïŒ ãã¹ãã±ãŒã¹å士ã®éã¯ç©ºè¡ã§åºåãããŠããïŒ Output åãã¹ãã±ãŒã¹ã«å¯ŸãïŒåŸãããšã®åºæ¥ã æŠéå ã®æå€§å€ãåºåããïŒ Sample Input 5 1 1 0 3 3 1 1 0 3 3 0 0 0 0 0 2 2 0 4 4 2 2 0 4 4 1 1 1 0 0 1 1 1 1 0 1 0 1 1 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 3 4 2 2 2 2 2 0 0 0 2 0 2 2 0 2 0 2 2 0 2 0 0 0 0 2 0 Output for Sample Input 1280 1420 0 1920 1020 | 35,579 |
Score : 400 points Problem Statement Kenkoooo is planning a trip in Republic of Snuke. In this country, there are n cities and m trains running. The cities are numbered 1 through n , and the i -th train connects City u_i and v_i bidirectionally. Any city can be reached from any city by changing trains. Two currencies are used in the country: yen and snuuk. Any train fare can be paid by both yen and snuuk. The fare of the i -th train is a_i yen if paid in yen, and b_i snuuk if paid in snuuk. In a city with a money exchange office, you can change 1 yen into 1 snuuk. However, when you do a money exchange, you have to change all your yen into snuuk. That is, if Kenkoooo does a money exchange when he has X yen, he will then have X snuuk. Currently, there is a money exchange office in every city, but the office in City i will shut down in i years and can never be used in and after that year. Kenkoooo is planning to depart City s with 10^{15} yen in his pocket and head for City t , and change his yen into snuuk in some city while traveling. It is acceptable to do the exchange in City s or City t . Kenkoooo would like to have as much snuuk as possible when he reaches City t by making the optimal choices for the route to travel and the city to do the exchange. For each i=0,...,n-1 , find the maximum amount of snuuk that Kenkoooo has when he reaches City t if he goes on a trip from City s to City t after i years. You can assume that the trip finishes within the year. Constraints 2 \leq n \leq 10^5 1 \leq m \leq 10^5 1 \leq s,t \leq n s \neq t 1 \leq u_i < v_i \leq n 1 \leq a_i,b_i \leq 10^9 If i\neq j , then u_i \neq u_j or v_i \neq v_j . Any city can be reached from any city by changing trains. All values in input are integers. Input Input is given from Standard Input in the following format: n m s t u_1 v_1 a_1 b_1 : u_m v_m a_m b_m Output Print n lines. In the i -th line, print the maximum amount of snuuk that Kenkoooo has when he reaches City t if he goes on a trip from City s to City t after i-1 years. Sample Input 1 4 3 2 3 1 4 1 100 1 2 1 10 1 3 20 1 Sample Output 1 999999999999998 999999999999989 999999999999979 999999999999897 After 0 years, it is optimal to do the exchange in City 1 . After 1 years, it is optimal to do the exchange in City 2 . Note that City 1 can still be visited even after the exchange office is closed. Also note that, if it was allowed to keep 1 yen when do the exchange in City 2 and change the remaining yen into snuuk, we could reach City 3 with 999999999999998 snuuk, but this is NOT allowed. After 2 years, it is optimal to do the exchange in City 3 . After 3 years, it is optimal to do the exchange in City 4 . Note that the same train can be used multiple times. Sample Input 2 8 12 3 8 2 8 685087149 857180777 6 7 298270585 209942236 2 4 346080035 234079976 2 5 131857300 22507157 4 8 30723332 173476334 2 6 480845267 448565596 1 4 181424400 548830121 4 5 57429995 195056405 7 8 160277628 479932440 1 6 475692952 203530153 3 5 336869679 160714712 2 7 389775999 199123879 Sample Output 2 999999574976994 999999574976994 999999574976994 999999574976994 999999574976994 999999574976994 999999574976994 999999574976994 | 35,580 |
Score : 100 points Problem Statement Given is a string S representing the day of the week today. S is SUN , MON , TUE , WED , THU , FRI , or SAT , for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively. After how many days is the next Sunday (tomorrow or later)? Constraints S is SUN , MON , TUE , WED , THU , FRI , or SAT . Input Input is given from Standard Input in the following format: S Output Print the number of days before the next Sunday. Sample Input 1 SAT Sample Output 1 1 It is Saturday today, and tomorrow will be Sunday. Sample Input 2 SUN Sample Output 2 7 It is Sunday today, and seven days later, it will be Sunday again. | 35,581 |
C : Shopping / è²·ãç© å顿 æçãåŸæãª2Dåã¯æŒãã¯ããäœãããšããŠãããæçã«ã¯ N åã®ææ a_{0}, a_{1}, ⊠, a_{Nâ1} ãå
šãŠãå¿
èŠã§ããã ããŠãä»2Dåã®å®¶ã®å·èµåº«ã«ã¯äžã€ãææãå
¥ã£ãŠããªãã®ã§ãã¹ãŒããŒã«è²·ãã«è¡ããªããã°ãªããªããã¹ãŒããŒã§ã¯ææ a_{i} ã倿®µ x_{i} åã§è²·ãããšãã§ããã 2Dåã¯éæ³äœ¿ãã§ãããã M çš®é¡ã®éæ³ã䜿ããã i çªç®ã®éæ³ãææ s_{i} ã«ãããã°ææ t_{i} ã«ããŸãéã« t_{i} ã«ãããã° s_{i} ã«å€ããããšãã§ãããããã«ãäžã€ã®ææã«å¯ŸããŠè€æ°ã®éæ³ãç¹°ãè¿ããŠäœ¿ãããšãã§ãããäŸãã°ã p ãã q ã«å€ããéæ³ãšã q ãã r ã«å€ããéæ³ã®2ã€ã䜿ã£ãŠã p ãã r ãåŸãããšãã§ããã 2Dåã¯éæ³ã®åãåããŠãªãã¹ãå®ãææãæããããšã«ãããæçã宿ãããããã«2Dåãè²·ãå¿
èŠã®ããææã®ã倿®µã®ç·åã®æå°å€ãæ±ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N a_{0} x_{0} ⊠a_{Nâ1} x_{Nâ1} M s_{0} t_{0} ⊠s_{Mâ1} t_{Mâ1} å¶çŽ æ°å€ã¯ãã¹ãп޿°ã§ãã ææã®ååã¯ãã¹ãŠ 1 æåä»¥äž 10 æå以äžã®ã¢ã«ãã¡ãããå°æåãããªã i â j ãªã a_{i} â a_{j} 1 \†x_{i} \†1,000 1 \†N \†5,000 0 \†M \†{\rm min}(N(Nâ1) / 2, 1000) s_{i} â t_{i} s_{i},t_{i} ã®çµã«éè€ã¯ãªã s_{i},t_{i} 㯠a_{0},âŠ,a_{Nâ1} ã«å«ãŸãã åºå çãã1è¡ã§åºåããã ãµã³ãã« ãµã³ãã«å
¥å1 2 tako 2 yaki 1 1 tako yaki éæ³ã«ãã£ãŠå®ã yaki ã tako ã«å€ããããšãã§ããã®ã§ã yaki ã 2 åè²·ãã°ããã ãµã³ãã«åºå1 2 ãµã³ãã«å
¥å2 5 a 1 b 2 c 2 d 4 e 3 5 b a a c c d e b c b ãµã³ãã«åºå2 5 äžã«ç€ºãããã«ãå
šãŠã®ææã a ããå€ããŠããããããšãã§ããã a : a ãã®ãŸãŸ b : a -> c -> b c : a -> c d : a -> c -> d e : a -> b -> e | 35,582 |
Max Score: 1000 Points Problem Statement There is a railroad company in Atcoder Kingdom, "Atcoder Railroad". There are N + 1 stations numbered 0, 1, 2, ..., N along a railway. Currently, two kinds of train are operated, local and express. A local train stops at every station, and it takes one minute from station i to i + 1 , and vice versa. An express train only stops at station S_0, S_1, S_2, ..., S_{K-1} (0 = S_0 < S_1 < S_2 < ... < S_{K-1} = N) . It takes one minute from station S_i to S_{i + 1} , and vice versa. But the president of Atcoder Railroad, Semiexp said it is not very convenient so he planned to operate one more kind of train, "semi-express". The stations where the semi-express stops (This is T_0, T_1, T_2, ..., T_{L-1} , 0 = T_0 < T_1 < T_2 < ... < T_{L-1} = N ) have to follow following conditions: From station T_i to T_{i+1} takes 1 minutes, and vice versa. The center of Atcoder Kingdom is station 0 , and you have to be able to go to station i atmost X minutes. If the express stops at the station, semi-express should stops at the station. Print the number of ways of the set of the station where semi-express stops (sequence T ). Since the answer can be large, print the number modulo 10^9 + 7 . Input Format N K X S_0 S_1 S_2 ... S_{K-1} Output Format Print the number of ways of the set of the station where semi-express stops, mod 10^9 + 7 in one line. Print \n (line break) in the end. Constraints 2 †K †2500 . 1 †X †2500 . S_0 = 0, S_{K-1} = N . 1 †S_{i + 1} - S_i †10000 . Scoring Subtask 1 [ 120 points] N, K, X †15 . Subtask 2 [ 90 points] K, X †15 . S_{i + 1} - S_i †15 . Subtask 3 [ 260 points] K, X †40 . S_{i + 1} - S_i †40 . Subtask 4 [ 160 points] K, X †300 . S_{i + 1} - S_i †300 . Subtask 5 [ 370 points] There are no additional constraints. Sample Input 1 7 2 3 0 7 Sample Output 1 55 The set of trains that stops station 0 and 7 , and can't satisfy the condition is: [0, 7], [0, 1, 7], [0, 1, 2, 7], [0, 1, 6, 7], [0, 1, 2, 6, 7], [0, 1, 2, 3, 6, 7], [0, 1, 2, 5, 6, 7], [0, 1, 2, 3, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7] , 9 ways. Therefore, the number of ways is 2^6 - 9 = 55 . | 35,583 |
Problem J: Secret Operation Mary Ice is a member of a spy group. She is about to carry out a secret operation with her colleague. She has got into a target place just now, but unfortunately the colleague has not reached there yet. She needs to hide from her enemy George Water until the colleague comes. Mary may want to make herself appear in Georgeâs sight as short as possible, so she will give less chance for George to find her. You are requested to write a program that calculates the time Mary is in Georgeâs sight before her colleague arrives, given the information about moves of Mary and George as well as obstacles blocking their sight. Read the Input section for the details of the situation. Input The input consists of multiple datasets. Each dataset has the following format: Time R L MaryX 1 MaryY 1 MaryT 1 MaryX 2 MaryY 2 MaryT 2 ... MaryX L MaryY L MaryT L M GeorgeX 1 GeorgeY 1 GeorgeT 1 GeorgeX 2 GeorgeY 2 GeorgeT 2 ... GeorgeX M GeorgeY M GeorgeT M N BlockSX 1 BlockSY 1 BlockTX 1 BlockTY 1 BlockSX 2 BlockSY 2 BlockTX 2 BlockTY 2 ... BlockSX N BlockSY N BlockTX N BlockTY N The first line contains two integers. Time (0 †Time †100) is the time Mary's colleague reaches the place. R (0 < R < 30000) is the distance George can see - he has a sight of this distance and of 45 degrees left and right from the direction he is moving. In other words, Mary is found by him if and only if she is within this distance from him and in the direction different by not greater than 45 degrees from his moving direction and there is no obstacles between them. The description of Mary's move follows. Mary moves from ( MaryX i , MaryY i ) to ( MaryX i +1 , MaryY i +1 ) straight and at a constant speed during the time between MaryT i and MaryT i +1 , for each 1 †i †L - 1. The following constraints apply: 2 †L †20, MaryT 1 = 0 and MaryT L = Time , and MaryT i < MaryT i +1 for any 1 †i †L - 1. The description of George's move is given in the same way with the same constraints, following Mary's. In addition, ( GeorgeX j , GeorgeY j ) and ( GeorgeX j +1 , GeorgeY j +1 ) do not coincide for any 1 †j †M - 1. In other words, George is always moving in some direction. Finally, there comes the information of the obstacles. Each obstacle has a rectangular shape occupying ( BlockSX k , BlockSY k ) to ( BlockTX k , BlockTY k ). No obstacle touches or crosses with another. The number of obstacles ranges from 0 to 20 inclusive. All the coordinates are integers not greater than 10000 in their absolute values. You may assume that, if the coordinates of Mary's and George's moves would be changed within the distance of 10 -6 , the solution would be changed by not greater than 10 -6 . The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. Output For each dataset, print the calculated time in a line. The time may be printed with any number of digits after the decimal point, but should be accurate to 10 -4 . Sample Input 50 100 2 50 50 0 51 51 50 2 0 0 0 1 1 50 0 0 0 Output for the Sample Input 50 | 35,584 |
JOIOI ã®å¡(Tower of JOIOI) JOIOI ã®å¡ãšã¯ïŒ1 人ã§éã¶åç€ã䜿ã£ãã²ãŒã ã§ããïŒ ãã®ã²ãŒã ã¯ïŒ J ïŒ O ïŒ I ã®ããããã®æåãæžãããããã€ãã®åç€ãçšããŠè¡ãïŒåç€ã¯çŽåŸãäºãã«ç°ãªãïŒã²ãŒã éå§æã«ã¯ãããã®åç€ã¯çŽåŸã®å€§ãããã®ããé ã«äžããäžã«åãã£ãŠç©ãŸããŠããïŒããªãã¯ïŒãããã®åç€ãçšããŠïŒåºæ¥ãã ãå€ãã®ãã JOIOI ã®å¡ãäœãããïŒãã JOIOI ã®å¡ãšã¯ 3 æã®åç€ãããªãïŒåç€ã®çŽåŸãå°ãããã®ããé ã«èªãã§ JOI ããã㯠IOI ãšèªãããã®ã§ããïŒãã ãïŒåãåç€ã2 床以äžäœ¿ãããšã¯ã§ããªãïŒ å³: JOIOII ããã¯ãã JOIOI ã®å¡ã 2 ã€äœãã èª²é¡ çšæãããåç€ã«æžãããæåãããããåç€ã®çŽåŸãå°ãããã®ããé ã«é·ã N ã®æåå S ãšããŠäžããããïŒãããã®åç€ã䜿ã£ãŠäœãããšã®ã§ãããã JOIOI ã®å¡ã®åæ°ã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ å¶é 1 †N †1 000 000 æåå S ã®é·ã å
¥å æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯æŽæ° N ãæžãããŠããïŒ N ã¯æåå S ã®é·ãã衚ãïŒ 2 è¡ç®ã«ã¯æåå S ãæžãããŠããïŒ åºå æšæºåºåã«ïŒäœãããšã®ã§ãããã JOIOI ã®å¡ã®æ°ã®æå€§å€ãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 6 JOIIOI åºåäŸ 1 2 JOIIOI 㯠JOI ããã³ IOI ããããã 1 ã€ãã€éšååãšããŠå«ãã§ããïŒäœãããšã®ã§ãããã JOIOI ã®å¡ã¯ 2 ã€ã§ããïŒ å
¥åäŸ 2 5 JOIOI åºåäŸ 2 1 éšååãšã㊠JOI ããã³ IOI ãå«ãã§ãããïŒæåã 2 床以äžäœ¿ãããšã¯ã§ããªãããåæã«åãåºãããšã¯ã§ããªãïŒ å
¥åäŸ 3 6 JOIOII åºåäŸ 3 2 ãã®å
¥åºåäŸã¯å顿äžã®äŸã«å¯Ÿå¿ããŠããïŒ å
¥åäŸ 4 15 JJOIIOOJOJIOIIO åºåäŸ 4 4 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,585 |
Problem H: Loss Problem ããªãã¯ããšããäŒç€Ÿããããã°ã©ã ã®äœæãäŸé Œãããã ãã®äŒç€Ÿã«ã¯$N$åã®ä»äºããããããããã®ä»äºã«ã¯$1$ãã$N$ãŸã§ã®çªå·ãæ¯ãããŠããã ä»äº$i$ã«ã¯ã$M_i$åã®åæãšãªãä»äº$X_{i,j}$ãååšããä»äº$i$ãåæãšãªãä»äº$X_{i,j}$ãããå
ã«è¡ããšãä»äº$i$ã¯å€å€§ãªæå€±ã被ãã ããã§ããªãã«ã¯ãæå€±ã被ãä»äºã®æ°ãæå°ãšãªããããªé çªã§ãã¹ãŠã®ä»äºãè¡ã£ããšãã®æå€±ã被ã£ãä»äºã®æ°ãæ±ããŠãããããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§ãã¹ãп޿°ã§äžããããã $N$ $M_1$ $X_{1,1}$ $X_{1,2}$ ... $X_{1,M_1}$ $M_2$ $X_{2,1}$ $X_{2,2}$ ... $X_{2,M_2}$ : $M_N$ $X_{N,1}$ $X_{N,2}$ ...$X_{N,M_N}$ ä»äºã®æ°$N$ã$1$è¡ã«äžããããã ç¶ã$N$è¡ã«åæãšãªãä»äºã®æ
å ±ãäžããããã$i+1$è¡ç®ã«ã¯ä»äº$i$ã®æ
å ±ã空çœåºåãã§äžããããã$M_i$ã¯ãä»äº$i$ã®åæãšãªãä»äºã®æ°ã$X_{i,j}$ã¯ä»äº$i$ã®åæãšãªãä»äºã®çªå·ã衚ããŠããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $1 \le N \le 10^5$ $0 \le M_i \le N$ $M_i$ã®ç·åã¯$10^5$ãè¶
ããªã $1 \le X_{i,j} \le min(i+1,N)$ Output æå€±ã被ãä»äºã®æ°ãæå°ã«ãªããããªé çªã§ãã¹ãŠã®ä»äºãè¡ã£ããšãããã®ãšãã®æå€±ã被ã£ãä»äºã®æ°ãäžè¡ã«åºåããã Sample Input 1 2 1 1 0 Sample Output 1 1 ä»äº$1$ã®ããã«åæãšãªãä»äºããã®ä»äºèªèº«ãšãªããããªå
¥åãååšããã Sample Input 2 3 3 2 1 2 0 1 2 Sample Output 2 1 Sample Input 3 5 1 2 1 3 2 1 2 3 1 3 5 0 Sample Output 3 1 äŸãã°ã$3,2,1,5,4$ã®é ã«ä»äºãè¡ããšæå€±ãæå°åã§ããã | 35,586 |
ãµãããªè« äŒæŽ¥çç©åŠç ç©¶æã®Aå士ã¯ããšããåã®å³¶ã§ãµãããªè«ãçºèŠããŸããã圢ã¯èè«ã®ããã«çްé·ãã®ã§ãããã²ãšã€ã®äœç¯ãçã®ãããªåœ¢ãããŠããã®ã§ã糞ã§ã€ãªãã ããŒãºçã®ããã«èŠããŸãããµãããªã®ã¯äœã®è²ã«æ§ã
ãªããªãšãŒã·ã§ã³ãããããšãšããªãã«ã¯æéããã€ã«ã€ããŠäœã®è²ãå€ã£ãŠããè«ãããããšã§ãããã©ã®è«ã®äœç¯ã®è²ãèµ€ãç·ãéã®ã©ããã«éãããããã§ããã1 ç§ããšã«äœç¯ã®è²ãå€ãã£ãŠãããæåŸã«ã¯ãã¹ãŠã®äœç¯ãåãè²ã«ãªã£ãŠèœã¡çãå Žåãããã°ããã€ãŸã§åŸ
ã£ãŠããã£ãšè²ãå€ããã€ã¥ããå Žåãããããã§ããã 調ã¹ãŠãããã¡ã«ããµã ãã¯ãã¹ãŠã®äœç¯ãåãè²ãããŠããã®ã§ãããäœãã«é©ãããããŠè奮ããåŸã¯äœç¯ã®è²ãåæã«å€ãã£ãŠããŸãããšãããããŸãããäžåºŠäœç¯ã®è²ãå€ãã£ãŠããŸããšããµããã³ãã¹ãŠã®äœç¯ãåãè²ã«ãªããŸã§ã¯ãã£ãšè²ãå€ããç¶ããããšãããããŸããã Aå士ã¯ãã®è«ãäœå¹ãæãŸããŠè奮ãããŠã¿ãŠã¯ãè²ãå€ããæ§åãè峿·±ã芳å¯ããŠããŸãããããããŠè²ãå€åããŠããæäžã®è²ã®å€ããæ¹ã«ã¯æ¬¡ã®ãããªèŠåæ§ãããããšã«æ°ãã€ããŸããã è²ãå€ããã®ã¯ãé£ãåã£ãŠããè²éãã® 2ã€ã®äœç¯ã®ã㢠1çµã ããå€ãããä»ã®äœç¯ã®è²ã¯å€ãããªãããã ãããã®ãããªãã¢ãè€æ°ãããšãã«ãã©ã®ãã¢ã®è²ãå€ãããã¯ãããããäºæž¬ã§ããªãã ãã®ãããªãã¢ã¯ã2ã€ã®äœç¯ã®è²ã®ã©ã¡ãã§ããªãè²ã«åæã«å€ãã(ããšãã°ãç·ãšèµ€ã®äœç¯ãé£ãåã£ãŠãããšãã¯ãããããåæã«éã«å€ãã)ã è«ã®è²ã®å€åãã2ç§åŸãŸã§ãã¹ãŠæžãããã®ãäžã®å³ã§ããå³ã®äžæ®µã®ãããªè²ãããè«ããããšããŸãããã®ãšããé£ãåã£ãè²éãã®äœç¯ã®ãã¢ã¯ 3çµããã®ã§ã1ç§åŸã«ã¯äžæ®µã«äžŠã¹ãŠæãã 3éãã®è²ã®ã©ããã«å€ãããŸãã1ç§åŸã«äžæ®µå·ŠåŽã® 2ã€ã®ããã«å€ãã£ããšãã«ã¯ã2ç§åŸã«ãã¹ãŠã®äœç¯ãç·è²ã«ãªãããšãã§ããŸã(å³ã®äžæ®µã®å·ŠåŽãã 2çªç®)ã ããã«å¯ŸããŠã1ç§åŸã«äžæ®µã®1çªå³ã®ããã«å€ãã£ããšãã«ã¯ã2ç§åŸã«ãã¹ãŠã®äœç¯ãåãè²ã«å€ããããšã¯ãããŸããã å士ã¯ãç®ã®åã«ããè«ã®äœç¯ããã¹ãŠåãè²ã«ãªãå¯èœæ§ãããã®ãããããšããããããªãã®ã¯æçã§äœç§åŸãªã®ããäºæž¬ããããšã«ããŸããã ç®ã®åã«ããè«ã®äœç¯ã®è²ã®äžŠã³ãå
¥åãšãããã®è«ã®äœç¯ããã¹ãŠåãè²ã«ãªãã®ã«èŠããæçã®æéãç§åäœã§åºåããããã°ã©ã ãäœæããŠãã ããããã ããåãè²ã«ãªãå¯èœæ§ããªããšãã¯ãNA(åè§è±å€§æå)ããšåºåããŠãã ããããŸããè«ã®äœç¯ã®è²ã®äžŠã³ã¯2 ä»¥äž 10 以äžã®r(èµ€)ãg(ç·)ãb(é)ãããªãæååã§è¡šãããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãã㟠ããåããŒã¿ã»ãããšããŠã è«ã®äœç¯ã®æ
å ±ã衚ãïŒã€ã®æååãïŒè¡ã«äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã Output ããŒã¿ã»ããæ¯ã«ããã¹ãŠã®äœç¯ã®è²ãåãã«ãªããŸã§ã«èŠããæå°æé (ç§åäœã®æŽæ°) ãŸã㯠NA ãïŒè¡ã«åºåããŸãã Sample Input rbgrg rbbgbbr bgr bgrbrgbr bggrgbgrr gbrggrbggr rrrrr bgbr 0 Output for the Sample Input 5 7 1 6 NA 8 0 4 | 35,587 |
æææ¢æ»(Planetary Exploration) ããªããä¹ããè¶
æç©ºç§»æ°è¹ã¯é·æ
ã®æ«ïŒã€ãã«å±
äœå¯èœãšæãããææãçºèŠããïŒJOI æãšåä»ãããããã®ææã¯ïŒãã®åã®éãããžã£ã³ã°ã«(Jungle)ãïŒãæµ·(Ocean)ãïŒãæ°·(Ice)ãã®3 çš®é¡ã®å°åœ¢ãå
¥ãçµãã éé
·ãªææã§ããïŒç°¡åãªèª¿æ»ã«ããïŒå±
äœäºå®å°è¿èŸºã®å°å³ãäœæãããïŒå±
äœäºå®å°ã¯åå M km, æ±è¥¿ N km ã®é·æ¹åœ¢ã®åœ¢ãããŠããïŒ 1 km åæ¹ã®æ£æ¹åœ¢ã®åºç»ã«åããããŠããïŒåºç»ã¯å
šéšã§ MN åããïŒåãã p è¡ç®ïŒè¥¿ãã q åç®ã®åºç»ã( p , q ) ã§è¡šãïŒå西ã®è§ã®åºç»ã(1, 1) ã§ããïŒåæ±ã®è§ã®åºç»ã( M , N ) ã§ããïŒååºç»ã®å°åœ¢ã¯ïŒããžã£ã³ã°ã«ãïŒãæµ·ãïŒãæ°·ãã®ããããã§ããïŒããžã£ã³ã°ã«ãã¯J, ãæµ·ãã¯O, ãæ°·ãã¯I ã®è±å1 æåã§è¡šããã. ããŠïŒè©³çްãªç§»äœèšç»ãç«ãŠãã«ãããïŒ K ç®æã®é·æ¹åœ¢é åå
ã«ããžã£ã³ã°ã«ãïŒãæµ·ãïŒãæ°·ããããããäœåºç»å«ãŸãããã調ã¹ãããšã«ããïŒ èª²é¡ å±
äœäºå®å°ã®æ
å ±ãšïŒèª¿æ»å¯Ÿè±¡ãšãªãé åã®æ
å ±ãäžãããããšãïŒããããã®é åã«ã€ããŠïŒ ããžã£ã³ã°ã«ãïŒãæµ·ãïŒãæ°·ããäœåºç»å«ãŸããŠããããæ±ããããã°ã©ã ãäœæããïŒ å¶é 1 †M †1000 å±
äœäºå®å°ã®ååã®é·ã(km) 1 †N †1000 å±
äœäºå®å°ã®æ±è¥¿ã®é·ã(km) 1 †K †100000 調æ»å¯Ÿè±¡ãšãªãé åã®åæ° å
¥å æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯æŽæ° M , N ã空çœãåºåããšããŠæžãããŠããïŒå±
äœäºå®å°ãååã« M km ïŒæ±è¥¿ã« N km ã®åºãã§ããããšã衚ãïŒ 2 è¡ç®ã«ã¯æŽæ° K ãæžãããŠããïŒèª¿æ»å¯Ÿè±¡ãšãªãé åã®åæ°ã衚ãïŒ ç¶ã M è¡ã«ã¯å±
äœäºå®å°ã®æ
å ±ãæžãããŠããïŒ i + 2 è¡ç®(1 †i †M ) ã«ã¯ïŒå±
äœäºå®å°ã®åãã i è¡ç®ã«äœçœ®ãã N åºç»ã®æ
å ±ã衚ãJïŒOïŒI ãããªã N æåã®æååãæžãããŠããïŒ ç¶ã K è¡ã«ã¯èª¿æ»å¯Ÿè±¡ãšãªãé åãæžãããŠããïŒ j + M + 2 è¡ç®(1 †j †K ) ã«ã¯ïŒ j çªç®ã®é åãè¡šãæ£æŽæ° a j , b j , c j , d j ã空çœãåºåããšããŠæžãããŠããïŒ( a j , b j ) ã¯èª¿æ»é åã®å西ã®è§ã®åºç»ãïŒ( c j , d j ) ã¯èª¿æ»é åã®åæ±ã®è§ã®åºç»ã衚ãïŒãã ãïŒ a j , b j , c j , d j ã¯ïŒ1 †a j †c j †M , 1 †b j †d j †N ãæºããïŒ åºå æšæºåºåã«èª¿æ»ã®çµæã衚ã K è¡ãåºåããïŒåºåã® j è¡ç®ã«ã¯ïŒ j çªç®ã®èª¿æ»é åã«å«ãŸããããžã£ã³ã°ã«ã(J) ã®åºç»æ°ïŒãæµ·ã(O) ã®åºç»æ°ïŒãæ°·ã(I) ã®åºç»æ°ã衚ã3 ã€ã®æŽæ°ãïŒãã®é ã«ç©ºçœãåºåããšããŠæžãïŒ æ¡ç¹åºæº æ¡ç¹çšããŒã¿ã®ãã¡ïŒé
ç¹ã®30%åã«ã€ããŠã¯ïŒ M †50 ã〠K †100 ãæºããïŒé
ç¹ã®50%åã«ã€ããŠã¯ïŒ M †50 ãæºããïŒ å
¥åºåã®äŸ å
¥åäŸ 4 7 4 JIOJOIJ IOJOIJO JOIJOOI OOJJIJO 3 5 4 7 2 2 3 6 2 2 2 2 1 1 4 7 åºåäŸ 1 3 2 3 5 2 0 1 0 10 11 7 ãã®å
¥åäŸã§ã¯ïŒ 2 çªç®ã®é åã¯äžå³ã®ããã«ããžã£ã³ã°ã«ãã3 åºç»ïŒãæµ·ãã5 åºç»ïŒãæ°·ãã2 åºç»å«ãïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,588 |
Problem E: Full Text Search Mr. Don is an administrator of a famous quiz website named QMACloneClone. The users there can submit their own questions to the system as well as search for question texts with arbitrary queries. This search system employs bi-gram search method. The bi-gram search method introduces two phases, namely preprocessing and search: Preprocessing Precompute the set of all the substrings of one or two characters long for each question text. Search Compute the set for the query string in the same way. Then nd the question texts whose precomputed sets completely contain the set constructed from the query. Everything looked fine for a while after the feature was released. However, one of the users found an issue: the search results occasionally contained questions that did not include the query string as-is. Those questions are not likely what the users want. So Mr. Don has started to dig into the issue and asked you for help. For each given search query, your task is to find the length of the shortest question text picked up by the bi-gram method but not containing the query text as its substring. Input The input consists of multiple datasets. A dataset is given as a search query on each line. The input ends with a line containing only a hash sign (" # "), which should not be processed. A search query consists of no more than 1,000 and non-empty lowercase and/or uppercase letters. The question texts and queries are case-sensitive. Output For each search query, print the minimum possible length of a question text causing the issue. If there is no such question text, print " No Results " in one line (quotes only to clarify). Sample Input a QMAClone acmicpc abcdefgha abcdefgdhbi abcbcd # Output for the Sample Input No Results 9 7 9 12 6 Note Let's consider the situation that one question text is "CloneQMAC". In this situation, the set computed in the preprocessing phase is {"C", "Cl", "l", "lo", "o", "on", "n", "ne", "e", "eQ", "Q", "QM", "M", "MA", "A", "AC"}. In the testcase 2, our input text (search query) is "QMAClone". Thus the set computed by the program in the search phase is {"Q", "QM", "M", "MA", "A", "AC", "C", "Cl", "l", "lo", "o", "on", "n", "ne", "e"}. Since the first set contains all the elements in the second set, the question text "CloneQMAC" is picked up by the program when the search query is "QMAClone" although the text "CloneQ-MAC" itself does not contain the question text "QMAClone". In addition, we can prove that there's no such text of the length less than 9, thus, the expected output for this search query is 9. | 35,589 |
Score : 200 points Problem Statement Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat. Constraints 0 \leq A,B,C \leq 10^9 A,B and C are integers. Input Input is given from Standard Input in the following format: A B C Output Print the maximum number of tasty cookies that Takahashi can eat. Sample Input 1 3 1 4 Sample Output 1 5 We can eat all tasty cookies, in the following order: A tasty cookie containing poison An untasty cookie containing antidotes A tasty cookie containing poison A tasty cookie containing antidotes A tasty cookie containing poison An untasty cookie containing antidotes A tasty cookie containing poison Sample Input 2 5 2 9 Sample Output 2 10 Sample Input 3 8 8 1 Sample Output 3 9 | 35,590 |
Problem F: Prize Game Problem æ°ããã²ãŒã ã»ã³ã¿ãŒãéåºããããšã«ãªã£ããããããã®ã客ãããåãå
¥ããããã«ãå
šãæ°ãããã©ã€ãºã²ãŒã ãèšçœ®ããããšã«ãªã£ãã ãã®ãã©ã€ãºã²ãŒã 㯠R à C ã®ã°ãªããããæ§æããããåãã¹ã¯ç©ºçœãã1ã18ã®ããããã®æ°åãæžãããŠããããã¬ã€ã€ãŒã¯ã²ãšã€ã®ç©ºçœã®ãã¹ãéžæãããã®ãã¹ã®æ¯åãç²åŸã§ããããã ãããã¹ã«ããæ¯åã¯ãã¬ã€ã€ãŒããèŠãããšãã§ããªãã ã¹ã¿ããã¯ãã®ãã©ã€ãºã²ãŒã ã«æ¯åãèšçœ®ããªããã°ãªããªããã¹ã¿ããã¯ä»¥äžã®ã«ãŒã«ãå®ãããŠããã°ãã©ã®ããã«æ¯åãé
眮ããŠããããæ°åãæžãããŠãããã¹ã«ã€ããŠããã®æ°åã x ãšãããšããã®æ°åãäžå¿ãšããåžåã®ç¯å²ã®äžã«æ¯åãã¡ããã© x å眮ãããŠããå¿
èŠãããïŒäžã®å³ãåç
§ïŒããã®åžåã®åºã£åŒµã£ãŠããéšåã¯äžãåããŠããããŸããæ¯åã¯ç©ºçœã®ãã¹ã®ã¿ã«çœ®ãããšãã§ãã1ã€ã®ãã¹ã«3åãŸã§çœ®ãããšãåºæ¥ãã1åã眮ããªãããšãå¯èœã§ããã äžå€®ã®æ°åã5ã ã£ãå Žåã®æ¯åã®çœ®ãæ¹ã®äŸããªã¬ã³ãžè²ã®éšåã«ã¡ããã©èš5åã®æ¯åã眮ãããŠããå¿
èŠãããã ã客ããã«æ¯åã®å Žæãç°¡åã«æšæž¬ãããŠã¯å€§æã§ãããããã§ããªãŒããã³ã°ã¹ã¿ããã§ããããªãã«ãäžèšã«ãŒã«ã«åã£ãæ¯åã®çœ®ãæ¹ã®å Žåã®æ°ãæ°ããŠãããããããã ããæ¯åã¯äºãã«åºå¥ã§ããªããã®ãšãããçãã¯å€§ãããªãå Žåãããã®ã§çãã®å Žåã®æ°ã1000000007ã§å²ã£ãäœããçããªããã Input R C a 1,1 a 1,2 ... a 1,C a 2,1 a 2,2 ... a 2,C : a R,1 a R,2 ... a R,C 1è¡ç®ã«2ã€ã®æŽæ° R , C ã空çœåºåãã§äžãããããããããã°ãªããã®è¡æ°ãšåæ°ã衚ããæ¬¡ã«ãã©ã€ãºã²ãŒã ã衚ãã°ãªããã®æ
å ±ã R è¡ã§äžãããããã°ãªããã®æ
å ±ã® i è¡ç®ã«ã¯ C åã®æŽæ° a i,j ã空çœåºåãã§äžããããã a i,j ã¯ã°ãªããã® i è¡ j åã®ãã¹æ
å ±ã衚ãã0ã®å Žåã¯ç©ºçœã®ãã¹ããã以å€ã®å Žåã¯æ°å a i,j ãæžããããã¹ã衚ãããŸããäžããããã°ãªããã¯1è¡ç®ããã©ã€ãºã²ãŒã ã®äžçªäžã衚ãã R è¡ç®ãäžçªäžã衚ãã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã 1 †R , C †6 0 †a i,j †18 (1 †i †R , 1 †j †C ) Output ã«ãŒã«ã«åã£ãæ¯åã®çœ®ãæ¹ã®å Žåã®æ°ã1000000007ã§å²ã£ãäœãã1è¡ã«åºåããã Sample Input 1 3 3 0 0 0 0 18 0 0 0 0 Sample Output 1 16 Sample Input 2 3 3 0 0 0 0 2 0 0 0 0 Sample Output 2 336 Sample Input 3 3 3 0 1 0 1 0 0 0 1 1 Sample Output 3 1 Sample Input 4 1 1 1 Sample Output 4 0 Sample Input 5 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Sample Output 5 80065005 | 35,591 |
ã¹ã³ãŒã³é
éèšç» ææããã®å®¶ã¯ãå°ããªå«è¶åºãçµå¶ããŠããŸããææããã®ãæ¯ãããçŒãã¹ã³ãŒã³ã¯ãšãŠãçŸå³ãããŠãåºã¯ãšãŠãç¹çããŠããŸããã ãŠã§ã€ãã¬ã¹ã§ããææããã®ä»äºã®äžã€ã¯ã次ã
ãšçŒãäžããã¹ã³ãŒã³ããã客æ§ã®åžãŸã§å±ããããšã§ããçŒãããã£ãã¹ã³ãŒã³ã¯ãçã®äžã«ä¹ããããã«ãŠã³ã¿ãŒã®äžã«äžåã«äžŠã¹ãããŸãã i çªç®ã®ãçã®äžã«ä¹ã£ãŠããã¹ã³ãŒã³ã®æ°ã K i ãšããŸããããææããã¯ãããããã®ã客æ§ã«ã¡ããã© m åã®ã¹ã³ãŒã³ãéã°ãªããã°ãªããŸãããææããã¯äžåºŠã«ããã€ã§ããçãæã€ããšãã§ãããŸãè€æ°ã®ãçãã 1 人ã®ã客æ§ã«ã¹ã³ãŒã³ãé
ã£ãããïŒã€ã®ãçããè€æ°ã®ã客æ§ã«é
ã£ãŠãæ§ããŸããã å«è¶åºã«ã¯ãšãŠãããããã®ã客æ§ããã£ãŠããã®ã§ãã«ãŠã³ã¿ãŒã«çœ®ããŠããå
šãŠã®ã¹ã³ãŒã³ãéãã§ããå
šãŠã®ã客æ§ã«å±ããããšã¯ã§ããŸãããããããã§ããã ãå€ãã®ã客æ§ã«å±ããåŸã§ã m åã«æºããªãæ°ã®ã¹ã³ãŒã³ãäœãããšããããããããŸããããã®ãããªã¹ã³ãŒã³ã¯ããæäŒãã®ãè€çŸãšããŠãææãããè²°ããããšã«ãªããŸããã ããã§ãµãšãææããã¯èããŸãããäžåºŠã«å
šãŠã®ãçãæã€ã®ã§ã¯ãªããäžéšã®ãçã ããæã£ãŠã客æ§ã«ã¹ã³ãŒã³ãå±ãããšãäœãã¹ã³ãŒã³ã®æ°ãéã£ãŠããã¯ãã§ããé©åã«ãçãéžã¶ããšã§ãããå€ãã®ã¹ã³ãŒã³ãäœãããã«ã§ãããããããŸãããææããã¯ãäœçºçã«ãçãéžãã§ããããšããæ¯ããã«èŠæãããªãããã«ãã«ãŠã³ã¿ãŒã®äžã®1ã€ã®é£ç¶ããç¯å²ã®ãçãéžã¶ããšã«ããŸããããŸããæ®ã£ããçã¯ãç¶ããããæ¯ãããéãã§ããŸãã®ã§ãææãããã¹ã³ãŒã³ãããããã£ã³ã¹ã¯äžåºŠãããããŸããã ããŠãææããã¯æå€§ããã€ã®ã¹ã³ãŒã³ãè²°ããã§ããããïŒèšç®ããããã°ã©ã ãæžããŠãã ããããçã®æ° n 㯠1 ä»¥äž 30,000以äžã m 㯠1 ä»¥äž 100,000 以äžã§ãããŸãæ°åã®åèŠçŽ K i 㯠0 ä»¥äž 2 32 -1 ã§ãã å
¥å è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®ãšããã§ãã 1è¡ç® n m ïŒæŽæ° æŽæ°ïŒåè§ç©ºçœåºåãïŒ 2è¡ç® ãçäžã®ã¹ã³ãŒã³ã®æ
å ± K 1 K 2 ... K n ïŒãã¹ãп޿° ; åè§ç©ºçœåºåãïŒ K i : i çªç®ã®ãçäžã®ã¹ã³ãŒã³ã®æ° ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã åºå ããŒã¿ã»ããããšã«ãããããã¹ã³ãŒã³ã®æå€§æ°ãïŒè¡ã«åºåããŸãã å
¥åäŸ 5 11 11 27 34 45 56 8 5 0 2 1 5 4 6 8 3 5 2 2 4 2 4 6 10 18 10 15 12 31 12 50 11 23 43 181 1 100 5 0 0 åºåäŸ 8 4 0 17 5 | 35,592 |
Score : 400 points Problem Statement Given are three integers N , K , and S . Find a sequence A_1, A_2, ..., A_N of N integers between 1 and 10^9 (inclusive) that satisfies the condition below. We can prove that, under the conditions in Constraints, such a sequence always exists. There are exactly K pairs (l, r) of integers such that 1 \leq l \leq r \leq N and A_l + A_{l + 1} + \cdots + A_r = S . Constraints 1 \leq N \leq 10^5 0 \leq K \leq N 1 \leq S \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: N K S Output Print a sequence satisfying the condition, in the following format: A_1 A_2 ... A_N Sample Input 1 4 2 3 Sample Output 1 1 2 3 4 Two pairs (l, r) = (1, 2) and (3, 3) satisfy the condition in the statement. Sample Input 2 5 3 100 Sample Output 2 50 50 50 30 70 | 35,593 |
Score : 1500 points Problem Statement Snuke received two matrices A and B as birthday presents. Each of the matrices is an N by N matrix that consists of only 0 and 1 . Then he computed the product of the two matrices, C = AB . Since he performed all computations in modulo two, C was also an N by N matrix that consists of only 0 and 1 . For each 1 †i, j †N , you are given c_{i, j} , the (i, j) -element of the matrix C . However, Snuke accidentally ate the two matrices A and B , and now he only knows C . Compute the number of possible (ordered) pairs of the two matrices A and B , modulo 10^9+7 . Constraints 1 †N †300 c_{i, j} is either 0 or 1 . Input The input is given from Standard Input in the following format: N c_{1, 1} ... c_{1, N} : c_{N, 1} ... c_{N, N} Output Print the number of possible (ordered) pairs of two matrices A and B (modulo 10^9+7 ). Sample Input 1 2 0 1 1 0 Sample Output 1 6 Sample Input 2 10 1 0 0 1 1 1 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 1 0 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1 1 1 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 0 1 1 1 0 0 0 0 1 0 1 0 0 1 1 1 1 1 Sample Output 2 741992411 | 35,594 |
Problem F: Computation of Minimum Length of Pipeline The Aizu Wakamatsu city office decided to lay a hot water pipeline covering the whole area of the city to heat houses. The pipeline starts from some hot springs and connects every district in the city. The pipeline can fork at a hot spring or a district, but no cycle is allowed. The city office wants to minimize the length of pipeline in order to build it at the least possible expense. Write a program to compute the minimal length of the pipeline. The program reads an input that consists of the following three parts: Input The first part consists of two positive integers in one line, which represent the number s of hot springs and the number d of districts in the city, respectively. The second part consists of s lines: each line contains d non-negative integers. The i -th integer in the j -th line represents the distance between the j -th hot spring and the i -th district if it is non-zero. If zero it means they are not connectable due to an obstacle between them. The third part consists of d -1 lines. The i -th line has d - i non-negative integers. The i -th integer in the j -th line represents the distance between the j -th and the ( i + j )-th districts if it is non-zero. The meaning of zero is the same as mentioned above. For the sake of simplicity, you can assume the following: The number of hot springs and that of districts do not exceed 50. Each distance is no more than 100. Each line in the input file contains at most 256 characters. Each number is delimited by either whitespace or tab. The input has several test cases. The input terminate with a line which has two 0. The number of test cases is less than 20. Output Output the minimum length of pipeline for each test case. Sample Input 3 5 12 8 25 19 23 9 13 16 0 17 20 14 16 10 22 17 27 18 16 9 7 0 19 5 21 0 0 Output for the Sample Input 38 Hint The first line correspondings to the first part: there are three hot springs and five districts. The following three lines are the second part: the distances between a hot spring and a district. For instance, the distance between the first hot spring and the third district is 25. The last four lines are the third part: the distances between two districts. For instance, the distance between the second and the third districts is 9. The second hot spring and the fourth district are not connectable The second and the fifth districts are not connectable, either. | 35,595 |
H: ãžã£ã³ãããŒã㣠åé¡ ãšãããã³ã¹ããŒã«ã§ $N$ 人ã®åå ãããã³ã¹ããŒãã£ãŒãè¡ãããã ãã®ãã³ã¹ããŒã«ã¯çžŠæ¹åã« $H$ åãæšªæ¹åã« $W$ åã®ã°ãªããã«åããããŠããã å·Šäžã $(0,0)$ãäžãã $r$ ãã¹ãå·Šãã $c$ ãã¹ç®ã®ã°ãªããã®åº§æšã $(r,c)$ ãšè¡šãã $i$ çªç®ã®åå è
ã®åæäœçœ®ã¯ $(R_i, C_i)$ ã§ããã$(i,j)$ ã®ã°ãªããã«ã¯ $(r_{ij}, c_{ij})$ ãæžãããŠããã ååå è
ã¯ãç¡éã«ç¶ã鳿¥œã«åãããŠæ¬¡ã®ããã«åæã«ç§»åãè¡ãã ãã®æã«ãã座æšã $(i,j)$ ã®ãšãã$(r_{ij}, c_{ij})$ ãžãžã£ã³ãã§ç§»åããã ããããã®ã°ãªããã¯çãã2 人以äžã®åå è
ãåæã«åãã°ãªããã«ç§»åãããšè¡çªããŠããŸãããã ãã空äžã§è¡çªããããšã¯ç¡ããšããã ãããèããããªãã¯ããžã£ã³ãåŸã« 2 人以äžã®åå è
ãè¡çªããŠããŸããªãããšå¿é
ã«ãªã£ãã ããã§ãè¡çªãèµ·ããå¯èœæ§ããããããããªãã°äœåç®ã®ãžã£ã³ãã®åŸã«è¡çªãèµ·ããããæ±ããããšã«ããã å¶çŽ $1 \le H,W \le 500$ $0 \le N \le H \times W$ $0 \le r_{ij} < H \ (0 \le i < H, 0 \le j < W)$ $0 \le c_{ij} < W \ (0 \le i < H, 0 \le j < W)$ $0 \le R_i < H \ (0 \le i < N)$ $0 \le C_i < W \ (0 \le i < N)$ åå è
ã®åæäœçœ®ã¯çžç°ãªã å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $H \ W \ N$ $r_{00} \ c_{00} \ \cdots \ r_{0 \ W-1} \ c_{0 \ W-1}$ $\vdots$ $r_{H-1 \ 0} \ c_{H-1 \ 0} \ \cdots \ r_{H-1 \ W-1} \ c_{H-1 \ W-1}$ $R_0 \ C_0$ $\vdots$ $R_{N-1} \ C_{N-1}$ ãã®åé¡ã§ã¯å
¥åãã¡ã€ã«ãéåžžã«å€§ãããªãããšãããããšã«æ³šæããã C++ ãªã ãã®ããŒãž ãåèã«ãããšè¯ããããããªãã åºå è¡çªãèµ·ããå Žåã¯äœåç®ã®ãžã£ã³ãã®åŸã«èµ·ãããã 1 è¡ã§åºåããã ããã§ãªãå Žå㯠-1 ãåºåããã ãŸããæ«å°Ÿã«æ¹è¡ãåºåããã ãµã³ãã« ãµã³ãã«å
¥å 1 2 2 2 1 0 0 1 0 0 1 0 0 0 0 1 ãµã³ãã«åºå 1 -1 ãµã³ãã«å
¥å 2 2 2 2 1 0 0 1 0 0 1 0 0 0 1 1 ãµã³ãã«åºå 2 1 | 35,596 |
å質管ç äŒæŽ¥ã¿ã«ãåžãçç£è²©å£²ããåžè£œã³ãŒã¹ã¿ãŒã¯ã察称ãªãã¶ã€ã³ã§ãšãŠãçŸããããšã§ç¥ãããŠãããäŒæŽ¥ã¿ã«ãåžã§ã¯å質管çã®äžç°ãšããŠã補é ã©ã€ã³ã«ã«ã¡ã©ãèšçœ®ããåã³ãŒã¹ã¿ãŒãæ®åœ±ããŠåŸãããç»åã察称ã«ãªã£ãŠããããèªåã§æ€èšŒããŠãããåã³ãŒã¹ã¿ãŒã¯ N à N ãã¯ã»ã«ã®æ£æ¹åœ¢ã®çœé»ç»åãšããŠè¡šããããåãã¯ã»ã«ã¯çœãŸãã¯é»ã®ç»åã«å¯Ÿå¿ããŠã0 ãŸã㯠1 ã®å€ããšãã ãã®åºŠãçç£ã©ã€ã³ã®æ©åšæŽæ°ã«ãšããªã£ãŠãç»åè§£æã·ã¹ãã ã®ãœãããŠã§ã¢ãæŽæ°ããããšã«ãªã£ããæ°ã·ã¹ãã ã§ã¯ãéä¿¡ããŒã¿éãåæžãã工倫ããªããã以äžã®æ¹æ³ã§ã«ã¡ã©ããè§£æã·ã¹ãã ã«ããŒã¿ãéãããŠããã ã©ã€ã³ã«æµããŠããæåã®ã³ãŒã¹ã¿ãŒã®æ
å ±ã¯ã N à N ãã¯ã»ã«ã®ç»åãšããŠã·ã¹ãã ã«éãããŠããã ïŒæç®ä»¥éã®ã³ãŒã¹ã¿ãŒã®æ
å ±ã¯ãïŒã€åã«éãããç»åãšã®å·®åã ããéãããŠãããå·®åã¯ãã0 ãã 1 ããŸãã¯ã1 ãã 0 ããžãšå€åãããã¯ã»ã«ã®äœçœ®ã®éåãšããŠäžããããã C æã®ã³ãŒã¹ã¿ãŒã«ã€ããŠãïŒæç®ã®ç»åã®ãã¯ã»ã«æ
å ±ãšç¶ã C - 1 æåã®å·®åæ
å ±ãå
¥åããäžäžå¯Ÿç§°ãã€å·Šå³å¯Ÿç§°ãšãªã£ãŠããã³ãŒã¹ã¿ãŒã®ææ°ãå ±åããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã C N p 11 p 12 ... p 1N p 21 p 22 ... p 2N : p N1 p N2 ... p NN diff 1 diff 2 : diff Câ1 ïŒè¡ç®ã«ã³ãŒã¹ã¿ãŒã®ææ° C (1 †C †10000) ãšç»åã®çžŠãšæšªã®ãã¯ã»ã«æ° N (2 †N †1000 ã〠N ã¯å¶æ°) ãäžãããããïŒè¡ç®ãã N + 1 è¡ç®ã«æåã®ã³ãŒã¹ã¿ãŒã®ç»åã®ãã¯ã»ã«ã衚ã N è¡ Ã N åã®æ°å p ij ( p ij 㯠0 ãŸã㯠1)ãäžããããã N + 2 è¡ç®ä»¥éã«ãïŒæç®ä»¥éã®ã³ãŒã¹ã¿ãŒã®æ
å ±ã衚ãå·®å diff i ãæ¬¡ã®åœ¢åŒã§äžããããã D r 1 c 1 r 2 c 2 : r D c D ïŒè¡ç®ã«å€åãããã¯ã»ã«ã®æ° D (0 †D †100) ãäžãããããç¶ã D è¡ã«å€åãããã¯ã»ã«ã®è¡ãšåã®çªå·ããããã衚ã r i ãš c i (1 †r i , c i †N ) ãäžããããã diff i ã®äžã«ãåãäœçœ®ã¯ïŒå以äžäžããããªãã Output äžäžå¯Ÿç§°ãã€å·Šå³å¯Ÿç§°ãšãªã£ãŠããã³ãŒã¹ã¿ãŒã®ææ°ãïŒè¡ã«åºåããã Sample Input 1 7 8 00100000 00011000 10111101 01100110 01000110 10111101 00011000 00100100 2 5 3 1 6 1 6 8 3 6 8 3 3 3 6 2 6 3 6 6 0 2 3 8 6 8 Sample Output 1 3 å
¥åäŸïŒã®ã³ãŒã¹ã¿ãŒã®ç»åã以äžã«ç€ºãããã®å ŽåãïŒæç®ãïŒæç®ãïŒæç®ã®ã³ãŒã¹ã¿ãŒãäžäžå¯Ÿç§°ãã€å·Šå³å¯Ÿç§°ãšãªãããã3ãšå ±åããã Sample Input 2 1 6 000000 000000 010010 010010 000000 000000 Sample Output 2 1 Sample Input 3 2 2 00 00 4 1 1 1 2 2 1 2 2 Sample Output 3 2 | 35,597 |
Largest Rectangle in a Histogram A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints $1 \leq N \leq 10^5$ $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Sample Input 1 8 2 1 3 5 3 4 2 1 Sample Output 1 12 Sample Input 2 3 2 0 1 Sample Output 2 2 | 35,598 |
Reconstruction of a Tree Write a program which reads two sequences of nodes obtained by the preorder tree walk and the inorder tree walk on a binary tree respectively, and prints a sequence of the nodes obtained by the postorder tree walk on the binary tree. Input In the first line, an integer $n$, which is the number of nodes in the binary tree, is given. In the second line, the sequence of node IDs obtained by the preorder tree walk is given separated by space characters. In the second line, the sequence of node IDs obtained by the inorder tree walk is given separated by space characters. Every node has a unique ID from $1$ to $n$. Note that the root does not always correspond to $1$. Output Print the sequence of node IDs obtained by the postorder tree walk in a line. Put a single space character between adjacent IDs. Constraints $1 \leq n \leq 40$ Sample Input 1 5 1 2 3 4 5 3 2 4 1 5 Sample Output 1 3 4 2 5 1 Sample Input 2 4 1 2 3 4 1 2 3 4 Sample Output 2 4 3 2 1 | 35,599 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.