Submission #2973625

Source Code Expand

Copy
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn solve(_n:u32, p:Vec<Vec<i32>>) -> bool {
    let mut x = 0;
    let mut y = 0;
    let mut t = 0;
    for pi in p {
        let (ti, xi, yi) = (pi[0], pi[1], pi[2]);
        let dx = (xi - x).abs() + (yi - y).abs();
        let dt = ti - t;
        if dx > dt {
            return false;
        }  
        if (dt - dx).abs() % 2 == 1 {
            return false;
        }
        x = xi;
        y = yi;
        t = ti;
    }
    true
}
fn main() {
    let n:u32 = read::<u32>();
    let p = read_vec2::<i32>(n);
    if solve(n, p) {
        println!("Yes");
    } else {
        println!("No");
    }
}

Submission Info

Submission Time
Task ABC086C - Traveling
User naoya_t
Language Rust (1.15.1)
Score 300
Code Size 1049 Byte
Status
Exec Time 41 ms
Memory 8444 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_000.txt, 0_001.txt, 0_002.txt
All 300 / 300 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt
Case Name Status Exec Time Memory
0_000.txt 2 ms 4352 KB
0_001.txt 2 ms 4352 KB
0_002.txt 2 ms 4352 KB
1_003.txt 2 ms 4352 KB
1_004.txt 41 ms 8444 KB
1_005.txt 41 ms 8444 KB
1_006.txt 38 ms 8444 KB
1_007.txt 7 ms 4352 KB
1_008.txt 2 ms 4352 KB
1_009.txt 9 ms 4352 KB
1_010.txt 2 ms 4352 KB
1_011.txt 7 ms 4352 KB
1_012.txt 2 ms 4352 KB