結果

問題 No.1359 [Zelkova 3rd Tune] 四人セゾン
ユーザー StrorkisStrorkis
提出日時 2021-01-22 22:13:48
言語 Rust
(1.77.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 2,095 bytes
コンパイル時間 1,373 ms
コンパイル使用メモリ 151,132 KB
実行使用メモリ 10,884 KB
最終ジャッジ日時 2023-08-27 19:35:30
合計ジャッジ時間 16,217 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 96 ms
6,568 KB
testcase_04 AC 94 ms
6,524 KB
testcase_05 AC 86 ms
6,556 KB
testcase_06 AC 87 ms
6,488 KB
testcase_07 AC 129 ms
8,416 KB
testcase_08 AC 130 ms
8,504 KB
testcase_09 AC 36 ms
4,380 KB
testcase_10 AC 36 ms
4,384 KB
testcase_11 AC 168 ms
9,940 KB
testcase_12 AC 169 ms
9,864 KB
testcase_13 AC 107 ms
7,028 KB
testcase_14 AC 106 ms
7,020 KB
testcase_15 AC 97 ms
6,460 KB
testcase_16 AC 96 ms
6,412 KB
testcase_17 AC 182 ms
10,432 KB
testcase_18 AC 182 ms
10,456 KB
testcase_19 AC 156 ms
9,408 KB
testcase_20 AC 156 ms
9,388 KB
testcase_21 AC 172 ms
9,812 KB
testcase_22 AC 170 ms
9,712 KB
testcase_23 AC 112 ms
7,608 KB
testcase_24 AC 112 ms
7,624 KB
testcase_25 AC 18 ms
4,384 KB
testcase_26 AC 18 ms
4,384 KB
testcase_27 AC 59 ms
4,780 KB
testcase_28 AC 59 ms
4,776 KB
testcase_29 AC 73 ms
5,472 KB
testcase_30 AC 73 ms
5,500 KB
testcase_31 AC 96 ms
6,668 KB
testcase_32 AC 97 ms
6,676 KB
testcase_33 AC 71 ms
5,472 KB
testcase_34 AC 71 ms
5,476 KB
testcase_35 AC 94 ms
6,568 KB
testcase_36 AC 95 ms
6,480 KB
testcase_37 AC 19 ms
4,384 KB
testcase_38 AC 19 ms
4,380 KB
testcase_39 AC 16 ms
4,380 KB
testcase_40 AC 16 ms
4,380 KB
testcase_41 AC 34 ms
4,380 KB
testcase_42 AC 33 ms
4,380 KB
testcase_43 AC 27 ms
4,380 KB
testcase_44 AC 177 ms
10,508 KB
testcase_45 AC 75 ms
5,572 KB
testcase_46 AC 26 ms
4,380 KB
testcase_47 AC 128 ms
7,820 KB
testcase_48 AC 118 ms
7,780 KB
testcase_49 AC 118 ms
7,876 KB
testcase_50 AC 91 ms
6,500 KB
testcase_51 AC 5 ms
4,384 KB
testcase_52 AC 159 ms
9,608 KB
testcase_53 AC 179 ms
10,872 KB
testcase_54 AC 189 ms
10,808 KB
testcase_55 AC 187 ms
10,828 KB
testcase_56 AC 188 ms
10,872 KB
testcase_57 AC 191 ms
10,880 KB
testcase_58 AC 187 ms
10,860 KB
testcase_59 AC 188 ms
10,816 KB
testcase_60 AC 183 ms
10,872 KB
testcase_61 AC 173 ms
10,852 KB
testcase_62 AC 188 ms
10,872 KB
testcase_63 AC 188 ms
10,852 KB
testcase_64 AC 192 ms
10,860 KB
testcase_65 AC 188 ms
10,776 KB
testcase_66 AC 186 ms
10,864 KB
testcase_67 AC 195 ms
10,872 KB
testcase_68 AC 183 ms
10,856 KB
testcase_69 AC 170 ms
10,884 KB
testcase_70 AC 171 ms
10,872 KB
testcase_71 AC 165 ms
10,880 KB
testcase_72 AC 193 ms
10,872 KB
testcase_73 AC 164 ms
10,776 KB
testcase_74 AC 161 ms
10,804 KB
testcase_75 AC 162 ms
10,808 KB
testcase_76 AC 161 ms
10,820 KB
testcase_77 AC 162 ms
10,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{BufRead, Write};

struct Lines<B> { b: B, buf: Vec<u8> }
 
impl<B: BufRead> Lines<B> {
    fn next(&mut self) -> &str {
        self.buf.clear();
        self.b.read_until(b'\n', &mut self.buf).ok();
        if self.buf.ends_with(&[b'\n']) {
            self.buf.pop();
            if self.buf.ends_with(&[b'\r']) {
                self.buf.pop();
            }
        }
        std::str::from_utf8(&self.buf).unwrap()
    }
}

macro_rules! parse {
    ($s:expr, Usize1) => (parse!($s, usize) - 1);
    ($s:expr, Bytes) => ($s.as_bytes().to_vec());
    ($s:expr, Chars) => ($s.chars().collect::<Vec<_>>());
    ($s:expr, $t:ty) => ($s.parse::<$t>().unwrap());
}

macro_rules! scan {
    ($iter:expr, ($($t:ident),*)) => (
        ($(scan!($iter, $t)),*)
    );
    ($iter:expr, [$t:ident]) => (
        $iter.map(|s| parse!(s, $t)).collect::<Vec<_>>()
    );
    ($iter:expr, $t:ident) => (
        parse!($iter.next().unwrap(), $t)
    );
}

macro_rules! read {
    ($lines:expr, [$t:tt; $n:expr]) => (
        (0..$n).map(|_| read!($lines, $t)).collect::<Vec<_>>()
    );
    ($lines:expr, $t:tt) => ({
        let iter = &mut $lines.next().split(' ');
        scan!(iter, $t)
    });
}

fn pow_mod(mut a: usize, mut n: usize, m: usize) -> usize {
    let mut res = 1;
    while n > 0 {
        if n & 1 > 0 {
            res = res * a % m;
        }
        a = a * a % m;
        n >>= 1;
    }
    res
}

fn run<B: BufRead, W: Write>(mut lines: Lines<B>, mut writer: W) {
    let (n, k, m) = read!(lines, (usize, usize, usize));
    let mut a = read!(lines, [[usize]; 4]);

    for a in a.iter_mut() {
        a.sort();
    }

    let mut ans = 0;
    for i in 0..n {
        let max = a.iter().map(|a| a[i]).max().unwrap();
        let min = a.iter().map(|a| a[i]).min().unwrap();
        ans = (ans + pow_mod(max - min, k, m)) % m;
    }
    writeln!(writer, "{}", ans).ok();
}

fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let lines = Lines { b: stdin.lock(), buf: Vec::new() };
    run(lines, std::io::BufWriter::new(stdout.lock()));
}
0