結果
問題 | No.1392 Don't be together |
ユーザー | chineristAC |
提出日時 | 2020-09-02 23:55:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 588 ms / 2,000 ms |
コード長 | 1,531 bytes |
コンパイル時間 | 322 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 273,280 KB |
最終ジャッジ日時 | 2024-11-22 02:11:24 |
合計ジャッジ時間 | 9,509 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
59,008 KB |
testcase_01 | AC | 48 ms
59,136 KB |
testcase_02 | AC | 47 ms
58,880 KB |
testcase_03 | AC | 47 ms
58,880 KB |
testcase_04 | AC | 48 ms
58,752 KB |
testcase_05 | AC | 48 ms
59,008 KB |
testcase_06 | AC | 396 ms
157,056 KB |
testcase_07 | AC | 401 ms
218,368 KB |
testcase_08 | AC | 513 ms
206,456 KB |
testcase_09 | AC | 588 ms
273,280 KB |
testcase_10 | AC | 349 ms
168,236 KB |
testcase_11 | AC | 442 ms
211,696 KB |
testcase_12 | AC | 344 ms
164,816 KB |
testcase_13 | AC | 403 ms
189,736 KB |
testcase_14 | AC | 419 ms
214,700 KB |
testcase_15 | AC | 318 ms
169,168 KB |
testcase_16 | AC | 459 ms
214,168 KB |
testcase_17 | AC | 347 ms
168,892 KB |
testcase_18 | AC | 435 ms
211,512 KB |
testcase_19 | AC | 381 ms
191,544 KB |
testcase_20 | AC | 200 ms
124,692 KB |
testcase_21 | AC | 118 ms
84,096 KB |
testcase_22 | AC | 290 ms
145,136 KB |
testcase_23 | AC | 224 ms
125,332 KB |
testcase_24 | AC | 162 ms
102,860 KB |
testcase_25 | AC | 238 ms
124,876 KB |
testcase_26 | AC | 113 ms
83,712 KB |
testcase_27 | AC | 142 ms
82,432 KB |
testcase_28 | AC | 230 ms
125,204 KB |
testcase_29 | AC | 163 ms
103,808 KB |
ソースコード
def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 998244353 N = 5000 g1 = [1]*(N+1) g2 = [1]*(N+1) inverse = [1]*(N+1) for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod ) g2[i]=( (g2[i-1] * inverse[i]) % mod ) inverse[0]=0 N,M = map(int,input().split()) P = list(map(int,input().split())) P = [P[i]-1 for i in range(N)] cycle = [] used = [False]*N for i in range(N): if not used[i]: used[i] = True c = 1 pos = i while not used[P[pos]]: pos = P[pos] used[pos] = True c += 1 cycle.append(c) n = len(cycle) binom_poly = [1] for i in range(n): c = [cmb(cycle[i],j,mod) for j in range(1,cycle[i]+1)] for j in range(0,cycle[i],2): c[j] = (- c[j]) % mod c[0] = (c[0] + 1) % mod merged = [0]*(len(binom_poly) + len(c) - 1) for i in range(len(binom_poly)): for j in range(len(c)): merged[i+j] += binom_poly[i] * c[j] merged[i+j] %= mod binom_poly = merged Stirling = [[0 for j in range(N+1)] for i in range(M+1)] for j in range(1,N+1): Stirling[1][j] = 1 for i in range(2,M+1): for j in range(i,N+1): Stirling[i][j] = Stirling[i-1][j-1] + i * Stirling[i][j-1] Stirling[i][j] %= mod ans = 0 for i in range(N-n+1): ans += Stirling[M][n+i] * binom_poly[i] ans %= mod ans *= (-1)**N ans %= mod print(ans)