結果

問題 No.630 門松グラフ
ユーザー phspls
提出日時 2023-01-14 18:55:03
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 143 ms / 1,500 ms
コード長 1,200 bytes
コンパイル時間 14,564 ms
コンパイル使用メモリ 382,648 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2024-12-26 04:20:16
合計ジャッジ時間 18,316 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];

    if m+1 < n {
        println!("NO");
        return;
    }
    let mut points = vec![0usize; n];
    let mut maxval = n;
    let mut minval = 1usize;
    for i in 0..n {
        if i % 2 == 0 {
            points[i] = minval;
            minval += 1;
        } else {
            points[i] = maxval;
            maxval -= 1;
        }
    }
    let mut lines = (1..n).map(|i| (i, i+1)).collect::<Vec<_>>();
    let mut size = 4usize;
    while size <= n {
        for i in 1.. {
            if lines.len() == m { break; }
            if i+size-1 > n {
                break;
            }
            lines.push((i, i+size-1));
        }
        if lines.len() == m { break; }
        size += 2;
    }
    if lines.len() == m {
        println!("YES");
        println!("{}", points.iter().map(|v| v.to_string()).collect::<Vec<_>>().join(" "));
        for &(l, r) in lines.iter() {
            println!("{} {}", l, r);
        }
    } else {
        println!("NO");
    }
}
0