A - フィギュアスケート予選 / Figure Skating Qualifying Round 解説 by admin
gemini-3-flash-previewOverview
\(N\) contestants receive scores from \(M\) judges. The problem asks us to calculate each contestant’s final score according to rules determined by the number of judges \(M\) (such as excluding the highest and lowest scores), and then count the number of contestants who “fail the preliminary round” by scoring below the threshold \(K\).
Analysis
The key points of this problem are: correctly calculating the final score according to the conditional rules, and processing efficiently since \(N\) can be large.
Final Score Calculation Rules
- When \(M \geq 3\): Subtract the maximum value and the minimum value from the total, then compute the average of the remaining \(M-2\) scores (truncated toward zero).
- When \(M \leq 2\): Simply compute the average of all \(M\) scores (truncated toward zero).
In both cases, since we perform “truncation of the decimal part,” we can directly use integer division of programming languages (the
//operator in Python).
Constraints and Complexity
- The number of contestants \(N\) is at most \(10^5\), and the number of judges \(M\) is at most \(100\).
- Processing all contestants’ scores involves reading up to \(N \times M = 10^7\) values in total.
- Computing the “sum, max, min” for each contestant takes \(O(M)\), so the overall complexity is \(O(N \times M)\). This is well within typical time limits (around 2 seconds).
Algorithm
We judge each contestant using the following procedure:
- Read \(N, M, K\) from input.
- Repeat the following process \(N\) times:
- Read contestant \(i\)’s list of \(M\) scores \(S_i\).
- If \(M \geq 3\):
- Let
sumbe the total of \(S_i\),maxbe the maximum, andminbe the minimum. - Final score =
(sum - max - min) // (M - 2)
- Let
- If \(M \leq 2\):
- Let
sumbe the total of \(S_i\). - Final score =
sum // M
- Let
- If the final score is less than \(K\), increment the counter variable
fail_countby 1.
- Output the final
fail_count.
Complexity
- Time Complexity: \(O(N \times M)\)
- For each contestant, we scan through \(M\) scores once, resulting in \(N \times M\) operations in total.
- Space Complexity: \(O(M)\)
- We use \(M\) memory to hold one contestant’s score list, but there is no need to hold all contestants’ data simultaneously.
Implementation Notes
Python’s
//operator: For division between positive numbers,a // breturns the integer obtained by truncating the decimal part ofa / b(floor function). This behaves exactly as the problem statement’s instruction to “truncate the decimal part.”Utilizing built-in functions:
sum(),max(),min()are processed efficiently internally in Python, making them more efficient than manually iterating with a loop.Fast I/O: Since \(N \times M\) can be large, reading data using
sys.stdininstead ofinput()can reduce execution time.Source Code
import sys
def solve():
# 標準入力から1行ずつ読み込むイテレータを作成
input_iter = sys.stdin
# 最初の行(N, M, K)を読み込む
first_line = next(input_iter, None)
if first_line is None:
return
params = first_line.split()
if not params:
return
n = int(params[0])
m = int(params[1])
k = int(params[2])
fail_count = 0
# 審査員数 M が 3 以上の場合の処理
if m >= 3:
div = m - 2
# 各選手の得点を処理
for _ in range(n):
line = next(input_iter, None)
if line is None:
break
# 1行分の得点を整数のリストに変換
scores = list(map(int, line.split()))
if not scores:
continue
# 最高点と最低点を1つずつ除いた残りの得点の合計
# sum, max, min は Python の組み込み関数で高速に動作する
s_sum = sum(scores)
s_max = max(scores)
s_min = min(scores)
# 最終得点の計算(小数点以下切り捨て)
# Pythonの // 演算子は正の数に対して小数点以下を切り捨てる(床関数)
final_score = (s_sum - s_max - s_min) // div
# 基準点 K 未満であれば予選落ちとしてカウント
if final_score < k:
fail_count += 1
# 審査員数 M が 2 以下の処理
else:
for _ in range(n):
line = next(input_iter, None)
if line is None:
break
scores = list(map(int, line.split()))
if not scores:
continue
# すべての得点の平均値(小数点以下切り捨て)
final_score = sum(scores) // m
if final_score < k:
fail_count += 1
# 予選落ちの人数を出力
sys.stdout.write(str(fail_count) + '\n')
if __name__ == '__main__':
solve()
This editorial was generated by gemini-3-flash-preview.
投稿日時:
最終更新: