TopCoder SRM 398 DIV 2

Problem Check Points
250 o 237.52
500 x -
900 o 524.99

55分ぐらいで完走。まあ500は凡ミスしてしまったけど、全体的にはよかったと思います。

TopCoder Statistics

@uwitenpen

Problem 250 MinDifference

You are given numbers A0, X, Y, M and n. Generate a list A of length n according to the following recurrence relation:


A[0] = A0
A[i] = (A[i - 1] * X + Y) MOD M, for 0 < i < n


Return the minimal absolute difference between any two elements of A.

TopCoder SRM 398 DIV2 Problem250 MinDifference

Problem 500 CountExpressions

You are helping your brother with his homework assignment. His teacher gave him two distinct numbers x and y, and asked him to use those numbers to form as many different expressions as possible. Each expression must satisfy all of the following rules:

The only allowed operators are '+', '-' and '*'.
x and y must each appear exactly twice. No other numbers are allowed.
The result of the expression must be equal to val.

In other words, each expression can be written in the form "a op1 b op2 c op3 d", where each of op1, op2 and op3 is '+', '-' or '*', and among the numbers a, b, c and d, exactly two are equal to x and the other two are equal to y. Please note that the unary minus is not allowed (see example 0). Expressions are calculated from left to right, and there is no operator precedence. For example, to calculate the result of "2 + 2 * 3 + 3", you would first calculate 2 + 2, then multiply the result by 3, and then add 3 to get 15.

Return the total number of different expressions that can be formed. Two expressions are considered different if their string notations (as described in the previous paragraph) are different. For example, the expressions "2 + 3 - 2 - 3", "2 - 2 + 3 - 3" and "2 - 3 - 2 + 3" are all different.

next_permutationを使っておきながらsortをし忘れるという愚行をする。そりゃ不正解にもなるわ・・・

TopCoder SRM 398 DIV2 Problem500 CountExpressions

Problem 900 MatchString

You are given a goal word as a String matchString and puzzle words as a String[] matchWords. The number of puzzle words is equal to the number of letters in the goal word. Assume all letters in all words have the same width and height.

You want to play a game. At the beginning of the game, all the words from matchWords are arranged one below another, in the order that they're given. The words are horizontally aligned so that the first letters of all the words form a vertical line. You may then shift each of the words any number of places (zero or more) to the right, where one place is the width of a single letter. The goal of the game is to shift the puzzle words such that the goal word can be read vertically from top to bottom in a straight line. See examples for clarification.

Your score is the sum of the number of places each puzzle word was shifted. Return the minimal score you can obtain while achieving your goal, or -1 if it is impossible.

Medium並の難易度。"matchString will contain the same number of characters as the number of elements in matchWords."の制限がないと、とたんに難しくなったと思う。

TopCoder SRM 398 DIV2 Problem900 MatchString