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

23871번 - HILO 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB40362893.333%

문제

Bessie knows a number $x+0.5$ where $x$ is some integer between 0ドル$ to $N,$ inclusive (1ドル\le N\le 5000$).

Elsie is trying to guess this number. She can ask questions of the form "is $i$ high or low?" for some integer $i$ between 1ドル$ and $N,$ inclusive. Bessie responds by saying "HI!" if $i$ is greater than $x+0.5,ドル or "LO!" if $i$ is less than $x+0.5$.

Elsie comes up with the following strategy for guessing Bessie's number. Before making any guesses, she creates a list of $N$ numbers, where every number from 1ドル$ to $N$ occurs exactly once (in other words, the list is a permutation of size $N$.) Then, she goes through the list, guessing numbers that appear in the list in order. However, Elsie skips any unnecessary guesses. That is, if Elsie is about to guess some number $i$ and Elsie previously guessed some $j < i$ such that Bessie responded with "HI!," Elsie will not guess $i$ and will move on to the next number in the list. Similarly, if she is about to guess some number $i$ and she previously guessed some $j > i$ such that Bessie responded with "LO!," Elsie will not guess $i$ and will move on to the next number in the list. It can be proven that using this strategy, Elsie always uniquely determines $x$ regardless of the permutation she creates.

If we concatenate all of Bessie's responses of either "HI" or "LO" into a single string $S,$ the number of times Bessie says "HILO" is the number of length 4ドル$ substrings of $S$ that are equal to "HILO."

Bessie knows that Elsie will use this strategy and has already chosen the value of $x,ドル but she does not know what permutation Elsie will use. Your goal is to compute the sum of the number of times Bessie says "HILO" over all permutations that Elsie could possibly choose, modulo 10ドル^9+7$.

입력

The only line of input contains $N$ and $x$.

출력

The total number of HILOs modulo 10ドル^9+7$.

제한

예제 입력 1

4 2

예제 출력 1

17

In this test case, Bessie's number is 2ドル.5$.

For example, if Elsie's permutation is $(4,1,3,2),ドル then Bessie will say "HILOHILO," for a total of two "HILO"s. As another example, if Elsie's permutation is $(3,1,2,4),ドル then Bessie will say "HILOLO," for a total of one "HILO."

예제 입력 2

60 10

예제 출력 2

508859913

Make sure to output the sum modulo 10ドル^9+7$.

힌트

출처

Olympiad > USA Computing Olympiad > 2021-2022 Season > USACO 2021 December Contest > Platinum 3번

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

출처

대학교 대회

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

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