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

32309번 - What's the Order Anyway? 다국어

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

문제

Alice, Bob, Carol, Denise, Eddie and Frank are up to their usual tricks. They're performing in the local comedy show but haven't told you the order in which they are presenting their stand-up routines. Instead, they've given you cryptic clues such as (with A standing for Alice, B for Bob, C for Carol, D for Denise, E for Eddie and F for Frank):

  • A > B
  • F < A
  • not C D

The first clue means that A is performing before B. The second clue means that F is performing after A. The third clue means that C and D are not performing consecutively. (In essence, if we were treating the acts as numbers, the inequality signs are assuming that the acts are sorted from greatest to least.)

Given the above clues, a possible order for the acts is Alice, Carol, Bob, Denise, Frank, Eddie.

What you've realized is that even with their clues, it might be impossible to pin down the exact order of their acts. Thus, you've settled for figuring out how many orderings are possible given the clues they've given you.

Given clues about the order of comedy acts, determine the number of valid possible orderings for the acts.

입력

The first input line contains two space-separated integers: n (2 ≤ n ≤ 10), indicating the number of comedy acts, and c (1 ≤ c ≤ 10), indicating the number of clues you've been provided. The acts are denoted by the first n uppercase letters.

The clues are provided in the following input lines, one clue per line. Each of these input lines has three space-separated pieces of information: a (1 ≤ a ≤ 3), x and y, as described below:

  • x and y are guaranteed to be distinct uppercase letters out of the first n letters,
  • a represents the type of restriction where 1 indicates that x's act comes before y's, 2 indicates that x's act comes after y's and 3 indicates that x's act and y's act don't occur consecutively (in either order).

It's guaranteed that the input clues won't be contradictory, and that there will be at least one valid ordering of the comedy acts.

출력

Print the number of different orders in which the comedy acts could be.

제한

예제 입력 1

6 3
1 A B
2 F A
3 C D

예제 출력 1

160

예제 입력 2

3 2
1 C A
2 B A

예제 출력 2

1

힌트

출처

University > University of Central Florida > 2024 Local Programming Contest (Qualifying Round) 5번

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

출처

대학교 대회

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

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