結果
問題 | No.1194 Replace |
ユーザー |
![]() |
提出日時 | 2025-04-15 21:37:14 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 932 bytes |
コンパイル時間 | 476 ms |
コンパイル使用メモリ | 82,372 KB |
実行使用メモリ | 142,408 KB |
最終ジャッジ日時 | 2025-04-15 21:39:26 |
合計ジャッジ時間 | 8,645 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | WA * 27 |
ソースコード
import sys from collections import defaultdict def main(): N, M = map(int, sys.stdin.readline().split()) operations = [] s = set() for _ in range(M): B, C = map(int, sys.stdin.readline().split()) if C > B: operations.append((B, C)) s.add(B) s.add(C) # No valid operations if not s: print(N * (N + 1) // 2) return sorted_v = sorted(s, reverse=True) b_to_cs = defaultdict(list) for B, C in operations: b_to_cs[B].append(C) max_val = {} for v in sorted_v: current_max = v for C in b_to_cs.get(v, []): c_max = max_val.get(C, C) if c_max > current_max: current_max = c_max max_val[v] = current_max total = N * (N + 1) // 2 for v in s: total += (max_val[v] - v) print(total) if __name__ == "__main__": main()