Connection Status:
Competition Arena > GreaterGameDiv2
SRM 637 · 2014-08-25 · by snuke · Simple Search, Iteration
Class Name: GreaterGameDiv2
Return Type: int
Method Name: calc
Arg Types: (vector<int>, vector<int>)
Problem Statement

Problem Statement

Cat Snuke and wolf Sothe are playing the Greater Game. The game is played with cards. Each card has a number written on it. There are 2N cards. The numbers on the cards are the integers between 1 and 2N, inclusive.


At the beginning of the game, each player gets N of the cards and chooses the order in which he wants to play them. The game then consists of N turns. In each turn, both players play one of their cards simultaneously. The player who revealed the card with the larger number gets a point.


You are given two int[]s: snuke and sothe. The elements of snuke are the numbers on the cards Snuke is going to play, in order. Similarly, the elements of sothe are the numbers on the cards Sothe is going to play, in order. Compute and return the number of points Snuke will have at the end of the game.

Constraints

  • N will be between 1 and 50, inclusive.
  • snuke and sothe will contain exactly N elements each.
  • Each integer in snuke and sothe will be between 1 and 2N, inclusive.
  • The integers in snuke and sothe will be distinct.
Examples
0)
{1,3}
{4,2}
Returns: 1

Snuke loses the first round because 1 is less than 4. Snuke then wins the second round because 3 is greater than 2.

1)
{1,3,5,7,9}
{2,4,6,8,10}
Returns: 0
2)
{2}
{1}
Returns: 1
3)
{1}
{2}
Returns: 0
4)
{1,2,3,4,5}
{6,7,8,9,10}
Returns: 0

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

Coding Area

Language: C++17 · define a public class GreaterGameDiv2 with a public method int calc(vector<int> snuke, vector<int> sothe) · 68 test cases · 2 s / 256 MB per case

Submitting as anonymous