結果
問題 | No.655 E869120 and Good Triangles |
ユーザー | sntea |
提出日時 | 2018-05-29 00:32:50 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1,020 ms / 2,500 ms |
コード長 | 3,894 bytes |
コンパイル時間 | 12,690 ms |
コンパイル使用メモリ | 403,880 KB |
実行使用メモリ | 327,552 KB |
最終ジャッジ日時 | 2024-06-30 07:57:13 |
合計ジャッジ時間 | 31,304 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 1,020 ms
327,468 KB |
testcase_11 | AC | 1,006 ms
327,532 KB |
testcase_12 | AC | 994 ms
327,528 KB |
testcase_13 | AC | 1,003 ms
327,460 KB |
testcase_14 | AC | 967 ms
327,464 KB |
testcase_15 | AC | 978 ms
327,424 KB |
testcase_16 | AC | 1,011 ms
327,552 KB |
testcase_17 | AC | 991 ms
327,552 KB |
testcase_18 | AC | 975 ms
327,552 KB |
testcase_19 | AC | 977 ms
327,488 KB |
testcase_20 | AC | 987 ms
327,476 KB |
testcase_21 | AC | 989 ms
327,464 KB |
testcase_22 | AC | 979 ms
327,480 KB |
testcase_23 | AC | 964 ms
327,476 KB |
testcase_24 | AC | 634 ms
315,264 KB |
testcase_25 | AC | 607 ms
315,520 KB |
testcase_26 | AC | 600 ms
315,264 KB |
testcase_27 | AC | 645 ms
315,264 KB |
testcase_28 | AC | 581 ms
315,264 KB |
testcase_29 | AC | 632 ms
315,264 KB |
testcase_30 | AC | 1 ms
5,376 KB |
testcase_31 | AC | 1 ms
5,376 KB |
testcase_32 | AC | 1 ms
5,376 KB |
コンパイルメッセージ
warning: unused macro definition: `printf` --> src/main.rs:62:18 | 62 | macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); } | ^^^^^^ | = note: `#[warn(unused_macros)]` on by default warning: unused variable: `e` --> src/main.rs:119:17 | 119 | for (j, e) in dist[i].iter().enumerate() { | ^ help: if this is intentional, prefix it with an underscore: `_e` | = note: `#[warn(unused_variables)]` on by default
ソースコード
#[allow(dead_code)] fn getline() -> String { let mut res = String::new(); std::io::stdin().read_line(&mut res).ok(); res } #[allow(unused_macros)] macro_rules! readl { ($t: ty) => { { let s = getline(); s.trim().parse::<$t>().unwrap() } }; ($( $t: ty),+ ) => { { let s = getline(); let mut iter = s.trim().split(' '); ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) } }; } #[allow(unused_macros)] macro_rules! readlvec { ($t: ty) => { { let s = getline(); let iter = s.trim().split(' '); iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>() } } } #[allow(unused_macros)] // macro_rules! debug { ($x: expr) => { println!("{}: {:?}", stringify!($x), $x) } } macro_rules! debug { ($x: expr) => () } #[allow(dead_code)] fn show<T>(iter: T) -> String where T: Iterator, T::Item: std::fmt::Display { let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e)); res.pop(); res } #[allow(unused_imports)] use std::cmp::{max, min}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::collections::btree_map::Entry::{Occupied, Vacant}; fn main() { use std::io::Write; let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); } macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); } let dx = [-1, -1, 0, 1, 1, 0, -1]; let dy = [-1, 0, 1, 1, 0, -1, -1]; let (n, k, p) = readl!(usize, usize, i64); let mut qu = VecDeque::new(); let mut dist: Vec<_> = (0..n).map(|i| vec![-1; i+1]).collect(); for _ in 0..k { let (x, y) = readl!(usize, usize); qu.push_back((x-1, y-1, 0)); dist[x-1][y-1] = 0; } let check = |x, y| 0 <= x && x < n as i32 && 0 <= y && y <= x; while let Some((x, y, d)) = qu.pop_front() { for k in 0..dx.len() { let nx = x as i32 + dx[k]; let ny = y as i32 + dy[k]; if check(nx, ny) && dist[nx as usize][ny as usize] == -1 { dist[nx as usize][ny as usize] = d+1; qu.push_back((nx as usize, ny as usize, d+1)); } } } debug!(dist); let mut csumu: Vec<_> = (0..n+1).map(|i| vec![0; i+1]).collect(); for i in 0..n { for j in 0..i+1 { csumu[i+1][j] = dist[i][j] + csumu[i][j]; } } let csumu = csumu; let mut csuml: Vec<_> = (0..n).map(|i| vec![0; i+2]).collect(); for i in 0..n { for j in 0..i+1 { csuml[i][j+1] = dist[i][j] + csuml[i][j]; } } let csuml = csuml; debug!(csuml); debug!(csumu); let mut dp: Vec<_> = (0..n).map(|i| vec![0; i+1]).collect(); let mut vt: Vec<_> = (0..n).map(|i| vec![0; i+1]).collect(); for (i, e) in dp[n-1].iter_mut().enumerate() { if dist[n-1][i] < p { *e = n; vt[n-1][i] = dist[n-1][i]; } else { *e = n-1; vt[n-1][i] = 0; } } for i in (0..n-1).rev() { for (j, e) in dist[i].iter().enumerate() { let mut r = dp[i+1][j+1]; let mut val = vt[i+1][j+1] + (csumu[r][j] - csumu[i][j]); while i < r && val >= p { let len = r-i; val -= csuml[r-1][j + len] - csuml[r-1][j]; r -= 1; } dp[i][j] = r; vt[i][j] = val; } } debug!(vt); debug!(dp); let mut ans = 0; for row in &dp { for &e in row { ans += n-e; } } printfln!("{}", ans); }