結果

問題 No.655 E869120 and Good Triangles
ユーザー snteasntea
提出日時 2018-05-29 00:16:40
言語 Rust
(1.77.0 + proconio)
結果
WA  
実行時間 -
コード長 3,889 bytes
コンパイル時間 12,996 ms
コンパイル使用メモリ 402,096 KB
実行使用メモリ 327,588 KB
最終ジャッジ日時 2024-06-30 07:56:19
合計ジャッジ時間 29,725 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,812 KB
testcase_01 AC 0 ms
6,940 KB
testcase_02 WA -
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 0 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 942 ms
327,424 KB
testcase_11 AC 905 ms
327,492 KB
testcase_12 AC 895 ms
327,540 KB
testcase_13 AC 909 ms
327,492 KB
testcase_14 AC 901 ms
327,460 KB
testcase_15 AC 919 ms
327,524 KB
testcase_16 AC 927 ms
327,584 KB
testcase_17 AC 919 ms
327,488 KB
testcase_18 AC 920 ms
327,464 KB
testcase_19 AC 901 ms
327,540 KB
testcase_20 AC 900 ms
327,512 KB
testcase_21 AC 910 ms
327,588 KB
testcase_22 AC 899 ms
327,536 KB
testcase_23 AC 887 ms
327,448 KB
testcase_24 AC 592 ms
315,264 KB
testcase_25 AC 564 ms
315,392 KB
testcase_26 AC 565 ms
315,264 KB
testcase_27 AC 602 ms
315,520 KB
testcase_28 AC 543 ms
315,264 KB
testcase_29 AC 597 ms
315,264 KB
testcase_30 AC 1 ms
6,940 KB
testcase_31 AC 1 ms
6,944 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: `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

ソースコード

diff #

#[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] = dist[n-1][i];
        }
    }
    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!(dp);
    let mut ans = 0;
    for row in &dp {
        for &e in row {
            ans += n-e;
        }
    }
    printfln!("{}", ans);
}
0