結果

問題 No.1299 Random Array Score
ユーザー Moss_LocalMoss_Local
提出日時 2020-11-28 07:57:47
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 10,892 bytes
コンパイル時間 14,093 ms
コンパイル使用メモリ 399,904 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-12 22:08:07
合計ジャッジ時間 16,085 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 1 ms
6,812 KB
testcase_03 AC 15 ms
6,944 KB
testcase_04 AC 14 ms
6,944 KB
testcase_05 AC 13 ms
6,944 KB
testcase_06 AC 11 ms
6,944 KB
testcase_07 AC 11 ms
6,944 KB
testcase_08 AC 14 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 9 ms
6,944 KB
testcase_13 AC 14 ms
6,944 KB
testcase_14 AC 10 ms
6,940 KB
testcase_15 AC 11 ms
6,944 KB
testcase_16 AC 10 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 7 ms
6,940 KB
testcase_19 AC 8 ms
6,944 KB
testcase_20 AC 4 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 10 ms
6,940 KB
testcase_24 AC 12 ms
6,940 KB
testcase_25 AC 10 ms
6,944 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 4 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 4 ms
6,940 KB
testcase_30 AC 9 ms
6,940 KB
testcase_31 AC 4 ms
6,944 KB
testcase_32 AC 14 ms
6,944 KB
testcase_33 AC 15 ms
6,940 KB
testcase_34 AC 6 ms
6,940 KB
testcase_35 AC 16 ms
6,944 KB
testcase_36 AC 6 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unnecessary parentheses around type
  --> src/main.rs:39:15
   |
