結果
問題 |
No.2941 Sigma Music Game Score Problem
|
ユーザー |
![]() |
提出日時 | 2024-10-21 10:43:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 182 ms / 2,500 ms |
コード長 | 1,801 bytes |
コンパイル時間 | 514 ms |
コンパイル使用メモリ | 41,984 KB |
最終ジャッジ日時 | 2025-02-24 22:10:21 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:73:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 73 | scanf("%lld%d", &m, &n); | ~~~~~^~~~~~~~~~~~~~~~~~ main.cpp:74:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 74 | for (int i = 1; i <= n; i++) scanf("%lld", xs + i); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 2941.cc: No.2941 Sigma Music Game Score Problem - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 1000000; const int MOD = 998244353; /* typedef */ using ll = long long; template<const int MOD> struct MI { int v; MI(): v() {} MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; } MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; } explicit operator int() const { return v; } MI operator+(const MI m) const { return MI(v + m.v); } MI operator-(const MI m) const { return MI(v + MOD - m.v); } MI operator*(const MI m) const { return MI((long long)v * m.v); } MI &operator+=(const MI m) { return (*this = *this + m); } MI &operator-=(const MI m) { return (*this = *this - m); } MI &operator*=(const MI m) { return (*this = *this * m); } bool operator==(const MI m) const { return v == m.v; } bool operator!=(const MI m) const { return v != m.v; } MI pow(int n) const { // a^n % MOD MI pm = 1, a = *this; while (n > 0) { if (n & 1) pm *= a; a *= a; n >>= 1; } return pm; } MI inv() const { return pow(MOD - 2); } MI operator/(const MI m) const { return *this * m.inv(); } MI &operator/=(const MI m) { return (*this = *this / m); } }; using mi = MI<MOD>; /* global variables */ mi inv6 = mi(6).inv(); ll xs[MAX_N + 2]; /* subroutines */ inline mi sigma2(ll n) { return mi(n) * mi(n + 1) * mi(n * 2 + 1) * inv6; } /* main */ int main() { ll m; int n; scanf("%lld%d", &m, &n); for (int i = 1; i <= n; i++) scanf("%lld", xs + i); xs[0] = 0, xs[n + 1] = m + 1; mi sum = 0; for (int i = 0; i <= n; i++) { ll d = xs[i + 1] - xs[i] - 1; sum += sigma2(d); } printf("%d\n", (int)sum); return 0; }