結果

問題 No.497 入れ子の箱
ユーザー tanzakutanzaku
提出日時 2017-03-24 23:09:40
言語 Rust
(1.77.0)
結果
AC  
実行時間 672 ms / 5,000 ms
コード長 2,611 bytes
コンパイル時間 1,211 ms
コンパイル使用メモリ 154,308 KB
実行使用メモリ 7,312 KB
最終ジャッジ日時 2023-09-20 03:11:42
合計ジャッジ時間 15,873 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 654 ms
7,164 KB
testcase_04 AC 655 ms
7,180 KB
testcase_05 AC 653 ms
7,164 KB
testcase_06 AC 656 ms
7,260 KB
testcase_07 AC 671 ms
7,312 KB
testcase_08 AC 667 ms
7,272 KB
testcase_09 AC 672 ms
7,212 KB
testcase_10 AC 671 ms
7,204 KB
testcase_11 AC 667 ms
7,132 KB
testcase_12 AC 414 ms
4,820 KB
testcase_13 AC 405 ms
4,788 KB
testcase_14 AC 405 ms
4,792 KB
testcase_15 AC 410 ms
4,748 KB
testcase_16 AC 416 ms
4,788 KB
testcase_17 AC 407 ms
4,816 KB
testcase_18 AC 635 ms
7,300 KB
testcase_19 AC 637 ms
7,128 KB
testcase_20 AC 634 ms
7,296 KB
testcase_21 AC 634 ms
7,212 KB
testcase_22 AC 633 ms
7,284 KB
testcase_23 AC 13 ms
4,380 KB
testcase_24 AC 13 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 497 ms
5,860 KB
testcase_28 AC 494 ms
5,936 KB
testcase_29 AC 490 ms
5,656 KB
testcase_30 AC 98 ms
4,376 KB
testcase_31 AC 101 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn inside(a: &mut [usize; 3], b: &mut [usize; 3]) -> bool {
    let mut ok = true;
    for i in 0..3 {
        if a[i] == std::usize::MAX { continue; }
        ok = false;
        for j in 0..3 {
            if b[j] == std::usize::MAX { continue; }
            if a[i] < b[j] {
                let tmp = (a[i], b[j]);
                a[i] = std::usize::MAX;
                b[j] = std::usize::MAX;
                let res = inside(a, b);
                a[i] = tmp.0;
                b[j] = tmp.1;
                if res { return true; }
            }
        }
    }
    ok
}

fn main() {
    let mut scanner = Scanner::new();
    let n = scanner.next_usize();
    let mut g = vec![Vec::new(); n];

    let mut t = Vec::new();
    for i in 0..n {
        t.push([scanner.next_usize(), scanner.next_usize(), scanner.next_usize()]);
        for j in 0..i {
            let mut a = t[j];
            let mut b = t[i];
            if inside(&mut a, &mut b) { g[i].push(j) }
            if inside(&mut b, &mut a) { g[j].push(i) }
        }
    }

    let mut dp = vec![1; n];
    for _ in 0..n {
        for i in 0..n {
            for j in 0..g[i].len() {
                dp[i] = std::cmp::max(dp[i], dp[g[i][j]] + 1)
            }
        }
    }

    println!("{}", dp.iter().max().unwrap());
}


struct Scanner {
    reader: std::io::Stdin,
    tokens: std::collections::VecDeque<String>,
}

impl Scanner {
    fn new() -> Self {
        Scanner {
            reader: std::io::stdin(),
            tokens: std::collections::VecDeque::new(),
        }
    }

    fn next(&mut self) -> String {
        if self.tokens.is_empty() {
        let mut s = String::new();
            loop {
                self.reader.read_line(&mut s).ok();
                let s = s.trim();
                if s.len() != 0 {
                    for it in s.split_whitespace() {
                        self.tokens.push_back(it.into())
                    }
                    break;
                }
            }
        }
        self.tokens.pop_front().unwrap()
    }

    fn next_generics<T>(&mut self) -> T where
        T: std::str::FromStr + std::marker::Copy,
        <T as std::str::FromStr>::Err: std::fmt::Debug
    {
        self.next().parse().unwrap()
    }
    
    #[allow(dead_code)] fn next_i32(&mut self) -> i32 { self.next_generics::<i32>() }
    #[allow(dead_code)] fn next_i64(&mut self) -> i64 { self.next_generics::<i64>() }
    #[allow(dead_code)] fn next_u64(&mut self) -> u64 { self.next_generics::<u64>() }
    #[allow(dead_code)] fn next_usize(&mut self) -> usize { self.next_generics::<usize>() }
}

0