39 | fn readi() -> (i64) {
   |               ^   ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
39 - fn readi() -> (i64) {
39 + fn readi() -> i64 {
   |

warning: unused macro definition: `notnan`
   --> src/main.rs:111:14
    |
111 | macro_rules! notnan(($lit:literal $(,)?) => (NotNan::new($lit).unwrap()));
    |              ^^^^^^
    |
    = note: `#[warn(unused_macros)]` on by default

warning: unused macro definition: `mint`
   --> src/main.rs:137:14
    |
137 | macro_rules! mint {
    |              ^^^^

warning: unnecessary parentheses around assigned value
   --> src/main.rs:230:19
    |
230 |         self.0 *= (rhs.0 % MOD);
    |                   ^           ^
    |
help: remove these parentheses
    |
230 -         self.0 *= (rhs.0 % MOD);
230 +         self.0 *= rhs.0 % MOD;
    |

warning: unused variable: `a2`
   --> src/main.rs:399:14
    |
399 |         let (a2, e2) = mod_fact(k, p, fact);
    |              ^^ help: if this is intentional, prefix it with an underscore: `_a2`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `a3`
   --> src/main.rs:400:14
    |
400 |         let (a3, e3) = mod_fact(n - k, p, fact);
    |              ^^ help: if this is intentional, prefix it with an underscore: `_a3`

warning: unused variable: `mk`
   --> src/main.rs:423:9
    |
423 |     let mk = Mint(k as i64);
    |         ^^ help: if this is intentional, prefix it with an underscore: `_mk`

warning: unused variable: `mn`
   --> src/main.rs:425:9
    |
425 |     let mn = Mint(n as i64);
    |         ^^ help: if this is intentional, prefix it with an underscore: `_mn`

warning: variable does not need to be mutable
   --> src/main.rs:421:9
    |
421 |     let mut s = Mint(s as i64);
    |         ----^
    |         |
    |         help: remove this `mut`
    |
    = note: `#[warn(unused_mut)]` on by defa

ソースコード

diff #

// -*- coding:utf-8-unix -*-

#![allow(dead_code)]
#![allow(unused_imports)]
use std::cmp::Ordering::*;

use std::cmp;
use std::cmp::Ordering;
use std::collections::*;
use std::convert::*;
use std::convert::{From, Into};
use std::fmt::Debug;
use std::fs::File;
use std::io::prelude::*;
use std::io::*;
use std::marker::Copy;
use std::mem::*;
use std::ops::{Add, Mul, Neg, Sub};
use std::str;
use std::vec;
const INF: i64 = 1223372036854775807;
const MEM_SIZE: usize = 202020;
// const MOD: i64 = 1000000007;
const MOD: i64 = 998244353;

use std::cmp::*;
use std::collections::*;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn readi() -> (i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    iter.next().unwrap().parse::<i64>().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn readii() -> (i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}

fn readff() -> (f64, f64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<f64>().unwrap(),
        iter.next().unwrap().parse::<f64>().unwrap(),
    )
}

#[allow(dead_code)]
fn readiii() -> (i64, i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}
#[allow(dead_code)]
fn readuu() -> (usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

fn readcc() -> (char, char) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<char>().unwrap(),
        iter.next().unwrap().parse::<char>().unwrap(),
    )
}

macro_rules! notnan(($lit:literal $(,)?) => (NotNan::new($lit).unwrap()));
#[allow(dead_code)]
fn readuuu() -> (usize, usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[allow(dead_code)]
fn readuuuu() -> (usize, usize, usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

macro_rules! mint {
    (a :expr ) => {
        Mint::new({ a })
    };
}
#[derive(Copy, Clone)]
pub struct Mint(i64);
impl Mint {
    fn new(x: i64) -> Self {
        Mint(x.rem_euclid(MOD))
    }
    fn pow(self, n: usize) -> Self {
        match n {
            0 => Mint::new(1),
            _ => {
                let mut a = self.pow(n >> 1);
                a *= a;
                if n & 1 == 1 {
                    a *= self;
                }
                a
            }
        }
    }
    fn inv(self) -> Self {
        self.pow((MOD - 2) as usize)
    }
}
impl std::ops::Neg for Mint {
    type Output = Mint;
    fn neg(self) -> Self::Output {
        Self::new(-self.0)
    }
}
impl std::ops::AddAssign<Mint> for Mint {
    fn add_assign(&mut self, rhs: Self) {
        self.0 += rhs.0;
        self.0 %= MOD;
    }
}
impl std::ops::AddAssign<i64> for Mint {
    fn add_assign(&mut self, rhs: i64) {
        *self += Mint::new(rhs);
    }
}
impl std::ops::AddAssign<usize> for Mint {
    fn add_assign(&mut self, rhs: usize) {
        *self += Mint::new(rhs as i64);
    }
}
impl<T> std::ops::Add<T> for Mint
where
    Mint: std::ops::AddAssign<T>,
{
    type Output = Self;
    fn add(self, other: T) -> Self {
        let mut res = self;
        res += other;
        res
    }
}
impl std::ops::SubAssign<Mint> for Mint {
    fn sub_assign(&mut self, rhs: Self) {
        self.0 -= rhs.0;
        if self.0 < 0 {
            self.0 += MOD;
        }
    }
}
impl std::ops::SubAssign<i64> for Mint {
    fn sub_assign(&mut self, rhs: i64) {
        *self -= Mint::new(rhs);
    }
}
impl std::ops::SubAssign<usize> for Mint {
    fn sub_assign(&mut self, rhs: usize) {
        *self -= Mint::new(rhs as i64);
    }
}
impl<T> std::ops::Sub<T> for Mint
where
    Mint: std::ops::SubAssign<T>,
{
    type Output = Self;
    fn sub(self, other: T) -> Self {
        let mut res = self;
        res -= other;
        res
    }
}
impl std::ops::MulAssign<Mint> for Mint {
    fn mul_assign(&mut self, rhs: Self) {
        self.0 %= MOD;
        self.0 *= (rhs.0 % MOD);
        self.0 %= MOD;
    }
}
impl std::ops::MulAssign<i64> for Mint {
    fn mul_assign(&mut self, rhs: i64) {
        *self *= Mint::new(rhs);
    }
}
impl std::ops::MulAssign<usize> for Mint {
    fn mul_assign(&mut self, rhs: usize) {
        *self *= Mint::new(rhs as i64);
    }
}
impl<T> std::ops::Mul<T> for Mint
where
    Mint: std::ops::MulAssign<T>,
{
    type Output = Self;
    fn mul(self, other: T) -> Self {
        let mut res = self;
        res *= other;
        res
    }
}
impl std::ops::DivAssign<Mint> for Mint {
    fn div_assign(&mut self, rhs: Self) {
        *self *= rhs.inv();
    }
}
impl std::ops::DivAssign<i64> for Mint {
    fn div_assign(&mut self, rhs: i64) {
        *self /= Mint::new(rhs);
    }
}
impl std::ops::DivAssign<usize> for Mint {
    fn div_assign(&mut self, rhs: usize) {
        *self /= Mint::new(rhs as i64);
    }
}
impl<T> std::ops::Div<T> for Mint
where
    Mint: std::ops::DivAssign<T>,
{
    type Output = Self;
    fn div(self, other: T) -> Self {
        let mut res = self;
        res /= other;
        res
    }
}
impl std::fmt::Display for Mint {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
impl std::ops::Deref for Mint {
    type Target = i64;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}
impl std::ops::DerefMut for Mint {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.0
    }
}

#[allow(dead_code)]
pub fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
#[allow(dead_code)]
pub fn lcm(a: usize, b: usize) -> usize {
    a / gcd(a, b) * b
}
#[allow(dead_code)]
/// (gcd, x, y)
pub fn extgcd(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (gcd, x, y) = extgcd(b, a % b);
        (gcd, y, x - (a / b) * y)
    }
}
#[allow(dead_code)]
/// x ^ n % m
pub fn mod_pow(x: usize, n: usize, m: usize) -> usize {
    let mut res = 1;
    let mut x = x % m;
    let mut n = n;
    while n > 0 {
        if n & 1 == 1 {
            res = (res * x) % m;
        }
        x = (x * x) % m;
        n >>= 1;
    }
    res
}
#[allow(dead_code)]
pub fn mod_inverse(a: usize, m: usize) -> usize {
    let (_, x, _) = extgcd(a as i64, m as i64);
    ((m as i64 + x) as usize % m) % m
}
#[allow(dead_code)]
pub fn fact_table(len: usize, m: usize) -> Vec<usize> {
    let mut res = vec![1; len + 1];
    for i in 1..len + 1 {
        res[i] = (i as usize * res[i - 1]) % m;
    }
    res
}
#[allow(dead_code)]
/// Factorial and Inverse factorial table
pub fn fact_inv_table(size: usize, m: usize) -> (Vec<usize>, Vec<usize>) {
    let mut fact = vec![1; size];
    let mut fact_inv = vec![1; size];
    for i in 2..size {
        fact[i] = fact[i - 1] * i as usize % m;
        fact_inv[i] = m - ((m / i as usize) * fact_inv[(m % i as usize) as usize] % m);
    }
    for i in 1..size {
        fact_inv[i] = fact_inv[i - 1] * fact_inv[i] % m;
    }
    (fact, fact_inv)
}
#[allow(dead_code)]
/// (a mod p, e when n! = a p\^e)
pub fn mod_fact(n: usize, p: usize, fact: &[usize]) -> (usize, usize) {
    if n == 0 {
        (1, 0)
    } else {
        let (a, b) = mod_fact(n / p, p, fact);
        let pow = b + n / p;
        if n / p % 2 != 0 {
            (a * (p - fact[(n % p) as usize]) % p, pow)
        } else {
            (a * fact[(n % p) as usize] % p, pow)
        }
    }
}
#[allow(dead_code)]
/// C(n, k) % p
pub fn mod_comb(n: usize, k: usize, p: usize, fact: &[usize]) -> usize {
    if n < k {
        0
    } else {
        let (a1, e1) = mod_fact(n, p, fact);
        let (a2, e2) = mod_fact(k, p, fact);
        let (a3, e3) = mod_fact(n - k, p, fact);
        if e1 > e2 + e3 {
            0
        } else {
            a1 * mod_inverse(a2 * a3 % p, p) % p
        }
    }
}

pub fn mod_perm(n: usize, k: usize, p: usize, fact: &[usize]) -> usize {
    if n < k {
        0
    } else {
        let (a1, e1) = mod_fact(n, p, fact);
        let (a2, e2) = mod_fact(k, p, fact);
        let (a3, e3) = mod_fact(n - k, p, fact);
        if e1 > e2 + e3 {
            0
        } else {
            a1 % p
        }
    }
}
#[allow(dead_code)]
/// H(n, k) % p
pub fn mod_comb_repetition(n: usize, k: usize, p: usize, fact: &[usize]) -> usize {
    mod_comb(n - 1 + k, n - 1, p, fact)
}

fn solve() {
    let (n, k) = readuu();
    let vec: Vec<usize> = read_vec();
    let mut s = 0;
    for i in 0..n {
        s += vec[i];
    }
    let mut s = Mint(s as i64);
    let mut res = Mint(0);
    let mk = Mint(k as i64);
    // let kk = (mk * (mk + Mint(1)) * (Mint(2) * mk + Mint(1)) + Mint(3) * mk * (mk + Mint(1))) / Mint(12);
    let mn = Mint(n as i64);
    // let mut kk = mk * mn.pow(k + 1) - mk * mn.pow(k) - mn.pow(k) + Mint(1);
    // kk /= (mn - Mint(1)).pow(2);

    // println!("{:?}", kk.0);
    // let kk = Mint(1) + mn.pow(k - 1);
    // let kk = mk * (mk + Mint(1)) / Mint(2) * mn.pow(k - 1);
    res += Mint(2).pow(k) * s;
    println!("{:?}", res.0);
}

fn main() {
    solve()
}
0