MultiRead
SRM 305 · 2006-05-31 · by vorthys
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
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.
"RWWRRR" 3 Returns: 4
The example above.
"RWWRRRR" 3 Returns: 5
Now the final group of 'R's takes two cycles.
"WWWWW" 5 Returns: 5
"RRRRRRRRRR" 4 Returns: 3
"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.
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