結果

問題 No.2941 Sigma Music Game Score Problem
ユーザー strangerxxxstrangerxxx
提出日時 2024-10-25 17:12:48
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 213 ms / 2,500 ms
コード長 6,684 bytes
コンパイル時間 13,865 ms
コンパイル使用メモリ 402,468 KB
実行使用メモリ 33,232 KB
最終ジャッジ日時 2024-10-25 17:13:08
合計ジャッジ時間 18,345 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 155 ms
24,552 KB
testcase_17 AC 174 ms
27,116 KB
testcase_18 AC 200 ms
31,908 KB
testcase_19 AC 158 ms
24,996 KB
testcase_20 AC 131 ms
20,764 KB
testcase_21 AC 57 ms
10,068 KB
testcase_22 AC 64 ms
10,556 KB
testcase_23 AC 58 ms
10,088 KB
testcase_24 AC 202 ms
32,472 KB
testcase_25 AC 25 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 1 ms
6,944 KB
testcase_29 AC 49 ms
14,616 KB
testcase_30 AC 74 ms
21,548 KB
testcase_31 AC 213 ms
33,056 KB
testcase_32 AC 212 ms
33,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// -*- coding:utf-8-unix -*-
#![allow(dead_code, unused_imports, unused_macros)]
fn main() {
    input! {
        m: u128,
        n: usize,
        x: [u128; n],
    }
    let md = MOD998244353 as u128;
    let mut a = vec![0];
    a.extend(x);
    a.push(m + 1);
    let mut ans = 0;
    for i in a.windows(2) {
        let diff = (&i[1] - &i[0] - 1) % md;
        ans += diff * (diff + 1) * (2 * diff + 1) / 6 % md;
        ans %= md;
    }
    p!(ans % md);
}
// use ::num;
// use itertools::Itertools;
// use ac_library::*;
// use proconio::input;
use cmp::Ordering::*;
// use itertools::Itertools;
// use itertools_num::ItertoolsNum;
// use maplit;
// use ordered_float::OrderedFloat;
use std::cmp::*;
use std::collections::*;
use std::fmt::*;
use std::hash::*;
use std::io::{stdin, stdout, Write};
use std::iter::FromIterator;
use std::str::FromStr;
use std::*;
// use superslice::*;
// use rand::Rng;
// use rand::rngs::SmallRng;
// use rand::seq::SliceRandom;
const MOD1000000007: i64 = 1000000007;
const MOD998244353: i64 = 998244353;
const MOD: i64 = 998244353;
const UMOD: usize = MOD as usize;
const PI: f64 = f64::consts::PI;
const DIRS: [char; 4] = ['U', 'D', 'L', 'R'];
const DIJ: [(usize, usize); 4] = [(!0, 0), (1, 0), (0, !0), (0, 1)];
#[macro_export]
macro_rules! p {
    ($($arg:expr),*) => {
        {
            print!("{}\n", vec![$(format!("{}", $arg)),*].join(" "));
        }
    };
}
#[macro_export]
macro_rules! vp {
    ($x:expr) => {
        print!(
            "{}\n",
            $x.iter()
                .map(|x| x.to_string())
                .collect::<Vec<_>>()
                .join(" ")
        );
    };
}
#[macro_export]
macro_rules! dprint {
    ($($arg:expr),*) => {
        #[allow(unused_assignments)]
        {
            let mut first = true;
            $(
                if !first {
                    eprint!(" ");
                }
                eprint!("{:?}", $arg);
                first = false;
            )*
            eprint!("\n");
        }
    };
}
#[macro_export]
macro_rules! yesno {
    ($val:expr) => {
        if $val {
            print!("Yes\n");
        } else {
            print!("No\n");
        }
    };
}
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn read_mat<T: FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn readii() -> (i64, i64) {
    let vec: Vec<i64> = read_vec();
    (vec[0], vec[1])
}
fn readiii() -> (i64, i64, i64) {
    let vec: Vec<i64> = read_vec();
    (vec[0], vec[1], vec[2])
}
fn readuu() -> (usize, usize) {
    let vec: Vec<usize> = read_vec();
    (vec[0], vec[1])
}
fn readff() -> (f64, f64) {
    let vec: Vec<f64> = read_vec();
    (vec[0], vec[1])
}
fn readcc() -> (char, char) {
    let vec: Vec<char> = read_vec();
    (vec[0], vec[1])
}
fn readuuu() -> (usize, usize, usize) {
    let vec: Vec<usize> = read_vec();
    (vec[0], vec[1], vec[2])
}
fn readiiii() -> (i64, i64, i64, i64) {
    let vec: Vec<i64> = read_vec();
    (vec[0], vec[1], vec[2], vec[3])
}
fn readuuuu() -> (usize, usize, usize, usize) {
    let vec: Vec<usize> = read_vec();
    (vec[0], vec[1], vec[2], vec[3])
}
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[macro_export]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[macro_export]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
pub trait BinarySearch<T> {
    fn bisect_left(&self, key: T) -> usize;
    fn bisect_right(&self, key: T) -> usize;
}
impl<T> BinarySearch<T> for [T]
where
    T: Ord,
{
    fn bisect_left(&self, key: T) -> usize {
        let mut ng = -1 as isize;
        let mut ok = self.len() as isize;
        while ok - ng > 1 {
            let mid = (ok + ng) / 2;
            if key <= self[mid as usize] {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        ok as usize
    }

    fn bisect_right(&self, key: T) -> usize {
        let mut ng = -1 as isize;
        let mut ok = self.len() as isize;
        while ok - ng > 1 {
            let mid = (ok + ng) / 2;
            if key < self[mid as usize] {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        ok as usize
    }
}
pub fn next_permutation<T: Ord>(a: &mut [T]) -> bool {
    let Some(i) = a.windows(2).rposition(|w| w[0] < w[1]) else {
        return false;
    };
    let j = a.iter().rposition(|x| x > &a[i]).unwrap();
    a.swap(i, j);
    a[i + 1..].reverse();
    true
}
fn mod_pow<T>(x: T, a: T, md: T) -> T
where
    T: Copy
        + From<u8>
        + std::ops::Mul<Output = T>
        + std::ops::Rem<Output = T>
        + std::ops::Shr<u64, Output = T>
        + std::ops::Add<Output = T>
        + std::ops::BitAnd<Output = T>
        + PartialOrd
        + Default
        + std::ops::ShrAssign<i32>,
{
    let mut res = T::from(1);
    let mut base = x;
    let mut ai = a;

    while ai > T::from(0) {
        if ai & T::from(1) == T::from(1) {
            res = res * base % md;
        }
        ai >>= 1;
        base = (base * base) % md;
    }

    res
}
0