結果
問題 | No.118 門松列(2) |
ユーザー | Yuki_Utaai |
提出日時 | 2018-06-05 21:08:44 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 806 bytes |
コンパイル時間 | 79 ms |
コンパイル使用メモリ | 11,036 KB |
実行使用メモリ | 27,524 KB |
最終ジャッジ日時 | 2023-09-12 22:34:44 |
合計ジャッジ時間 | 5,332 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 133 ms
20,100 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 125 ms
19,668 KB |
testcase_07 | AC | 125 ms
19,700 KB |
testcase_08 | AC | 122 ms
19,652 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
ソースコード
mod=10**9+7 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range(2,100001): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) #以下のcom関数を用いて組み合わせを計算 def com(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 n=int(input()) a=[int(i) for i in input().split()] syurui=0 times=1 count=1 for i in range(1,n): if a[i]==a[i-1]: count+=1 else : times*=(count) count=1 syurui+=1 else: times*=count syurui+=1 if syurui>=3: print(com(syurui,3,mod) * times % mod) else: print(0)