TopCoder SRM 394 DIV 2

Problem Check Points
250 o 144.51
500 o 312.32
1000 - -

500が解けて僕満足!


Problem 250 MountainWalk

You are in a mountainous area which is represented by a String[] areaMap. The j-th character of the i-th element of the areaMap is a digit '0'-'9' representing the height of cell (i, j). You perform a walk in the area according to the following rules:

  • You start from cell (0, 0).
  • If you are in cell (i, j), you examine cells (i+1, j), (i, j-1), (i-1, j), (i, j+1) in this order. You go to the first of these cells you can enter. You can enter a cell if it is still on the map, you haven't been to it before and the difference between the heights of your current cell and the cell you want to enter is no bigger (in absolute value) than heightDifference.
  • You end your walk if you can not make another move, i.e., if you can not enter any neighboring cell.

You must return the number of cells that you visit while performing your walk. You visit cell (i, j) if and only if you enter cell (i, j) at some point during your walk (the starting cell (0, 0) also counts as entered, i.e., you definitely visit (0, 0)). Note that you will visit each cell at most once since you never enter the same cell twice.

"in this order"という部分を読み飛ばしてて「これ250か!?」とか思ってて無駄に時間かかった。

TopCoder SRM 394 DIV2 Problem250 MountainWalk

Problem 500 RoughStrings

Given a string s, its roughness is calculated as follows: Let c1 be the letter that appears most frequently in s, and let c2 be the letter that appears least frequently (c2 must appear at least once). The roughness of s is the number of occurrences of c1 minus the number of occurrences of c2.

You are allowed to modify s by erasing between 0 and n characters, inclusive (see example 1 for clarification). Return the minimum possible roughness that can be achieved by such a modification.

roughnessを減らすには、アルファベット出現回数の「最大値を減らす」または「最小値を消す」の2種類。(最小値は完全に消さないとむしろ増える)これを全探索するようにしました。

TopCoder SRM 394 DIV2 Problem500 RoughStrings

Problem 1000 ProperDivisors

An integer k greater than 0 is called a cool divisor of m if it is less than m and divides m, but k^n does not divide m. Let d(m) denote the number of cool divisors that exist for an integer m. Given two integers a and b return the sum d(a) + d(a + 1) + ... + d(a + b).


範囲が鬼や!ということで太刀打ちできず。突如参戦した@LayCurseさんの美麗すぎるコードに魅了されました。約数の出し方がとても参考になります。

TopCoder SRM 394 DIV2 Problem1000 ProperDivisors