/** * _ _ __ _ _ _ _ _ _ _ * | | | | / / | | (_) | (_) | | (_) | | * | |__ __ _| |_ ___ ___ / /__ ___ _ __ ___ _ __ ___| |_ _| |_ ___ _____ ______ _ __ _ _ ___| |_ ______ ___ _ __ _ _ __ _ __ ___| |_ ___ * | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __| * | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) | __/ |_| | |_| |\ 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 { line().chars().collect() } #[allow(dead_code)] pub fn gets() -> Vec where ::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: 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() } #[allow(dead_code)] fn main() { let (n, k, p) = get!(usize, usize, u64); let mut triangle = 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]; 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]; 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; } } for v in &mut imos { v.shrink_to_fit(); } for v in &mut dp { v.shrink_to_fit(); } /* let calc = |i: usize, j: usize, h: usize| -> usize { let mut s = dp[i][j]; if i + h >= n { return s; } let sqr = imos[n][j + h] + imos[i + h][j] - imos[n][j] - imos[i + h][j + h]; // debug!(s, sqr, dp[i + h][j + h]); s -= sqr; s -= dp[i + h][j + h]; s }; */ fn calc( i: usize, j: usize, // n: usize, h: usize, dp: &[Vec], imos: &[Vec], ) -> u64 { /* if i + h >= n { return dp[i][j]; } */ //debug!(i, j, h); //dp[i][j] - (imos[n][j + h] + imos[i + h][j] - imos[n][j] - imos[i + h][j + h]) //- dp[i + h][j + h] // // dp[i][j] + imos[i + h + 1][j] - imos[i + h + 1][j + h] - dp[i + h][j + h] 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) } } /* debug!(triangle); debug!(dp); debug!(imos); debug!(calc(0, 0, 3, &dp, &imos)); */ let mut hs = vec![vec![0u16; n]; n]; 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 as u16; ans += n - i - r; } } println!("{}", ans); }