結果
| 問題 |
No.1825 Except One
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 18:55:37 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,210 ms / 3,000 ms |
| コード長 | 1,410 bytes |
| コンパイル時間 | 181 ms |
| コンパイル使用メモリ | 81,868 KB |
| 実行使用メモリ | 286,768 KB |
| 最終ジャッジ日時 | 2025-06-12 18:55:52 |
| 合計ジャッジ時間 | 12,490 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 31 |
ソースコード
from collections import defaultdict
def main():
import sys
input = sys.stdin.read().split()
N = int(input[0])
A = list(map(int, input[1:N+1]))
# Initialize DP: dp[m] is a dictionary of (sum, max_val) -> count
dp = [defaultdict(int) for _ in range(N+2)] # m ranges from 0 to N
dp[0][(0, 0)] = 1 # base case: 0 elements, sum 0, max 0
for a in A:
# Create a temporary structure to hold new states
temp = [defaultdict(int) for _ in range(N+2)]
for m in range(N+1):
for (s, curr_max), cnt in dp[m].items():
# Take the current element a
new_m = m + 1
if new_m > N:
continue
new_s = s + a
new_max = max(curr_max, a)
temp[new_m][(new_s, new_max)] += cnt
# Merge the temp into dp
for m in range(N+1):
for (s_max, cnt) in temp[m].items():
s, max_val = s_max
dp[m][(s, max_val)] += cnt
ans = 0
for m in range(2, N+1):
for (s, max_val), cnt in dp[m].items():
if (m - 1) == 0:
continue # impossible since m >=2
if s % (m - 1) != 0:
continue
k = s // (m - 1)
if max_val <= k:
ans += cnt
print(ans)
if __name__ == '__main__':
main()
gew1fw