結果

問題 No.2929 Miracle Branch
ユーザー Daichi01240124
提出日時 2024-10-12 16:59:26
言語 Rust
(1.83.0 + proconio)
結果
WA  
実行時間 -
コード長 2,241 bytes
コンパイル時間 26,830 ms
コンパイル使用メモリ 401,856 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2024-10-12 17:01:10
合計ジャッジ時間 33,249 ms
ジャッジサーバーID
(参考情報)
judge / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other WA * 25 TLE * 1 -- * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
  --> src/main.rs:41:9
   |
41 |     let mut primes = prime_factorization(X);
   |         ----^^^^^^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

ソースコード

diff #

#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::comparison_chain)]
#![allow(clippy::nonminimal_bool)]
#![allow(clippy::neg_multiply)]
#![allow(dead_code)]
#![allow(clippy::collapsible_else_if)]
use proconio::{
    fastout, input, input_interactive,
    marker::{Chars, Usize1},
};
use std::cmp::Reverse;
use std::collections::BinaryHeap;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::mem::swap;

//const MOD: usize = 1e9 as usize + 7;
const MOD: usize = 998244353;
// const MOD: usize = 2147483647;

#[macro_export]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $( $y: expr ),+) => {
        std::cmp::max($x, max!($( $y ),+))
    }
}
#[macro_export]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $( $y: expr ),+) => {
        std::cmp::min($x, min!($( $y ),+))
    }
}
fn main() {
    input! {
        X:usize,
    }
    let mut primes = prime_factorization(X);
    let mut nodes = vec![];
    let mut edges = vec![];
    for (_, val) in &primes {
        for _ in 0..*val {
            nodes.push('b');
        }
    }
    let mut now = nodes.len();
    let mut idx = 0;
    for (&key, &val) in &primes {
        for _ in 0..val {
            for _ in 0..key {
                if nodes.len() > 200000 {
                    println!("-1");
                    return;
                }
                nodes.push('g');
                edges.push((idx, now));
                now += 1;
            }
            idx += 1;
        }
    }
    if nodes.len() > 200000 {
        println!("-1");
        return;
    }
    println!("{}", nodes.len());
    for (i, j) in edges {
        println!("{} {}", i + 1, j + 1);
    }
    for n in nodes {
        print!("{} ", n);
    }
    println!("");
}
fn prime_factorization(n: usize) -> HashMap<usize, usize> {
    let mut n = n;
    let mut map = HashMap::new();
    if n == 1 {
        map.insert(1, 1);
        return map;
    }
    let mut i = 2;
    while i * i <= n {
        while n % i == 0 {
            *map.entry(i).or_insert(0) += 1;
            n /= i;
        }
        i += 1;
    }
    if n > 1 {
        map.insert(n, 1);
    }
    map
}
0