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

K. Knitpicking

설명

Kattis has many pairs of nice, warm, knit socks in her sock drawer that are perfect for the winter. These socks come in a wide range of colours and types, and have all been mixed together. Each morning Kattis needs to pick two matching socks.

To find matching socks, she simply randomly takes single socks out of the drawer until she has a matching pair. It may take a long time, for example when she keeps drawing right socks without a matching left one. How long does she need to keep drawing socks until she is guaranteed to have a pair to wear?

제약
입력 형식

The input consists of:
- One line with an integer \(n\) (\(1 \leq n \leq 1\,000\)), the number of groups of identical socks.
- \(n\) lines, each describing a group of identical socks with the following:
- A string \(i\), the type of the socks in the group. The type \(i\) consists of between \(1\) and \(20\) lowercase English letters. Socks with the same type are considered compatible for fashion purposes.
- A string \(j\), the fit of the socks in the group, which is either left, right or any, indicating whether the socks fit on the left foot, the right foot or any foot.
- An integer \(k\) (\(1\leq k \leq 1\,000\)), the number of socks in the drawer that are of this type and fit.

A given fit of a given type of sock appears at most once in the input.

출력 형식

Output the minimum number of socks Kattis needs to draw to be guaranteed to get a matching pair. If it is not possible to get a matching pair at all, output impossible.

예제 1
입력
3
fuzzy any 10
wool left 6
wool right 4
출력
8
예제 2
입력
3
sports any 1
black left 6
white right 6
출력
impossible
예제 3
입력
2
warm any 5
warm left 3
출력
4
문제 정보

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

출처 ICPC NWERC 2021

평가 및 의견

K. Knitpicking

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

Log in to rate problems.

개별 의견

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

풀이 제출

K. Knitpicking

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