結果

問題 No.110 しましまピラミッド
コンテスト
ユーザー elphe
提出日時 2026-02-11 12:23:50
言語 Rust
(1.93.0 + proconio + num + itertools)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,905 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,254 ms
コンパイル使用メモリ 204,108 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-02-11 12:23:58
合計ジャッジ時間 4,728 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

fn main() {
    let stdin = std::io::read_to_string(std::io::stdin().lock()).unwrap();
    let mut stdin = stdin.split_ascii_whitespace();

    let n_w: usize = stdin.next().unwrap().parse().unwrap();
    let w: Vec<u8> = (0..n_w)
        .map(|_| stdin.next().unwrap().parse().unwrap())
        .collect();
    let n_b: usize = stdin.next().unwrap().parse().unwrap();
    let b: Vec<u8> = (0..n_b)
        .map(|_| stdin.next().unwrap().parse().unwrap())
        .collect();

    use std::io::Write;
    std::io::stdout()
        .lock()
        .write_all(output(solve(w, b)).as_bytes())
        .unwrap();
}

fn solve(mut w: Vec<u8>, mut b: Vec<u8>) -> u8 {
    w.sort_unstable();
    b.sort_unstable();
    let blocks = [w, b];

    (0..=1)
        .map(|first| {
            let mut count = 0;
            let mut prev = 0;
            let mut i = 0;
            let mut j = 0;

            loop {
                while let Some(&len) = blocks[first].get(i)
                {
                    if len > prev { break; }
                    i += 1;
                }
                match blocks[first].get(i) {
                    Some(&len) => {
                        count += 1;
                        prev = len;
                        i += 1;
                    }
                    None => return count,
                }

                while let Some(&len) = blocks[first ^ 1].get(j)
                {
                    if len > prev { break; }
                    j += 1;
                }
                match blocks[first ^ 1].get(j) {
                    Some(&len) => {
                        count += 1;
                        prev = len;
                        j += 1;
                    }
                    None => return count,
                }
            }
        })
        .max()
        .unwrap()
}

fn output(ans: u8) -> String {
    ans.to_string() + "\n"
}
0