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

9268번 - Dragon Pattern 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 128 MB356617.143%

문제

The dragon curve is a polygonal chain with segments of length 1, defined recursively. We choose some point on the plane and one of four directions, collinear to the coordinate axes. The left(right) dragon of order n is constructed in the following way:

  • if n is equal to 0, we construct a segment of length 1 from the current point in the current direction, moving to endpoint;
  • otherwise we construct the left dragon of order n−1 from the current point in the current direction, turn 90 degrees to the left(right) in the endpoint, and construct the right dragon of order n−1;

Let us construct the left dragon of order n, starting from the origin (point (0,0)) in the positive direction of the axis OX.

Given some pattern as a sequence of directions, in which sequential movements by unit length is performed, your task is to determine how many times does the given pattern occurs in the constructed dragon curve.

입력

Input file contains integer n (0 ≤ n ≤ 109) and string S consisting of symbols R, L, U and D, which defines the pattern. R denotes rightward movement (positive direction of the axis OX), L denotes leftward movement (negative direction of the axis OX), U denotes upward movement (positive direction of the axis OY), D denotes downward movement (negative direction of the axis OY). The length of the string S is in the range from 1 to 106.

출력

Output number of given patterns in the left dragon of the order n, constructed in the positive direction of an axis OX, modulo 109+7.

제한

예제 입력 1

2 RU

예제 출력 1

1

예제 입력 2

3 L

예제 출력 2

3

예제 입력 3

4 LDL

예제 출력 3

2

힌트

출처

ICPC > Regionals > Europe > Southeastern European Regional Contest > SEERC 2013 F번

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

출처

대학교 대회

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

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