Connection Status:
Competition Arena > PosNegDice
SRM 783 · 2020-03-30 · by misof · Simple Math, Simple Search, Iteration
Class Name: PosNegDice
Return Type: int[]
Method Name: evaluateRoll
Arg Types: (int, vector<int>, vector<int>)
Problem Statement

Problem Statement

This problem is about a specific way of rolling the dice in one franchise of tabletop RPG games.

Whenever the player attempts a non-trivial action, the action is evaluated as follows:

  • The game master sets the target value T based on the player's skill.
  • The game master gives the player some 6-sided dice to roll. Each die is either positive or negative.
  • The player rolls all the dice.
  • As long as there is a positive and a negative die with the same value, a pair of such dice is removed from the roll.
  • At this point, if there is a positive die with value less than or equal to the target, the roll is a success, otherwise it is a failure.
  • Each negative die that was not removed counts as a point of stress for the player.

You are given the target T and two int[]s: positiveDice and negativeDice. Return a int[] with two elements {X, Y}:

  • X should be 1 if the roll was a success and 0 if it was a failure.
  • Y should be the number of points of stress the roll produced.

Constraints

  • T will be between 1 and 5, inclusive.
  • positiveDice will contain between 0 and 500 elements, inclusive.
  • negativeDice will contain between 0 and 500 elements, inclusive.
  • Each element of positiveDice will be between 1 and 6, inclusive.
  • Each element of negativeDice will be between 1 and 6, inclusive.
Examples
0)
1
{1, 6, 2}
{6}
Returns: {1, 0 }

The player rolled four dice: three positive dice and one negative die. The positive dice rolled 1, 6, and 2. The negative die rolled a 6. After the roll, one pair of dice is removed: a positive die with value 6 and a negative die with value 6. The player is left with two positive dice. These have values 1 and 2. As one of the dice is less than or equal to T = 1, the roll is a success. As there are no negative dice left, the player does not receive any stress points.

1)
4
{}
{}
Returns: {0, 0 }

There are no dice at all, so the roll is automatically a failure (as there is no positive die with a value that is small enough). On the positive side, there is also no stress.

2)
4
{5, 6, 6, 5, 5}
{}
Returns: {0, 0 }

A failure (all positive dice rolled numbers that are bigger than the target) but with no stress.

3)
5
{3, 6, 3, 6}
{3, 3, 1, 3, 6, 3, 5}
Returns: {0, 4 }

Twice we remove a positive 3 and a negative 3. Once we remove a positive 6 and a negative 6. We are left with positiveDice = {6} and negativeDice = {1, 3, 3, 5}. The roll is a failure (the remaining positive die is too large) and the player receives four points of stress.

4)
4
{4, 5, 6}
{1, 2, 3}
Returns: {1, 3 }

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 PosNegDice with a public method vector<int> evaluateRoll(int T, vector<int> positiveDice, vector<int> negativeDice) · 101 test cases · 2 s / 256 MB per case

Submitting as anonymous