Baseball Game (APCS 2016-10 Expert)

1.0s 256M

Nine players bat cyclically in the order \(1,2,\ldots,9,1,2,\ldots\). Their batting results are supplied separately for each player. Reconstruct chronological order and simulate the score.

For 1B, 2B, or 3B, the batter and every existing runner advance by \(1\), \(2\), or \(3\) bases respectively. On HR, the batter and all runners reach home. Every runner reaching home scores one run. Each of SO, FO, and GO adds one out without advancing runners. After every third out, clear all bases and continue with the next batter. Initially the bases are empty and both score and out count are zero.

Given \(b\), find the total score when the \(b\)-th out occurs. Ignore later batting results.

Input Format

The input has ten lines. For each of the nine players in order, one line contains the batting count \(a_i\) followed by that player’s \(a_i\) result strings in chronological order. The tenth line contains \(b\).

Output Format

Print the total score when the \(b\)-th out occurs.

Constraints

\(1\le a_i\le5\), \(1\le b\le27\). Every result is one of 1B, 2B, 3B, HR, SO, FO, GO. The records follow the cyclic batting order without missing turns and include at least \(b\) outs.

Scoring

  • 20 points: Only HR and SO occur.
  • 20 points: The only hit type is 1B, and \(b=3\).
  • 20 points: \(b=3\).
  • 40 points: No additional restrictions.

Each scored test is worth 5 points.

Sample Input 1

5 1B 1B FO GO 1B
5 1B 2B FO FO SO
4 SO HR SO 1B
4 FO FO FO HR
4 1B 1B 1B 1B
4 GO GO 3B GO
4 1B GO GO SO
4 SO GO 2B 2B
4 3B GO GO FO
3

Sample Output 1

0

Sample Input 2

5 1B 1B FO GO 1B
5 1B 2B FO FO SO
4 SO HR SO 1B
4 FO FO FO HR
4 1B 1B 1B 1B
4 GO GO 3B GO
4 1B GO GO SO
4 SO GO 2B 2B
4 3B GO GO FO
6

Sample Output 2

5

Source

APCS 2016-10 public archive version: c297

Problem page help

Keyboard shortcuts

Main features

  • Sample tests — Runs the sample cases bundled with the problem and auto-compares against the expected output.
  • Custom test — Run your code with your own stdin. Optionally tick the "Compare with expected (diff)" box to verify against expected output line-by-line.
  • Template — Paste the default code template you set on your profile page.
  • Collab — Edit this problem together with classmates in real time.
  • Auto-draft — Editor contents auto-save to your browser every 1.5 seconds (per account / problem / language).
  • Submit — Send your code to the judge for grading; returns AC / WA / TLE etc.

Limits

  • Source code: at most 65,536 characters
  • Custom test stdin and expected output: at most 1 MB each (≈1 million characters)
  • Custom test and sample test share the sandbox; about 1 request per 3 s per user (sample test: 1 per 1 s)
  • Custom test and sample test both have a 15 second wall-clock cap (the official judge still uses the problem time limit)
  • Interactive problems do not offer custom test (cannot simulate interaction with the judge).
  • Submitting has no rate limit, but rapid repeated submissions on the same problem are treated as score farming.