結果
問題 | No.655 E869120 and Good Triangles |
ユーザー | hatoo |
提出日時 | 2018-03-10 11:49:06 |
言語 | Rust (1.77.0 + proconio) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 7,289 bytes |
コンパイル時間 | 12,588 ms |
コンパイル使用メモリ | 383,324 KB |
最終ジャッジ日時 | 2024-11-14 20:23:16 |
合計ジャッジ時間 | 13,291 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
error[E0308]: mismatched types --> src/main.rs:64:22 | 64 | .filter_map(|&(dx, dy)| { | ^^^^^^^^^ | | | expected `({integer}, {integer})`, found `&_` | expected due to this | = note: expected tuple `({integer}, {integer})` found reference `&_` error[E0308]: mismatched types --> src/main.rs:105:30 | 105 | .filter_map(|&(dx, dy)| { | ^^^^^^^^^ | | | expected `({integer}, {integer})`, found `&_` | expected due to this | = note: expected tuple `({integer}, {integer})` found reference `&_` For more information about this error, try `rustc --explain E0308`. error: could not compile `main` (bin "main") due to 2 previous errors
ソースコード
/** * _ _ __ _ _ _ _ _ _ _ * | | | | / / | | (_) | (_) | | (_) | | * | |__ __ _| |_ ___ ___ / /__ ___ _ __ ___ _ __ ___| |_ _| |_ ___ _____ ______ _ __ _ _ ___| |_ ______ ___ _ __ _ _ __ _ __ ___| |_ ___ * | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __| * | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) | __/ |_| | |_| |\ V / __/ | | | |_| \__ \ |_ \__ \ | | | | |_) | |_) | __/ |_\__ \ * |_| |_|\__,_|\__\___/ \___/_/ \___\___/|_| |_| |_| .__/ \___|\__|_|\__|_| \_/ \___| |_| \__,_|___/\__| |___/_| |_|_| .__/| .__/ \___|\__|___/ * | | | | | | * |_| |_| |_| * * https://github.com/hatoo/competitive-rust-snippets */ #[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::iter::FromIterator; #[allow(unused_imports)] use std::io::{stdin, stdout, BufWriter, Write}; mod util { use std::io::{stdin, stdout, BufWriter, StdoutLock}; use std::str::FromStr; use std::fmt::Debug; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn chars() -> Vec<char> { line().chars().collect() } #[allow(dead_code)] pub fn gets<T: FromStr>() -> Vec<T> where <T as FromStr>::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } #[allow(dead_code)] pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) { let out = stdout(); let writer = BufWriter::new(out.lock()); f(writer) } } #[allow(unused_macros)] macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; } #[allow(unused_macros)] macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } } const INF: u64 = 1 << 30; #[allow(dead_code)] fn adjacent6(x: usize, y: usize, s: usize) -> Vec<(usize, usize)> { [(-1, -1), (-1, 0), (0, -1), (0, 1), (1, 0), (1, 1)] .into_iter() .filter_map(|&(dx, dy)| { let nx = x as isize + dx; let ny = y as isize + dy; if nx >= 0 && ny >= 0 && ny <= nx && nx < s as isize { Some((nx as usize, ny as usize)) } else { None } }) .collect() } fn main() { std::thread::Builder::new() .stack_size(1024 * 1024 * 1024) .spawn(solve) .unwrap() .join() .unwrap(); } #[allow(dead_code)] fn solve() { let (n, k, p) = get!(usize, usize, u64); let mut triangle = [[INF; 4001]; 4001]; //vec![vec![INF; n]; n]; { let xy = get!(usize, usize; k); let mut que: VecDeque<(usize, usize)> = xy.into_iter().map(|(x, y)| (x - 1, y - 1)).collect(); for &(y, x) in &que { triangle[y][x] = 0; } // let mut cnt = 0; while let Some((y, x)) = que.pop_front() { // cnt += 1; for (i, j) in [(-1, -1), (-1, 0), (0, -1), (0, 1), (1, 0), (1, 1)] .into_iter() .filter_map(|&(dx, dy)| { let nx = y as isize + dx; let ny = x as isize + dy; if nx >= 0 && ny >= 0 && ny <= nx && nx < n as isize { Some((nx as usize, ny as usize)) } else { None } }) { if triangle[i][j] > triangle[y][x] + 1 { triangle[i][j] = triangle[y][x] + 1; que.push_back((i, j)); } } } } // let mut imos = vec![vec![0; n + 2]; n + 2]; let mut imos = [[0; 4000 + 2]; 4000 + 2]; for i in 0..n { for j in 0..i + 1 { imos[i + 1][j + 1] = triangle[i][j]; } } for i in 0..n + 1 { for j in 1..n + 1 { imos[i][j] += imos[i][j - 1]; } } for i in (0..n).rev() { for j in 0..n + 1 { imos[i][j] += imos[i + 1][j]; } } // let mut dp = vec![vec![0; n + 1]; n + 1]; let mut dp = [[0; 4000 + 1]; 4000 + 1]; for i in (0..n).rev() { for j in 0..i + 1 { let mut x = triangle[i][j]; if i + 1 < n { x += dp[i + 1][j]; x += dp[i + 1][j + 1]; } if i + 2 < n { x -= dp[i + 2][j + 1]; } dp[i][j] = x; } } fn calc(i: usize, j: usize, h: usize, dp: &[[u64; 4001]], imos: &[[u64; 4002]]) -> u64 { unsafe { dp.get_unchecked(i).get_unchecked(j) + imos.get_unchecked(i + h + 1).get_unchecked(j) - imos.get_unchecked(i + h + 1).get_unchecked(j + h) - dp.get_unchecked(i + h).get_unchecked(j + h) } } let mut hs = [[0; 4000]; 4000]; let mut ans = 0; for i in (0..n).rev() { for j in 0..i + 1 { let mut r = if i + 1 < n { min(hs[i + 1][j] as usize, hs[i + 1][j + 1] as usize) + 1 } else { n - i }; let mut t = r; while r > 0 && calc(i, j, r, &dp, &imos) >= p { t = r; r -= 1; } hs[i][j] = t; ans += n - i - r; } } println!("{}", ans); }