====== 기숙사 재배정 ====== ===== 풀이 ===== * 기본적인 [[ps:tutorial:교란순열]] 문제. * D(1),...,D(N)을 미리 O(N)에 구해서 저장해두면 각 쿼리들을 O(1)에 처리하는 것도 가능하지만, N의 범위가 워낙 작아서 그럴 필요조차 없다.. ===== 코드 ===== """Solution code for "BOJ 10978. 기숙사 재배정". - Problem link: https://www.acmicpc.net/problem/10978 - Solution link: http://www.teferi.net/ps/problems/boj/10978 Tags: [combinatorics] """ from teflib import combinatorics def main(): T = int(input()) for _ in range(T): N = int(input()) print(combinatorics.derangement(N)) if __name__ == '__main__': main() * Dependency: [[:ps:teflib:combinatorics#derangement|teflib.combinatorics.derangement]] {{tag>BOJ ps:problems:boj:골드_3}}