結果
| 問題 |
No.1194 Replace
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 21:39:28 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 505 bytes |
| コンパイル時間 | 364 ms |
| コンパイル使用メモリ | 81,588 KB |
| 実行使用メモリ | 100,072 KB |
| 最終ジャッジ日時 | 2025-04-15 21:41:37 |
| 合計ジャッジ時間 | 7,100 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | WA * 27 |
ソースコード
n, m = map(int, input().split())
max_c = dict()
for _ in range(m):
b, c = map(int, input().split())
if c > b:
if b not in max_c or c > max_c[b]:
max_c[b] = c
memo = dict()
def get_max(x):
if x not in max_c:
return x
if x in memo:
return memo[x]
c = max_c[x]
cmax = get_max(c)
memo[x] = max(x, cmax)
return memo[x]
total = n * (n + 1) // 2
additional = 0
for b in max_c:
additional += (get_max(b) - b)
print(total + additional)
lam6er