結果
問題 |
No.844 split game
|
ユーザー |
|
提出日時 | 2022-12-01 22:25:24 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 1,223 bytes |
コンパイル時間 | 18,423 ms |
コンパイル使用メモリ | 380,096 KB |
実行使用メモリ | 9,780 KB |
最終ジャッジ日時 | 2024-10-09 03:23:51 |
合計ジャッジ時間 | 18,839 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 56 |
ソースコード
const INF: isize = 1isize << 60; fn main() { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = temp[0]; let m = temp[1]; let a = temp[2] as isize; let mut areas = (0..m).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); (temp[0]-1, temp[1], temp[2] as isize) }) .collect::<Vec<_>>(); areas.sort(); let mut dp = vec![vec![-INF; 2]; n+1]; for i in 0..=n { dp[i][0] = 0; } dp[0][1] = 0; let mut lidx = 0usize; for &(l, r, p) in areas.iter() { while lidx < l { dp[lidx+1][0] = dp[lidx+1][0].max(dp[lidx][0]).max(dp[lidx][1]); dp[lidx+1][1] = dp[lidx+1][1].max(dp[lidx][0] - a).max(dp[lidx][1] - a); lidx += 1; } let addval = if r == n { 0 } else { -a }; dp[r][1] = dp[r][1].max(dp[l][1] + p + addval); } println!("{}", dp.iter().map(|v| v.iter().max().unwrap()).max().unwrap()); }