結果
| 問題 |
No.851 テストケース
|
| コンテスト | |
| ユーザー |
qwewe
|
| 提出日時 | 2025-05-14 13:21:18 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 3,153 ms |
| コード長 | 3,776 bytes |
| コンパイル時間 | 225 ms |
| コンパイル使用メモリ | 82,904 KB |
| 実行使用メモリ | 52,096 KB |
| 最終ジャッジ日時 | 2025-05-14 13:23:43 |
| 合計ジャッジ時間 | 2,008 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
def solve():
# Read the first line, which is N.
# The problem statement says N = 3.
n_str = input()
# We can convert N to an integer if needed, but for this problem, its value is fixed.
# n = int(n_str)
N_FIXED = 3 # As per problem statement N=3
# Read the second line. This line's format determines the overall input structure.
line_after_n_str = input()
parts = line_after_n_str.split()
# Case 1: Incorrect format (N followed by A1 A2 A3 on one line)
# The problem states "入力形式が N \n A1 ... AN の場合は..."
# For N=3, this means the line after N contains A1 A2 A3.
# So, if len(parts) is N_FIXED (i.e., 3).
if len(parts) == N_FIXED:
# As per problem: "入力はすべて整数で与えられる" (all input is integers).
# So, if there are N_FIXED parts, they are the N_FIXED integers A1, A2, A3.
# We just need to detect this format and print "assert".
print('"assert"')
# Case 2: Correct format (N, then A1, A2, A3 each on a new line)
# This means the line after N contains only A1.
elif len(parts) == 1:
try:
a1 = int(parts[0])
# Read A2 and A3 from the subsequent lines.
# Assume these lines will contain single, valid integers if this path is taken.
a2 = int(input())
a3 = int(input())
# Calculate the three possible sums of pairs
sum_a1_a2 = a1 + a2
sum_a1_a3 = a1 + a3
sum_a2_a3 = a2 + a3
# Store these sums in a list
sums_list = [sum_a1_a2, sum_a1_a3, sum_a2_a3]
# Find the unique sum values.
# Example: if sums are [6, 7, 7], unique values are {6, 7}.
unique_sum_values = set(sums_list)
# Sort the unique sums in descending order.
# Example: {6, 7} -> sorted [7, 6]
sorted_unique_sums = sorted(list(unique_sum_values), reverse=True)
# The problem constraint A1 != AN (i.e., A1 != A3 for N=3) ensures
# that the three sums (A1+A2, A1+A3, A2+A3) cannot all be identical.
# Proof: If A1+A2 = A1+A3 => A2=A3. If A1+A2 = A2+A3 => A1=A3.
# So, if all sums are equal, then A1=A2=A3, which implies A1=A3,
# contradicting the constraint.
# Thus, there are at least two distinct sum values.
# `sorted_unique_sums` will have at least 2 elements.
# The second largest unique sum is at index 1.
print(sorted_unique_sums[1])
except (ValueError, IndexError, EOFError) as e:
# ValueError: if int() conversion fails (e.g., "abc", "1 2").
# IndexError: if parts was unexpectedly empty (not possible due to len(parts)==1 check).
# EOFError: if input ends prematurely.
# These situations imply input that deviates from the problem's specified formats
# and "all integers" rule, beyond the handled "assert" case.
# Standard competitive programming practice is to let such cases cause a runtime error.
raise e
else:
# len(parts) is 0, 2, or N_FIXED+k (i.e., not 1 and not N_FIXED).
# Examples:
# 3
# (empty line) -> len(parts) = 0
# 3
# 1 2 -> len(parts) = 2 (N_FIXED is 3)
# This is an unspecified malformed input.
# It's neither the "correct" format nor the specific "incorrect" format.
# Let it result in a runtime error.
raise RuntimeError("Input format error: The line after N has {} parts, but expected 1 (for correct format) or {} (for specified incorrect format).".format(len(parts), N_FIXED))
# Call the main solving function
solve()
qwewe