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

Struktura

설명

Petar and Ivana are bored during a long winter afternoon, so they decided to
invent a game with numbers.
Petar takes a sheet of paper and randomly writes down \(n\) numbers. Each number
is chosen completely at random and independently among the integers from
1 to \(k\). Using this procedure, Petar creates an array \(a\) of \(n\) numbers.
Ivana says that she especially likes some arrays because they have a “hidden
balance”, and she calls them structures. An array is a structure if the following
conditions are satisfied:
• Every number from 1 to \(n\) appears in the array exactly once.
• For every index \(i\) (\(1 \le i \le n\)), it holds that |\(a_{i} + i - n - 1\)| ≤1.
Ivana is interested in the probability that Petar, choosing the numbers completely at random, constructs
an array that is a structure.
It can be proven that the answer can always be represented as a fraction ^{P}
_{Q}^{,} ^{where} ^{P} ^{is} ^{an} ^{integer} ^{and} ^{Q}
is a positive integer not divisible by \(10^{9} + 7\). In that case, output \(P \cdot Q^{−1}\) (mod \(10^{9} + 7\)).

제약
입력 형식

The first line contains the natural numbers \(n\) and \(k\) (\(1 \le n\), \(k \le 10^{9}\)), the numbers from the problem
statement.

출력 형식

Output a single number, the answer to the question from the problem statement.

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

1

17점

n, \(k \le 7\)

2

23점

\(n \le 7\), \(k \le 100\)

3

19점

\(n \le 20\), \(k \le 100\)

4

25점

n, \(k \le 10^{6}\)

5

26점

No additional constraints.

예제 1
입력
2 1
출력
0
예제 2
입력
2 2
출력
500000004
예제 3
입력
7 94
출력
100976822
설명

Clarification of the second example: The arrays a that Petar can construct are: (1, 1), (1, 2), (2, 1),
(2, 2). The arrays that are structures are (1, 2) and (2, 1). The probability that Petar completely at

random obtains an array that is a structure is 2
4, i.e. 500000004 (mod 109 + 7).

문제 정보

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

출처 COCI 2025/2026 Contest 5

평가 및 의견

Struktura

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

Log in to rate problems.

개별 의견

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

풀이 제출

Struktura

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