結果

問題 No.2941 Sigma Music Game Score Problem
ユーザー NakLon131
提出日時 2024-10-19 11:11:45
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 206 ms / 2,500 ms
コード長 1,659 bytes
コンパイル時間 12,888 ms
コンパイル使用メモリ 403,944 KB
実行使用メモリ 33,028 KB
最終ジャッジ日時 2024-10-19 11:12:02
合計ジャッジ時間 16,377 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
	const MOD93: usize = 998244353;
    input!{
		m: usize, n: usize,
		mut x: [usize; n],
	}
	x.insert(0, 0);
	x.push(m+1); // 番兵を両端に入れる

	// 階差はn+1個出来る
	let mut diff_list = vec![0; n+1];
	for i in 0..n+1 {
		diff_list[i] = x[i+1] - x[i];
	}

	// (各階差-1)の2乗の和を数え上げ
	let mut ans = 0;
	for i in 0..n+1 {
		ans += multi_sum_calc(diff_list[i]-1, MOD93);
		ans %= MOD93;
	}
	println!("{}", ans);
}

fn multi_sum_calc(x: usize, mods: usize) -> usize
{
	let x = x % mods;

	// (1/6)*x*(x+1)*(2x+1)
	let mut ret = x; ret %= mods;
	ret *= x+1; 	ret %= mods;
	ret *= 2*x+1;	ret %= mods;
	ret = div(ret, 6, mods);
	ret
}

// 繰り返し二乗法
fn mod_pow(mut a: usize, mut b: usize, mods: usize) -> usize {
	let mut res = 1;
	while b > 0 {
		if b % 2 == 1 {
			res *= a;
			res %= mods;
		}
		a *= a;
		a %= mods;
		b >>= 1;
	}
	res
}
// 繰り返し二乗法による除算
fn div(a: usize, b: usize, mods: usize) -> usize {
	let mut ans = a;
	let x = mod_pow(b, mods - 2, mods);
	ans *= x;
	ans %= mods;
	ans
}

/*
1000000000000000 1
500000000000000

*/

// const MOD17: usize = 1000000007;

// const INF: usize = 1 << 60;
// let dx = vec![!0, 0, 1, 0]; // 上左下右
// let dy = vec![0, !0, 0, 1]; // 上左下右
// let d = vec!{(!0, 0), (0, !0), (1, 0), (0, 1)}; // 上左下右

#[allow(unused)]
use proconio::{input, marker::Chars, marker::Usize1};

#[allow(unused)]
use std::{
	mem::swap,
	cmp::min, cmp::max,
	cmp::Reverse,
	collections::HashSet, collections::BTreeSet,
	collections::HashMap, collections::BTreeMap,
	collections::BinaryHeap,
	collections::VecDeque,
	iter::FromIterator,
};
0