組合せページの位置づけ
| 項目 | 内容 |
|---|---|
| 必修度 | 標準 |
| 学習目安 | 標準〜発展 |
| 前提 | 階乗・mod |
| 対象問題 | 26問(推定値あり26問、未算出0問) |
この記事のdifficulty区分は、問題を解く順番を決めるための目安です。AtCoderの公式なA〜F区分ではなく、取得できたdifficulty推定値を次の範囲に分けています。
| 学習目安 | difficulty推定値 | 問題数 |
|---|---|---|
| 入門 | difficulty < 0 | 6 |
| 標準 | 0〜799 | 6 |
| 標準〜発展 | 800〜1199 | 6 |
| 発展 | 1200以上 | 8 |
| 未算出 | — | 0 |
順列の順位や組合せの数を、階乗と未使用要素の数え上げへ分解するページです。
問題ごとの細かな実装は異なりますが、最初に確認する条件は共通しています。
組合せの見分け方
- 辞書順の順位を求める
- 残りの要素数に応じて場合の数を足す
- 階乗・組合せを法の下で扱う
組合せの実装前チェック
- 順位の添字を0始まりにそろえる
- 各位置で小さい未使用要素を数える
- 階乗と法の扱いを確認する
先に確認する文法・ライブラリ
まずは必須Python文法で、入力・配列・条件分岐・ループなどの基本を確認してください。問題に合わせたキュー、ヒープ、二分探索などの選び方は標準ライブラリ・定石にまとめています。
代表問題で実装を確認する
最初の一問として、ABC225 A Distinct Strings(公式解説)を解きます。3文字の並べ方を全て作り、重複をsetで取り除きます。文字が同じ場合だけ同じ並べ方が重なることを、そのまま確認できます。
from itertools import permutations
S = input().strip()
patterns = {''.join(order) for order in permutations(S)}
print(len(patterns))
3!通りしかないのでO(1)です。文字数が大きい場合は階乗全探索ではなく、出現回数から数える方法を選びます。
組合せの学ぶ順番
このページでは全件を一度に並べず、difficultyの推定値を目安に代表問題を段階分けしています。難易度が未算出の問題は、制約と出題意図を先に確認します。
まず解く
| 問題 | 公式解説 | 出題意図 | difficulty |
|---|---|---|---|
| ABC300 A N-choice question | 公式解説 | Ai+BiがXになる選択肢の個数を数える。 | -1147 |
| ABC225 A Distinct Strings | 公式解説 | 3文字の重複個数に応じて異なる並べ方の数を場合分けする。 | -994 |
| ABC466 B Representative Balls | 公式解説 | Count representative-ball selections with combinations. | -552 |
| ABC342 B Which is ahead? | 公式解説 | Official editorial intent is classified as permutation position query. | -378 |
| ABC403 B Four Hidden | 公式解説 | 公式Editorialの方針を four hidden string count として整理する。 | -277 |
次に解く
| 問題 | 公式解説 | 出題意図 | difficulty |
|---|---|---|---|
| ABC392 C Bib | 公式解説 | Invert the bib-number permutation and compose it with the staring-person permutation. | -43 |
| ABC285 C abc285_brutmhyhiizp | 公式解説 | Interpret the uppercase word as a one-indexed base-26 number. | 25 |
| ABC195 C Comma | 公式解説 | For each digit length, count how many numbers up to N contain each comma position. | 235 |
| ABC185 C Duodecim Ferra | 公式解説 | Split L centimeters into twelve positive parts, giving C(L-1,11). | 373 |
| ABC276 C Previous Permutation | 公式解説 | Apply the standard previous-permutation operation to the given permutation. | 389 |
挑戦問題
| 問題 | 公式解説 | 出題意図 | difficulty |
|---|---|---|---|
| ABC150 C Count Order | 公式解説 | 全順列を辞書順に生成し、PとQより小さい順列の個数の差から順位差を求める。 | 422 |
| ABC382 D G. Keep Distance | 公式解説 | 隣接差制約を変数変換して非減少列の個数へ落とし、組合せで数える。 | 685 |
| ABC324 D G. Square Permutation | 公式解説 | Enumerate permutations of digits and test whether the square root is integral. | 895 |
| ABC163 D Sum of Large Numbers | 公式解説 | 選ぶ個数ごとに作れる和が最小値から最大値まで連続することを使い、K〜N+1個の場合の範囲の個数を加算する。 | 960 |
| ABC202 D aab aba baa | 公式解説 | At each position count strings beginning with a, and choose a or b according to K. | 966 |
問題文を読んだら、まず「見分け方」のどれに当たるかを一行で記録します。当てはまらない問題は、別のページへ移す判断自体を復習材料にします。





