Logo
(追記) (追記ここまで)

33592번 - Scooter 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 2048 MB98888.889%

문제

The Czech Technical University campus consists of $n$ buildings, indexed from 1ドル$ to $n$. In each building, there can be a math class scheduled, or a computer science class, or neither (but not both). Additionally, in each building, there is at most one professor, and each professor is either an expert in mathematics or in computer science.

As an intern at University Express Inc., your job is to quickly transport the professors to their classes. For this, you have been granted a brand new two-person scooter, able to accommodate yourself, plus at most one passenger.

Initially, you are the only person on the scooter. When you arrive at a building, you may drop off or pick up professors to/from that building. However, in order to improve the efficiency of your task, you are allowed to drive to each of the $n$ buildings at most once, in the order of your choice (you can also decide where to start the itinerary).

After the end of your itinerary, in each building where a math class is scheduled, there must be a professor expert in math, and in each building where a computer science class is scheduled, there must be a professor expert in computer science.

Devise an itinerary that makes it possible to teach all classes.

입력

The first line contains an integer $n$ (1ドル ≤ n ≤ 2000$) — the number of buildings in the campus.

The second line contains a string of $c$ of length $n$ consisting of the characters -, C, M — the $i$-th character denotes the subject of the class scheduled in the $i$-th building. C stands for computer science, M stands for mathematics, while - means that there is no class scheduled in the $i$-th building.

The third line contains a string $p$ of length $n$ consisting of the characters -, C, M — the $i$-th character denotes the expertise of the professor in the $i$-th building (if there is a professor). C stands for computer science, M stands for mathematics, while - means that there is no professor in the $i$-th building.

It is guaranteed that, for all tests given to your program, there exists a valid itinerary.

출력

In the first line print an integer $l$ — the number of operations in your chosen itinerary.

The $i$-th (1ドル ≤ i ≤ l$) of the next $l$ lines must contain one of three commands:

  1. DRIVE $x$ — go to the building with the number $x$ (1ドル ≤ x ≤ n$);
  2. PICKUP — pick up the professor which was initially at the current building;
  3. DROPOFF — drop off the passenger professor at the current building.

In order for the itinerary to be valid, the following conditions must hold:

  1. No two DRIVE instructions should go to the same building;
  2. At most one DROPOFF and one PICKUP instruction in this order should be issued at each specific building;
  3. For all PICKUP instructions, there must be a professor initially at the building, as well as no one already riding along on the scooter;
  4. For all DROPOFF instructions, there must be a professor riding along at the time of the command;
  5. After the itinerary, in each building, if there is a class in that building, there must be a professor expert in the class’ subject (either initially, or because they were dropped off there).

Note that, in particular, you cannot pick up a professor that you just dropped off for an itinerary to be valid.

제한

예제 입력 1

3
CM-
-CM

예제 출력 1

7
DRIVE 3
PICKUP
DRIVE 2
DROPOFF
PICKUP
DRIVE 1
DROPOFF

You start by driving to building number 3ドル$. You then pick up the mathematics professor. After dropping him off at building number 2ドル,ドル where a mathematics class is being held, you pick up the computer science professor from there, and drop her off at building number 1ドル,ドル finishing your itinerary.

예제 입력 2

1
C
C

예제 출력 2

0

예제 입력 3

2
-M
MC

예제 출력 3

4
DRIVE 1
PICKUP
DRIVE 2
DROPOFF

힌트

출처

ICPC > Regionals > Europe > European Championship > The 2024 ICPC European Championship G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /