Connection Status:
Competition Arena > RockPaperScissorsMagic
SRM 653 · 2015-01-29 · by dreamoon · Math, Simple Search, Iteration
Class Name: RockPaperScissorsMagic
Return Type: int
Method Name: count
Arg Types: (int, int, int, vector<int>)
Problem Statement

Problem Statement

Alice and Bob are going to play a variant of the traditional rock-paper-scissors game. Their game is played using cards. Each card shows one of the three pictures: a rock, a paper, or scissors. There is a sufficient supply of cards of each type. Bob has already chosen a sequence of cards and he has arranged them into a row, face down. It is now Alice's turn to do the same. Once she does that, they will use the two sequences of cards to play the game: For each i, Alice's i-th card and Bob's i-th card will be revealed and compared using the standard rules of rock-paper-scissors. The winner of each such game gets win points and the loser gets lose points. In case of a draw, each player gets tie points.

Alice has noticed that somebody has marked Bob's cards. Using those marks she can tell which cards have the same picture but she has no idea what that picture is. You are given this information as a int[] card. Each element of card is between 0 and 2, inclusive. Each of the numbers represents one type of pictures. (For example, it is possible that each 0 is a rock, each 1 are scissors, and each 2 is a paper.)

Alice wants to surprise Bob by giving an accurate prediction: She will announce her final score, then she will lay down her sequence of cards, and finally they will reveal all cards, add together all the scores, and presto: Alice's final score will match the score she announced at the beginning.

You are given the ints win, lose, tie, and the arrangement of Bob's cards. Let X be the number of ways in which Alice can perform the above trick and be sure that it succeeds. Two ways are considered different if she either announces a different final score, or if she chooses a different sequence of cards. Return the value (X modulo 1,000,000,007).

Constraints

  • The number of elements in card will be between 1 and 1,000, inclusive.
  • Elements in card will be between 0 and 2, inclusive.
  • win, lose,and tie will be between 0 and 1,000, inclusive.
Examples
0)
2
0
1
{0,1,2}
Returns: 3

There are 2 points for a win, 0 for a loss, and 1 for a tie. Bob has played three different cards. In this setting there are three ways how Alice can perform her trick. In each of the ways she will announce that she will score 3 points. Then, she will play three cards of the same type.

1)
2
0
1
{0,0,0}
Returns: 6

The scores for win/loss/draw are the same as in Example 0 but now Bob has played three cards of the same kind. Alice should announce that she will score 3 points, and then she should play three distinct cards. There are 3! = 6 ways in which Alice can order the cards she plays.

2)
0
0
0
{1,0,2,2,2,0}
Returns: 729
3)
514
451
145
{0,0,0,0,0,1,1,1,1,1,1,2,2,2}
Returns: 0
4)
3
6
9
{0,0,0,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2}
Returns: 2336040

Submissions are judged against all 101 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class RockPaperScissorsMagic with a public method int count(int win, int lose, int tie, vector<int> card) · 101 test cases · 2 s / 256 MB per case

Submitting as anonymous