結果

問題 No.2709 1975 Powers
ユーザー well-defined
提出日時 2024-09-16 16:56:40
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1,150 ms / 2,000 ms
コード長 1,328 bytes
コンパイル時間 13,565 ms
コンパイル使用メモリ 377,288 KB
実行使用メモリ 127,104 KB
最終ジャッジ日時 2024-09-16 16:57:10
合計ジャッジ時間 29,179 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::input;

fn main () {
    input! {
        n: usize,
        p: u128,
        q: u128,
        mut arr: [u128; n],
    }
    arr.sort();
    let apow: Vec<u128> = std::iter::successors(Some(10), |&prev| Some((prev * 10) % p))
        .take(arr[n-1] as usize)
        .collect();
    let bpow: Vec<u128> = std::iter::successors(Some(9), |&prev| Some((prev * 9) % p))
        .take(arr[n-1] as usize)
        .collect();
    let cpow: Vec<u128> = std::iter::successors(Some(7), |&prev| Some((prev * 7) % p))
        .take(arr[n-1] as usize)
        .collect();
    let dpow: Vec<u128> = std::iter::successors(Some(5), |&prev| Some((prev * 5) % p))
        .take(arr[n-1] as usize)
        .collect();
    let mut ans: u128 = 0;
    for i in 0..n {
        let a = arr[i];
        for j in i+1..n {
            let b = arr[j];
            for k in j+1..n {
                let c = arr[k];
                for l in k+1..n {
                    let d = arr[l];
                    //println!("a: {}, b: {}, c: {}, d: {}",a,b,c,d);
                    let val = (apow[a as usize -1] + bpow[b as usize -1] + cpow[c as usize -1] + dpow[d as usize -1]) % p;

                    if val == q {
                        ans += 1;
                    }

                }
            }
        }
    }
    println!("{}", ans);
}
0