This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
一つの講義には$theoreticalValue[i]$, $practicalValue[i]$, $expire[i]$がある.一ヶ月に一つの講義しか取ることができず,$i$番目の講義を受けるには,$expire$以内であり,自身のskillが少なくとも$(theoreticalValue[i] - 1$,$practicalValue[i] - 1)$以上である必要がある.skillが下がることはなく,受けた講義のskillよりも自分のskillが小さければ,その講義のskillになる.最初のskillは共に$(0, 0)$である.双方のskillが$skillBound$以上になるために,最も講義数が少ない講義の受け方を答える.答えが複数ある場合は辞書順最小のものを答える.
自分のskillが下がることがなく,少なくとも$(tvi-1$, $pvi-1)$あると講義を受けることができるため,例えば$(1, 3)$の時に$(2, 1)$の講義を受けると$(2, 3)$にすることができる.状態を$(tv, pv)$で持って,各状態への最短経路を求める.解が複数ある場合は辞書順最小となる解にするために,解が既にあり,更新しようとする値も同じ場合は,双方で経路復元をして,小さい方に更新する.skillが$skillBound$以上になっていれば良いので,$skillBound \sim 50$の組み合わせを全て列挙し,最も講義数が少ない,辞書順最初の経路を求める.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
勝ったら$bet$は$1$,負けたら次の$bet$を$2$倍にする.勝負に勝つ確立は毎回$prob$である.はじめ$initSum$所持していて,$rounds$回行い,$goalSum$以上になる確立を求める.
$$ dp[i][j][k] := iターン目に所持金jでk回負けた時の確立 $$
何回負けたかを持つと$bet$が$(1 << k)$で求まる.後は$bet$が所持金を超えないならば,勝つ,負ける,それぞれの場合に遷移させる.勝った場合は$k$は$0$になる.$goalSum$以上超えた場合は終わりなので,$j$は$goalSum$未満しか見ない.最後には,全てのラウンド内で$goalSum$以上になったものを全て足す.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
駅$0$から駅$n-1$に行きたい.空白区切りで$a\ b\ departure\ time\ cost$が与えられる.駅$a$と駅$b$を結ぶバスは,時刻$departure$に出発し,時間$time$かかり,コストは$cost$である.時刻$T$以内に駅$n-1$に着けない場合は$-1$,着ける場合は最小コストを答える.
(駅番号, 時刻)を状態にしてdijkstra.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
長さ$arrayLength$の配列の要素を$swapCount$回swapする.初めに$a$番目にあったものが$b$番目にいる確立を求める.
$$ dp[i][j] := i回swapした時にb番目にいる確立 $$
一回のswapの選択肢は$\displaystyle \frac{n*(n-1)}{2}$通りある.swap後に$b$番目にいる場合は,元々$b$番目にいてswapに$b$番目が選ばれない場合と,他の場所にいてその場所と$b$番目をswapする場合である.swap後に$b$番目にいない場合は,元々$b$番目にいて他の場所にswapされる場合と,他の場所にいてその場所と$b$番目がswapされない場合である.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
$played$, $won$が与えられる.勝率は$\displaystyle \frac{won}{played}$の百分率で表す(小数点以下は切り捨て).これ以降プレイする場合は必ず勝つ場合に,あと何回プレイすれば勝率を$+1$することができるか.
あと何回プレイするかを$[0, 10 ^9 + 5)$で二分探索.勝率が$+1$を満たす最も小さいものを求める.$\displaystyle \frac{won}{played}$の百分率に端数が無い場合にfloorを用いると$-1$してしまうので,その場合は$+1$して戻す.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
$N \leq 100000$の要素を持つ配列$R$を作る.$R$中の最大長方形を求める.最大長方形として使われる一番小さい要素を$1$つを全探索する.使う要素$i$を一つ決めると,それが一番小さいという仮定があるので,$[left, i]$と$[i, right]$のminが$R[i]$である必要があり,この条件を満たす端を求める二分探索をすることで答えが求まる.区間$[i, n)$で$min = R[i]$を満たす最も右端$right$と,$(-1, i]$で$min = R[i]$を満たす最も左端$left$が求まったとすると,$i$を一番小さい要素として使用した最大長方形は$R[i] * (right - left)$となる.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
文字列が与えられる.並び替えで作られる文字列の中で,辞書順で$k$番目にあたる文字列を答える.左端から文字を決めていき,順番を合わせていく.同じ文字があるために,残りの文字列の順列を出すために,残りも文字数だけではなくmapで管理する.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
$(startRow, startCol)$から$(endRow, endCol)$に移動したい.各マスは$k(1 \leq k \leq 9)$の種類があって,コストは$\frac{1}{k}$である.一回の移動はマスのコストの和が$1$以下でなければならない.何回の移動で$(endRow, endCol)$にたどり着けるか.
コスト和が$1$以下の$(x1, y1) \to (x2, y2)$を辺の重み$1$としてグラフを構成して,dijkstra.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
数列が与えられる.この数列を$k$個の数列に分け,それぞれの数列の分散の和を最小化したい.まず初めに$[i, j)$の分散を全て計算しておく.
$$ dp[i][j] := i番目までをj個に分けた時の分散の和の最小値 $$
として動的計画法.$j$番目まで見て$k+1$個に分ける時は,$[0, i)$と$[i, j)$に分けて$dp[i][k]$と$[i, j)$の分散の和を候補としてminを取っていく.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
$fac_k(n)$は次のように定義される.
$$ \begin{eqnarray} fac_k (n) &=& n\ \ \ if\ k >= n\\ fac_k (n) &=& n * fac_k(n - k)\ \ \ if\ k < n \end{eqnarray} $$
$n, k$が与えられるので,$fac_k(n)$を文字列で返す.$10 ^{18}$をより大きくなる場合は$overflow$を返す.
$n * fac_k(n - k)$が$10 ^{18}$より大きくなるかを判断したいが,そのままかけて比較すると実際に大きくなるときはオーバーフローしてしまうので,$10 ^ {18} >= i * ret$を$\frac{10 ^{18}}{i} >= ret$に変形する.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
$S_K(N)$は$N$の各桁を$K$乗した和と定義される.$S_2(65) = 6 ^2 + 5 ^2 = 61$である.$N$に対する数列は
$$ [N, S_K(N), S_K (S_K (N) ), …] $$
と定義される.$N$, $K$が与えられた時の$happiness$は数列の中の最小値である.$A, B, K$が与えられるので,$A \sim B$の各$happiness$の和を求める.
$A \sim B$のそれぞれの数について数列を求めるが,別の数列を求めていたとしても同じ数が途中に出現すればそれ以降は同じになるので,これをメモ化する.内容はその後の最小値である.最大値は$N = 999999, K = 6$の$2125764$であるが十分に余裕を持って配列を持った.後はそれぞれについて$happiness$を求め,その和を答える.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
$A \sim J$には,各々のアルファベットに$0 \sim 9$が対応する.全ての和の最大値を答える.まずは各アルファベットを1にして考えて,アルファベットごとの和を出す.この和が大きいものから数字を大きい順に当てはめていく.もし0で始まってしまう場合があったらそこはswapする.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
文字列$P1, P2, zeroCount$が与えられる.文字列$S$は$P1$を$1000000$回繰り返した後で$P2$を$1$回繰り返して連結する,この後に$P1$を$1000000$回繰り返した後で$P2$を$2$回繰り返して連結する…と$T$の長さが$10 ^{16}$以上になったら出来ないものとして考える.連続して'0'が$zeroCount$続く部分文字列がある時,その最初のindexを答える.
場合分けをたくさんした.$P1$が全て$0$, $P2$が全て$0$,そうでない場合と分けた.しっかり$P1$と$P2$の境目を考えなければいけなくて,適当にやったら非常にたくさんのWAを出した.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
$4$点が同じアルファベットである正方形は何個存在するか.正方形は,一辺が軸に平行でなければいけない訳ではないので,$2$点を選び,その$2$点を正方形の点として見て,アルファベットが一致しているかをみた.この方法では重複が発生するので,その分最後でちゃんと割ることを忘れない.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
数列が与えられる.各要素の中で$2$つ選びペアを作っても良い.ペアの場合は要素同士の積を取った後に,すべての(ペアを作っていないものも足して)和を最大化したい.
全てが正の数だった場合,大きいものから順番にペアを作っていけばよい.負の数がある場合,絶対値が大きいものから負の数同士でペアを作っていくのがよい.後はペアを作れない負の数があった場合,そのまま足してしまうと和の合計は下がってしまうので,もし$0$があれば,それで消す.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
コインの価値が与えられる.同じコインを何枚でも使って良いので$1 \sim X$を全て表せる,コインの枚数を最小化したい.
$$ dp[i] := 現在持っているコインで価値iを表せるか $$
として動的計画法.出来るだけ少ない枚数にしたいので,大きい数から減らせるだけ減らしていく.同じ配列を使ってしまうと何個も同じ数を使うdpになってしまうので,配列は分ける.最終的に$1 \sim X$全ての数字を表せているかをチェックする.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
$N$段目に$N$個のノードがあり,これを$R, G, B$の三色に乗り分けたい.各段には色が同じ数ではないといけない.その段に無い色はカウントしない.方法としては,一色に塗るか,二色に塗るか,三色に塗るかがある.
通り選び方があるのでかける.状態を$i$段目で各色が何色残っているかでメモ化した.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
全員が少なくとも一回は歌えるものの集合の中で,最小の要素数を答える.全ての歌を誰かしらが歌える条件での人数の最小化だと思っていて,全然ダメだった.歌は$10$までしかないので部分集合を全部列挙して,共通集合が無ければ歌えないので選べない.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
文字列の集合の全ての要素が,他の要素で始まっていない時に$prefix-free$という.与えられた文字列集合の部分集合の内,$prefix-free$である集合の個数を答える.
重複をどう列挙すればいいの全然分からなかった.解説を見た. $$ dp[i] := i番目以降のprefix-freeの集合の個数 $$ として動的計画法.基本的に,$dp[i+1]$が分かっているときに,$i$番目の文字列を追加したい場合は,その文字列を選ぶ場合と選ばない場合の$2$通りがあるので単純に$2$倍で良い.しかし,選ぶ場合に$prefix-free$になってしまってはいけないので,そうではない所から遷移させる.一度辞書順でsortしてしまえば,$pfefix$が同じ場合はsort後に隣接しているはずなので,同じにならない所にまで$1$個ずつずらせばよい.このずらした場所を$j$とすると,$i$番目の文字を選ばない時は$dp[i+1]$,選ぶ時は$dp[j]$なのでこれらの和が$dp[i]$となる.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
与えられた数より大きいく最も小さい回文数を答える.文字列で与えられて最大50桁あるので,愚直に回文数を列挙しても間に合わない.桁の半分まで見て,それを反転して繋げたものがすでに大きければ解になる.そうではない場合は$1$足して反転する.気をつけなければいけないケースは$9, 99, 999$などの$1$足した時に桁が増えるもので,元の数よりも$1$桁増やせば十分なので偶奇で場合分けして調整する.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|