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

Kruska

Platinum II 플래티넘 II
난이도
1s
시간 제한
64MB
메모리 제한
1
맞았습니다!!
1
제출 수
100.0%
정답률
레이팅

의견: 0

설명

Aladdin has become bored of life at the palace. He has a steady job, his wife Jasmine, kids are on the way and life is becoming monotonous. Prompted by all this, he has decided to have one more adventure before settling down: to find the Golden Pear, an extremely valuable legendary artifact that no one has been able to find.

The desert Aladdin is searching can be modeled as an \(N \times N\) grid of cells. Rows and columns are numbered \(1\) through \(N\) top to bottom and left to right. Some of the cells in the desert contain wizards that help Aladdin's quest in an unusual way.

Aladdin starts his quest in the top left corner of the desert on a Monday facing right. His movement involves repeating these steps:

  1. If the current cell contains a wizard that is awake, then Aladdin turns 90 degrees left or right, depending on what the wizard says.
  2. If moving forward would take Aladdin out of the desert, he turns 180 degrees.
  3. Aladdin moves forward one cell and it takes him exactly one day.

For each wizard we know his location and his activity schedule for each day of the week. The schedule is a string of exactly seven letters L, R or S, each character telling us what the wizard does on one day of the week (starting with Monday). The letter L means that Aladdin will be told to turn left, R that Aladdin will be told to turn right, while S means the wizard sleeps that day.

An old prophecy says that after \(K\) changes in direction (in steps 1 and/or 2) Aladdin will find the Pear.

Write a program that calculates how many days the search will last, according to the ancient prophecy.

제약

In test cases worth 50% of points, K will be at most 1000.
Contest #5, \(7^{th}\) February 2009

입력 형식

The first line contains two integers \(N\) and \(K\) (\(2 \le N \le 200\), \(1 \le K \le 1\,000\,000\,000\)), the size of the desert and the number of direction changes in the prophecy.

The second line contains an integer \(M\) (\(0 \le M \le 10000\)), the number of wizards.

Each of the following \(M\) lines contains two integers \(R\) and \(C\) (\(1 \le R, C \le N\)), and a string of seven letters L, R or S. The numbers represent the row and column where the wizard is located, while the string is his schedule.

No two wizards will share the same cell, nor will there be a wizard in cell \((1, 1)\).

출력 형식

Output the length of the search in days.

Scoring: In test cases worth \(50\%\) of points, \(K\) will be at most \(1000\).

서브태스크
서브태스크점수설명

Subtask 1

65점

\(K \le 1000\)

Subtask 2

65점

No additional constraints (\(K \le 10^9\)).

예제 1
입력
3 1
0
출력
2
예제 2
입력
5 2
2
1 3 RRSRRRR
1 5 RRRRLRR
출력
4
예제 3
입력
5 5
3
1 3 SSRSSSS
3 3 SSSLSSS
4 3 SSRSSLS
출력
10
문제 정보

riseoj 작성

출처 COCI 2008/2009 Contest 5

평가 및 의견

Kruska

개요
출제자 난이도 Platinum II 플래티넘 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Kruska

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