結果
| 問題 |
No.1294 マウンテン数列
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 13:51:36 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,169 bytes |
| コンパイル時間 | 183 ms |
| コンパイル使用メモリ | 82,816 KB |
| 実行使用メモリ | 91,112 KB |
| 最終ジャッジ日時 | 2025-06-12 13:52:25 |
| 合計ジャッジ時間 | 3,935 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 TLE * 1 -- * 11 |
ソースコード
MOD = 998244353
def main():
import sys
N, *rest = list(map(int, sys.stdin.read().split()))
A = rest[:N]
A.sort()
max_val = A[-1]
others = A[:-1]
total = 0
from itertools import combinations
# Generate all subsets of others that can be part of S (including none)
# S must include max_val (which is handled by the structure)
# Iterate over all possible subsets of others to include in S (max_val is always included)
for k in range(0, len(others)+1):
for subset in combinations(others, k):
S = list(subset) + [max_val]
S_sorted = sorted(S)
T = []
for x in others:
if x not in subset:
T.append(x)
T_sorted = sorted(T, reverse=True)
if not T_sorted:
seq = S_sorted
else:
seq = S_sorted + T_sorted
danger = 0
for i in range(len(seq)-1):
diff = abs(seq[i] - seq[i+1])
if diff > danger:
danger = diff
total += danger
print(total % MOD)
if __name__ == "__main__":
main()
gew1fw