Log inSign up
Problems / A003

Comparing combat power

300 ptsCases 18Set by dongbinna
Added October 30.

Statement

There are N seats laid out in a row. There are also N warriors numbered 1 through N, and each warrior must be placed in one seat. Every warrior has an individual combat power. Combat powers may be equal to each other, and each one is a natural number from 1 to 20.

When the N warriors are placed, N-1 conditions on adjacent seats must hold. The conditions are numbered 1 through N-1, and they mean the following.

Condition 1: the condition on seat 1 and seat 2 Condition 2: the condition on seat 2 and seat 3 … Condition N-1: the condition on seat N-1 and seat N

Each condition is one of the natural numbers 1, 2, 3 and 4, and the values mean the following.

1) Value 1: the warrior in the left seat has higher combat power than the warrior in the right seat. 2) Value 2: the warrior in the left seat has lower combat power than the warrior in the right seat. 3) Value 3: the warrior in the left seat and the warrior in the right seat have the same combat power. 3) Value 4: no condition has to hold at that position.

Write a program that prints the number of ways to place the warriors so that the conditions hold.

For example, let N=5, and let the combat powers of warriors 1 through N be 7, 10, 7, 5, 3 in order. Let the conditions be 3, 1, 2, 4. Placing the warriors in the order 1, 3, 5, 2, 4 satisfies the conditions as shown below.

In the figure, a condition with value 1 is drawn as ">", value 2 as "<", value 3 as "=", and value 4 as an empty box.

> (The placement figure from the original document was lost during text extraction.)

Placing the warriors in the order 3, 1, 5, 4, 2 also satisfies the conditions, as shown below.

> (The placement figure from the original document was lost during text extraction.)

So in this example there are 6 ways in total to place the warriors.

Input and Output Examples

Example 1

Input

5, [7, 10, 7, 5, 3], [3, 1, 2, 4]

Output

6

Example 2

Input

3, [4, 5, 6], [1, 2]

Output

2

Input

  • First the number of warriors N is given as a natural number. N is a natural number less than or equal to 10.

  • Next an array arr is given, holding the combat power of each of the N warriors numbered 1 through N. Each combat power is a natural number from 1 to 20.

  • Next an array conditions is given, holding the conditions numbered 1 through N-1. Each condition is one of the natural numbers 1, 2, 3 and 4.

Output

  • Return the number of ways to place the warriors so that the conditions hold, as a natural number.

Requirements

  • You must write a solution(N, arr, conditions) function and return the answer
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
  • There are 18 cases, and 5 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 18 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

5 public cases. Judging also uses hidden cases. You have to pass all 18 cases to solve this.

Input
Expected output
5, [7, 10, 7, 5, 3], [3, 1, 2, 4]
6
3, [4, 5, 6], [1, 2]
2
10, [14, 14, 3, 12, 11, 19, 17, 19, 5, 11], [1, 4, 2, 1, 2, 4, 3, 4, 1]
9352
6, [8, 8, 1, 6, 6, 20], [3, 3, 2, 3, 2]
0
4, [2, 17, 20, 18], [1, 2, 4]
8

Notes

Background that helps with solving. The rules you have to follow are in the input and output specs and the requirements above.

This is problem 1 of practice test 3 in the original.

The numbers labelling the condition descriptions run 1) 2) 3) 3) in the original. The last 3) is the fourth condition.

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 325ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 5 public cases. Submitting runs the hidden cases too.

People who solved this problem

Nobody yet. You could be the first.