結果
問題 |
No.3289 Make More Happy Connection
|
ユーザー |
![]() |
提出日時 | 2025-08-26 03:12:00 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 1,024 ms / 2,000 ms |
コード長 | 830 bytes |
コンパイル時間 | 719 ms |
コンパイル使用メモリ | 7,936 KB |
実行使用メモリ | 12,928 KB |
最終ジャッジ日時 | 2025-08-26 03:12:19 |
合計ジャッジ時間 | 18,412 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
コンパイルメッセージ
Syntax OK
ソースコード
def assert f unless f puts "Error!: Constraint Violation" exit end end n = gets.to_i assert(1 <= n && n <= 300000) pre_x = -1 pre_y = -1 dp = Hash.new(0) same = 0 n.times do x,y = gets.split.map(&:to_i) assert(1 <= x && x <= 10**9) assert(1 <= y && y <= 10**9) ndp = Hash.new(0) # xi, yi の順番に置くとき if x == pre_x ndp[y] = [dp[pre_x] + x, dp[pre_y]].max elsif x == pre_y ndp[y] = [dp[pre_y] + x, dp[pre_x]].max else ndp[y] = [dp[pre_x], dp[pre_y]].max end # yi, xi の順番に置くとき if y == pre_x ndp[x] = [dp[pre_x] + y, dp[pre_y]].max elsif y == pre_y ndp[x] = [dp[pre_y] + y, dp[pre_x]].max else ndp[x] = [dp[pre_x], dp[pre_y]].max end dp = ndp pre_x = x pre_y = y same += x if x == y end puts [dp[pre_x], dp[pre_y]].max + same