結果

問題 No.118 門松列(2)
ユーザー もちふわゆるゆるもちふわゆるゆる
提出日時 2023-09-10 01:32:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 107 ms / 5,000 ms
コード長 533 bytes
コンパイル時間 614 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 89,548 KB
最終ジャッジ日時 2023-09-10 01:32:37
合計ジャッジ時間 3,977 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
75,884 KB
testcase_01 AC 107 ms
89,548 KB
testcase_02 AC 106 ms
89,328 KB
testcase_03 AC 105 ms
89,348 KB
testcase_04 AC 106 ms
89,400 KB
testcase_05 AC 104 ms
89,316 KB
testcase_06 AC 76 ms
71,376 KB
testcase_07 AC 76 ms
71,240 KB
testcase_08 AC 80 ms
71,044 KB
testcase_09 AC 105 ms
87,720 KB
testcase_10 AC 84 ms
76,224 KB
testcase_11 AC 86 ms
77,684 KB
testcase_12 AC 83 ms
75,948 KB
testcase_13 AC 80 ms
75,768 KB
testcase_14 AC 104 ms
87,652 KB
testcase_15 AC 81 ms
75,644 KB
testcase_16 AC 93 ms
81,336 KB
testcase_17 AC 80 ms
75,876 KB
testcase_18 AC 84 ms
77,732 KB
testcase_19 AC 91 ms
80,208 KB
testcase_20 AC 91 ms
81,020 KB
testcase_21 AC 100 ms
86,132 KB
testcase_22 AC 83 ms
76,920 KB
testcase_23 AC 95 ms
84,784 KB
testcase_24 AC 86 ms
78,192 KB
testcase_25 AC 88 ms
80,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, math
input = lambda: sys.stdin.readline()[:-1]
def MI(): return map(int, input().split())
inf = 10**18
mod = 10**9+7

from itertools import *
def lcom(s):
    grouped = groupby(s)
    res = []
    for k, v in grouped:
        res.append((k, int(len(list(v)))))
    return res

n = int(input())
a = sorted(MI())
b = lcom(a)

b1, b3 = 0, 0
for _, i in b:
    b3 += i
b3 -= b[0][1]

ans = 0
for b2 in range(1, len(b)):
    b1 += b[b2-1][1]
    b3 -= b[b2][1]
    ans += b[b2][1] * b1 * b3 % mod
    ans %= mod
print(ans%mod)
0