Connection Status:
Competition Arena > MultiRead
SRM 305 · 2006-05-31 · by vorthys · Simple Math
Class Name: MultiRead
Return Type: int
Method Name: minCycles
Arg Types: (string, int)
Problem Statement

Problem Statement

In many computer systems, multiple processes can read from the same resource during the same clock cycle, but only a single process can write to the resource during a clock cycle. Reads and writes cannot be mixed during the same clock cycle. Given a history of the reads and writes that occurred during a particular computation as a String trace, and an int procs representing the number of processes used by the computation, calculate the minimum duration of the computation in clock cycles. The trace represents each read as an 'R' and each write as a 'W'.

For example, if trace is "RWWRRR" and procs is 3, then the minimum number of clock cycles is 4: one for the first read, one each for the two writes, and one for the last group of reads.

Constraints

  • trace will contain between 1 and 50 characters, inclusive.
  • Each character in trace will be 'R' or 'W'.
  • procs will be between 1 and 10, inclusive.
Examples
0)
"RWWRRR"
3
Returns: 4

The example above.

1)
"RWWRRRR"
3
Returns: 5

Now the final group of 'R's takes two cycles.

2)
"WWWWW"
5
Returns: 5
3)
"RRRRRRRRRR"
4
Returns: 3
4)
"RWRRWWRWRWRRRWWRRRRWRRWRRWRRRRRRRRRWRWRWRRRRWRRRRR"
4
Returns: 30

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

Coding Area

Language: C++17 · define a public class MultiRead with a public method int minCycles(string trace, int procs) · 41 test cases · 2 s / 256 MB per case

Submitting as anonymous