#P6916. Window Manager Simulator

    ID: 20123 Type: Default 1000ms 256MiB

Window Manager Simulator

Window Manager Simulator

You are required to build a simulator for a window manager for next generation smartphones. The smartphone screen is a rectangle and may display several non‐overlapping rectangular windows. Initially, no windows are open. Your simulator must support the following commands:

  • OPEN \(x\ y\ w\ h\) — Open a new window whose top-left corner is at \((x,y)\) with width \(w\) and height \(h\). The window must lie completely inside the screen and must not overlap any existing window.
  • CLOSE \(x\ y\) — Close the window that includes the pixel \((x,y)\). (Since windows do not overlap, at most one window includes this pixel.)
  • RESIZE \(x\ y\ w\ h\) — Resize the window that includes the pixel \((x,y)\) so that its new dimensions become \(w\) by \(h\). The top-left corner remains unchanged. The resized window must lie entirely within the screen and must not overlap any other window.
  • MOVE \(x\ y\ d_x\ d_y\) — Move the window that contains the pixel \((x,y)\). The movement is exclusively horizontal (if \(d_x\) is nonzero) or vertical (if \(d_y\) is nonzero). The window is moved by as many pixels as possible, up to the requested \(d_x\) or \(d_y\). If the moving window bumps into another window, it pushes that window in the same direction. This push may cascade to other windows. A window moves only if it can be shifted by one pixel without leaving the screen. If any window in the chain cannot move, the entire move for that pixel is cancelled. The move command repeats this one-pixel move until no further pixel can be moved or until the requested displacement is achieved.

The coordinate system has its origin at the top-left of the screen.

inputFormat

The first line of input contains two integers \(S_W\) and \(S_H\) representing the screen's width and height.

The second line contains an integer \(N\), the number of commands to process.

Each of the following \(N\) lines contains one command, which will be one of the following four types:

  • OPEN x y w h
  • CLOSE x y
  • RESIZE x y w h
  • MOVE x y d_x d_y

All values are integers. For the MOVE command, exactly one of \(d_x\) and \(d_y\) will be nonzero.

outputFormat

After processing all the commands, output the final state of the open windows. The first line should contain a single integer \(K\), the number of open windows. Then, for each open window in the order they were opened, output a line with four integers: the \(x\) and \(y\) coordinates of its top-left corner, followed by its width and height.

Note that if a command fails (for instance, if a window would exceed the screen boundaries or overlap with another window), it is simply ignored.

sample

100 100
4
OPEN 10 10 20 20
OPEN 40 10 20 20
MOVE 15 15 30 0
RESIZE 42 12 15 25
2

40 10 15 25 70 10 20 20

</p>