結果
| 問題 | 
                            No.1194 Replace
                             | 
                    
| コンテスト | |
| ユーザー | 
                             lam6er
                         | 
                    
| 提出日時 | 2025-04-15 21:44:51 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 504 bytes | 
| コンパイル時間 | 295 ms | 
| コンパイル使用メモリ | 81,700 KB | 
| 実行使用メモリ | 103,192 KB | 
| 最終ジャッジ日時 | 2025-04-15 21:46:02 | 
| 合計ジャッジ時間 | 10,540 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 6 WA * 21 | 
ソースコード
n, m = map(int, input().split())
operations = []
for _ in range(m):
    b, c = map(int, input().split())
    operations.append((b, c))
# Sort operations by C in descending order
operations.sort(key=lambda x: -x[1])
max_map = {}
for b, c in operations:
    current_b = max_map.get(b, b)
    current_c = max_map.get(c, c)
    if current_c > current_b:
        max_map[b] = current_c
total = n * (n + 1) // 2
sum_diff = 0
for key in max_map:
    sum_diff += (max_map[key] - key)
print(total + sum_diff)
            
            
            
        
            
lam6er