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

Linear Garden

Unrated 레이팅 미적용
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

August 16 – 23, Cairo

Contest Day 2 ‐ Linear Garden

English 1.1

1
Page of 2
LINEAR GARDEN

Ramesses II has just returned victorious from battle. To commemorate his victory, he has decided to
build a majestic garden. The garden will contain a long line of plants that will run all the way from his
palace at Luxor to the temple of Karnak. It will consist only of lotus plants and papyrus plants, since they
symbolize Upper and Lower Egypt respectively.

The garden must contain exactly N plants. Also, it must be balanced: in any contiguous section of the
garden, the numbers of lotus and papyrus plants must not differ by more than 2.

A garden can be represented as a string of letters ‘L’ (lotus) and ‘P’ (papyrus). For example, for N=5 there
are 14 possible balanced gardens. In alphabetical order, these are: LLPLP, LLPPL, LPLLP,
LPLPL, LPLPP, LPPLL, LPPLP, PLLPL, PLLPP, PLPLL, PLPLP, PLPPL, PPLLP,
and PPLPL.

The possible balanced gardens of a certain length can be ordered alphabetically, and then numbered
starting from 1. For example, for N=5, garden number 12 is the garden PLPPL.

TASK
Write a program that, given the number of plants N and a string that represents a balanced garden,
calculates the number assigned to this garden modulo some given integer M.
Note that for solving the task, the value of M has no importance other than simplifying computations.

EXAMPLE

Sample input 1
Sample output 1
5
7
PLPPL
5
The actual number assigned to PLPPL is 12. So, the output is 12 modulo 7, which is 5.

August 16 – 23, Cairo

Contest Day 2 ‐ Linear Garden

English 1.1

2
Page of 2

Sample input 2
Sample output 2
12
10000
LPLLPLPPLPLL
39

제약

1 <= N <= 1,000,000
7 <= M <= 10,000,000

GRADING
In inputs worth a total of 40 points, N will not exceed 40.

입력 형식

Your program must read from the standard input the following data:
• Line 1 contains the integer N, the number of plants in the garden.
• Line 2 contains the integer M.
• Line 3 contains a string of N characters ‘L’ (lotus) or ‘P’ (papyrus) that represents a balanced garden.

출력 형식

Your program must write to the standard output a single line containing one integer between 0 and M‐1
(inclusive), the number assigned to the garden described in the input, modulo M.

문제 정보

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

출처 IOI 2008

평가 및 의견

Linear Garden

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

Log in to rate problems.

개별 의견

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

풀이 제출

Linear Garden

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