結果
問題 | No.1247 ブロック登り |
ユーザー | akakimidori |
提出日時 | 2020-10-02 23:18:43 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,590 bytes |
コンパイル時間 | 12,526 ms |
コンパイル使用メモリ | 400,616 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-17 23:46:27 |
合計ジャッジ時間 | 14,110 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | WA | - |
testcase_23 | AC | 1 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,944 KB |
testcase_25 | AC | 36 ms
6,940 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
ソースコード
// ---------- begin chmin, chmax ---------- trait ChangeMinMax { fn chmin(&mut self, x: Self) -> bool; fn chmax(&mut self, x: Self) -> bool; } impl<T: PartialOrd> ChangeMinMax for T { fn chmin(&mut self, x: Self) -> bool { *self > x && { *self = x; true } } fn chmax(&mut self, x: Self) -> bool { *self < x && { *self = x; true } } } // ---------- end chmin, chmax ---------- //https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // fn run() { input! { n: usize, k: usize, a: [i64; n], } let ini = std::i64::MIN / 10; if k == 1 { for i in 0..n { let mut ans = ini; if i > 0 { ans.chmax(a[i - 1]); } if i + 1 < n { ans.chmax(a[i + 1]); } println!("{}", ans); } return; } let mut dp = vec![vec![vec![ini; n]; n]; 2]; for i in 0..n { let mut sum = 0; for j in (i..n).take(k) { sum += (k - (j - i)) as i64 * a[j]; if j > i { let rem = k - (j - i); let x = (j ^ rem) & 1; let l = std::cmp::max(i, j.saturating_sub(rem)); dp[x][l][j - (rem & 1)].chmax(sum); } } } for i in 0..n { let mut sum = 0; for j in (0..=i).rev().take(k) { sum += (k - (i - j)) as i64 * a[j]; if j < i { let rem = k - (i - j); let x = (j ^ rem) & 1; let r = std::cmp::min(i, j + rem); dp[x][j + (rem & 1)][r].chmax(sum); } } } for mid in 0..n { let mut sum = 0; for l in (0..=mid).rev() { sum += (k - (mid - l)) as i64 * a[l]; let mut sum = sum; for r in (mid + 1)..n { if r - mid + 2 * (mid - l) > k { break; } sum += (k - 2 * (mid - l) - (r - mid)) as i64 * a[r]; let rem = k - 2 * (mid - l) - (r - mid); let x = (r ^ rem) & 1; let l = std::cmp::max(l, r.saturating_sub(rem)); dp[x][l][r - (rem & 1)].chmax(sum); } } } for mid in 0..n { let mut sum = 0; for r in mid..n { sum += (k - (r - mid)) as i64 * a[r]; let mut sum = sum; for l in (0..mid).rev() { if 2 * (r - mid) + mid - l > k { break; } sum += (k - 2 * (r - mid) - (mid - l)) as i64 * a[l]; let rem = k - 2 * (r - mid) - (mid - l); let x = (r ^ rem) & 1; let r = std::cmp::min(r, l + rem); dp[x][l + (rem & 1)][r].chmax(sum); } } } for dp in dp.iter_mut() { for i in 0..n { for j in (i..n).rev() { let v = dp[i][j]; if i < j { dp[i + 1][j].chmax(v); dp[i][j - 1].chmax(v); } } } } for i in 0..n { println!("{}", dp[(i ^ k) & 1][i][i]); } } fn main() { run(); }