結果
問題 | No.655 E869120 and Good Triangles |
ユーザー | sntea |
提出日時 | 2018-05-29 01:28:50 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1,373 ms / 2,500 ms |
コード長 | 3,853 bytes |
コンパイル時間 | 14,338 ms |
コンパイル使用メモリ | 406,008 KB |
実行使用メモリ | 384,808 KB |
最終ジャッジ日時 | 2024-06-30 08:00:38 |
合計ジャッジ時間 | 38,852 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 0 ms
6,944 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 1,369 ms
384,784 KB |
testcase_11 | AC | 1,363 ms
384,800 KB |
testcase_12 | AC | 1,373 ms
384,768 KB |
testcase_13 | AC | 1,327 ms
384,748 KB |
testcase_14 | AC | 1,318 ms
384,680 KB |
testcase_15 | AC | 1,343 ms
384,808 KB |
testcase_16 | AC | 1,372 ms
384,692 KB |
testcase_17 | AC | 1,349 ms
384,708 KB |
testcase_18 | AC | 1,349 ms
384,684 KB |
testcase_19 | AC | 1,302 ms
384,744 KB |
testcase_20 | AC | 1,322 ms
384,728 KB |
testcase_21 | AC | 1,302 ms
384,656 KB |
testcase_22 | AC | 1,291 ms
384,760 KB |
testcase_23 | AC | 1,281 ms
384,800 KB |
testcase_24 | AC | 956 ms
372,480 KB |
testcase_25 | AC | 923 ms
372,480 KB |
testcase_26 | AC | 939 ms
372,480 KB |
testcase_27 | AC | 961 ms
372,608 KB |
testcase_28 | AC | 914 ms
372,480 KB |
testcase_29 | AC | 947 ms
372,480 KB |
testcase_30 | AC | 1 ms
6,940 KB |
testcase_31 | AC | 1 ms
6,940 KB |
testcase_32 | AC | 1 ms
6,940 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: `i` --> src/main.rs:87:43 | 87 | let mut csumu: Vec<_> = (0..n+1).map(|i| vec![0; n+1]).collect(); | ^ help: if this is intentional, prefix it with an underscore: `_i` | = 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)); } } } let mut csumu: Vec<_> = (0..n+1).map(|i| vec![0; n+1]).collect(); for i in 0..n { for j in 0..i+1 { // csumu[i+1][j] = dist[i][j] + csumu[i][j]; csumu[j][i+1] = dist[i][j] + csumu[j][i]; } } 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; 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 in 0..dist[i].len() { let mut r = dp[i+1][j+1]; let mut val = vt[i+1][j+1] + (csumu[j][r] - csumu[j][i]); 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; } } let mut ans = 0; for row in &dp { for &e in row { ans += n-e; } } printfln!("{}", ans); }