結果
問題 | No.1359 [Zelkova 3rd Tune] 四人セゾン |
ユーザー |
![]() |
提出日時 | 2021-01-22 22:13:48 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 330 ms / 2,000 ms |
コード長 | 2,095 bytes |
コンパイル時間 | 15,730 ms |
コンパイル使用メモリ | 379,436 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-12-28 01:37:44 |
合計ジャッジ時間 | 34,922 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 75 |
ソースコード
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()));}