RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 R03697

J4. Wait Time

설명

You exchange text messages with your friends. Since you receive so
many messages, you want to measure how long your friends have to wait
for your replies.

Your message device records each received and sent message in order
using the following two kinds of entries:

  • R X indicates a message was received
    from a friend numbered \(X\);

  • S X indicates a message was sent to a
    friend numbered \(X\).

Your message device sends and receives messages instantaneously, and
for each consecutive pair of entries described above, either

  • a single entry W X is recorded in
    between them indicating they occur \(X\) seconds apart, or

  • there is no entry between them and they occur one second
    apart.

Several rules of message etiquette are always followed:

  • the only messages you send are replies to messages that you have
    received;

  • you send at most one reply to any message from any particular
    friend;

  • your friends do not send a subsequent message until you have
    replied to their previous message.

The wait time for a message is the time that passes between when you
receive it and the time you reply to it. If a friend \(X\) received a reply to each message they
sent, the total wait time for friend \(X\) is the sum of all wait times for all
messages from friend \(X\). Otherwise,
the total wait time for friend \(X\) is
\(-1\).

Your job is to determine the total wait time for each friend.

제약
입력 형식

The input consists of the integer \(M\) (\(1 \leq M \leq 20\)), followed by \(M\)
lines, where each line consists of one character
(W, R, or
S), followed by a space, followed by an
integer \(X\) (\(1 \leq X \leq 100\)). These \(M\) lines are the entries described above
(in order).

출력 형식

Output one line for each friend that sent a message in the form \(X\) \(T\)
where \(X\) is a friend number and
\(T\) is the total wait time for friend
\(X\). The lines are in increasing
order of the friend numbers.

예제 1
입력
5
R 2
R 3
W 5
S 2
S 3
출력
2 6
3 6
설명

Friend 2 sends a message at time \(0\) and Friend 3 sends a message at time
\(1\). Friend 2 receives a reply at
time \(6\) and Friend 3 receives a
reply at time \(7\).

예제 2
입력
14
R 12
W 2
R 23
W 3
R 45
S 45
R 45
S 23
R 23
W 2
S 23
R 34
S 12
S 34
출력
12 13
23 8
34 2
45 -1
설명

For Friend 12, a message is received at time 0 and replied to at time
13. For Friend 23, two messages are exchanged, with the first message
having a wait time of 6 seconds and the second message having a wait
time of 2 seconds. For Friend 34, a message is received at time 10 and
replied to at time 12. Friend 45 sends a message which is never replied
to.

문제 정보

생성자가 기록되지 않았습니다.

출처 CCC 2015 Junior

평가 및 의견

J4. Wait Time

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

J4. Wait Time

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8