#P1580. Queue Bombing

    ID: 14866 Type: Default 1000ms 256MiB

Queue Bombing

Queue Bombing

This problem simulates a "bombing" attempt by a rotating trio of attackers against a target. The three attackers are identified by their id as \(\mathtt{Huntfire}\), \(\mathtt{redbag}\) and \(\mathtt{absi2011}\), appearing in that order repeatedly. The target, however, is fixed as soha (i.e. the statement will output messages with @soha).

The input consists of \(n\) messages in order. Every message is a string which may (or may not) contain exactly one @ character. A message that contains exactly one @ is considered a potential element of a "queue shape". In a valid queue element, the substring immediately following @ is interpreted as a target name according to the rule below:

  • Locate the single occurrence of @ in the message, and then extract the target name as the first three tokens (separated by whitespace) immediately following @. For example:
  • The message yyy loves OI : @yyy loves Microelectronic has target name yyy loves Microelectronic.
  • The message yyy loves Maths : @yyy loves Microelectronic 我佩服soha的出题效率 yields the same target name yyy loves Microelectronic (ignoring extra commentary).
  • The message yyy loves OI : @yyy loves Microelectronic +1 also yields yyy loves Microelectronic.
  • Note that the @ may appear anywhere in the line (for instance, after a +1 in yyy loves Chemistry : +1 @yyy loves Microelectronic).

The very first message that is valid (i.e. contains exactly one @) determines the expected target name \(T\). Every subsequent valid message must also produce the same target name \(T\) (when using the above extraction). Otherwise, the "queue shape" is said to be broken.

If the queue is broken at some line \(i\) (1-indexed) by an attacker, then normally the bombing attempt is unsuccessful and the program should output:

  1. In the first line: Unsuccessful @soha attempt
  2. In the second line: the line number \(i\) where the break occurred followed by the breaker's id (i.e. one of \(\mathtt{Huntfire}\), \(\mathtt{redbag}\), or \(\mathtt{absi2011}\)). Here, the id is denoted by \(\mathtt{id}\) in LaTeX as \(\texttt{\text{id}}\).

However, there is an exception: if the attacker who causes the break has already posted a message earlier (i.e. this is not his first turn) or he is himself the one breaking the queue (which is always the case when a break occurs), then the bombing attempt is deemed successful and the program should output only:

  • Successful @soha attempt

If no break ever occurs (i.e. every valid message extracts the same target name), then after processing all \(n\) messages the bombing attempt is unsuccessful and the program should output:

  1. In the first line: Unsuccessful @soha attempt
  2. In the second line: the total number of valid queue messages (the queue length).
  3. In the third line: Good Queue Shape

The attackers post messages in cyclic order: the 1st message is from \(\mathtt{Huntfire}\), the 2nd from \(\mathtt{redbag}\), the 3rd from \(\mathtt{absi2011}\), the 4th again from \(\mathtt{Huntfire}\), and so on.


Input Format:

The first line contains a positive integer \(n\) (the number of messages). The following \(n\) lines each contain a message (a non-empty string).

Output Format:

  • If the queue is broken and the breaker's condition is not met for success, output two lines:
    • The first line is: Unsuccessful @soha attempt
    • The second line contains the breaking line number and the breaker's id (separated by a space).
  • If the break occurs but the breaker qualifies for success, output a single line: Successful @soha attempt.
  • If no break occurs by the end, output three lines:
    1. Unsuccessful @soha attempt
    2. The queue length (i.e. the number of valid messages).
    3. Good Queue Shape

inputFormat

The input starts with a single integer \(n\) (where \(n \ge 1\)), denoting the number of messages. Then \(n\) lines follow, each representing a message that a participant posts. Each message is a string that may or may not contain exactly one @ character.

outputFormat

Depending on the simulation outcome, output as follows:

  • If the queue is broken by a message that does not qualify for a successful bombing (i.e. the attacker breaking the queue has not spoken before), output two lines: the first line should be Unsuccessful @soha attempt and the second line should contain the 1-indexed line number where the break occurred and the attacker's id, separated by a space.
  • If a break occurs but the breaker qualifies (has already spoken before or is himself breaking the queue), output a single line: Successful @soha attempt.
  • If no break occurs throughout the input, output three lines: the first line as Unsuccessful @soha attempt, the second line is the total number of valid (@-containing) messages (i.e. the queue length), and the third line as Good Queue Shape.

sample

3
yyy loves OI : @yyy loves Microelectronic
yyy loves Maths : @yyy loves Microelectronic 我佩服soha的出题效率
yyy loves Chemistry : +1 @yyy loves AnotherTarget
Unsuccessful @soha attempt

3 absi2011

</p>