結果
問題 | No.1392 Don't be together |
ユーザー | chineristAC |
提出日時 | 2020-09-01 12:23:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,421 ms / 2,000 ms |
コード長 | 1,633 bytes |
コンパイル時間 | 172 ms |
コンパイル使用メモリ | 82,224 KB |
実行使用メモリ | 277,596 KB |
最終ジャッジ日時 | 2024-11-21 00:41:05 |
合計ジャッジ時間 | 19,693 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
63,848 KB |
testcase_01 | AC | 55 ms
64,276 KB |
testcase_02 | AC | 56 ms
65,096 KB |
testcase_03 | AC | 55 ms
63,656 KB |
testcase_04 | AC | 55 ms
63,772 KB |
testcase_05 | AC | 55 ms
64,324 KB |
testcase_06 | AC | 525 ms
157,300 KB |
testcase_07 | AC | 696 ms
219,332 KB |
testcase_08 | AC | 1,190 ms
204,180 KB |
testcase_09 | AC | 756 ms
277,596 KB |
testcase_10 | AC | 970 ms
169,024 KB |
testcase_11 | AC | 1,191 ms
224,384 KB |
testcase_12 | AC | 1,067 ms
159,008 KB |
testcase_13 | AC | 1,088 ms
202,108 KB |
testcase_14 | AC | 939 ms
221,120 KB |
testcase_15 | AC | 710 ms
160,204 KB |
testcase_16 | AC | 1,421 ms
226,500 KB |
testcase_17 | AC | 852 ms
182,060 KB |
testcase_18 | AC | 1,201 ms
201,240 KB |
testcase_19 | AC | 1,006 ms
192,676 KB |
testcase_20 | AC | 356 ms
116,972 KB |
testcase_21 | AC | 178 ms
92,180 KB |
testcase_22 | AC | 739 ms
150,760 KB |
testcase_23 | AC | 515 ms
123,256 KB |
testcase_24 | AC | 283 ms
98,692 KB |
testcase_25 | AC | 636 ms
130,396 KB |
testcase_26 | AC | 188 ms
95,672 KB |
testcase_27 | AC | 404 ms
103,612 KB |
testcase_28 | AC | 588 ms
131,244 KB |
testcase_29 | AC | 365 ms
102,032 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 = 2*10**5 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())) assert(2<=N<=5000) assert(2<=M<=N) assert(len(P)==N) assert(all(i+1!=P[i] for i in range(N))) 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) P.sort() assert(all(i==P[i] for i in range(N))) n = len(cycle) binom_poly = [1] for i in range(n): c = [cmb(cycle[i],j,mod)*pow(-1,j,mod) for j in range(1,cycle[i]+1)] c[0] = (c[0] + 1) % mod merged = [0 for i in range(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 = [[int(i==j or i==1) for i in range(M+1)] for j in range(N+1)] Stirling[0][0] = 0 for j in range(2,M+1): for i in range(j+1,N+1): Stirling[i][j] = Stirling[i-1][j-1] + j * Stirling[i-1][j] Stirling[i][j] %= mod ans = 0 for i in range(N-n+1): ans += Stirling[n+i][M] * binom_poly[i] ans %= mod ans *= (-1)**N ans %= mod print(ans)