結果

問題 No.1644 Eight Digits
ユーザー tonyu0tonyu0
提出日時 2021-08-13 21:57:45
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 1,007 bytes
コンパイル時間 10,785 ms
コンパイル使用メモリ 390,872 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-03 18:42:18
合計ジャッジ時間 11,938 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn permutation(n: usize, p: &mut Vec<usize>, used: &mut Vec<bool>, all: &mut Vec<Vec<usize>>) {
    if p.len() == n {
        all.push(p.to_vec());
        return;
    }
    for i in 0..n {
        if !used[i] {
            p.push(i);
            used[i] = true;
            permutation(n, p, used, all);
            p.pop();
            used[i] = false;
        }
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let k: usize = itr.next().unwrap().parse().unwrap();

    let mut p: Vec<usize> = Vec::new();
    let mut out: Vec<Vec<usize>> = Vec::new();
    let mut used: Vec<bool> = vec![false; 8];
    permutation(8, &mut p, &mut used, &mut out);

    let mut ans = 0;
    for x in out {
        let mut d = 0;
        for y in x {
            d *= 10;
            d += y + 1
        }
        if d % k == 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}
0