結果

問題 No.1540 級数おもちゃ
コンテスト
ユーザー Re_menal2
提出日時 2021-04-28 23:51:11
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,191 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,172 ms
コンパイル使用メモリ 187,480 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2026-05-16 07:51:58
合計ジャッジ時間 4,152 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:39:12: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   39 |     a = (a + (A[i]*two[i] % MM)*I[i][0] % MM) % MM;
      |         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:37:8: note: 'a' was declared here
   37 |   long a, b, c = 0;
      |        ^
main.cpp:40:12: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
   40 |     b = (b + (A[i]*two[i] % MM)*I[i][1] % MM) % MM;
      |         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:37:11: note: 'b' was declared here
   37 |   long a, b, c = 0;
      |           ^

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

const int MM = 998244353;

long modpow(long a, long b, long mod) {
    if (b == 0) {
          return 1;
    }
    if ((b & 1) == 0) {
      return modpow((a * a) % mod, b >> 1, mod);
    }
    return (a * modpow(a, b - 1, mod)) % mod;
}

int main() {
  int N; cin >> N;
  vector<int> A(N+1);
  for (int i=0; i<N; i++) cin >> A[i];

  vector<long> two(N+1);
  two[0] = 1;
  for (int i=1; i<N; i++) {
    two[i] = 2*two[i-1] % MM;
  }

  vector<vector<long>> I(N+1, vector<long>(3));
  I[0][2] = modpow(6, MM-2, MM); I[0][0] = 0; I[0][1] = 0;
  I[1][0] = 1; I[1][1] = modpow(-2, MM-2, MM)+MM; I[1][2] = 0;
  for (int i=2; i<N; i++) {
    I[i][0] = ((i-1)*I[i-1][0] % MM) * modpow(i, MM-2, MM) % MM;
    I[i][1] = (((i-1)*I[i-1][1] % MM) * modpow(i, MM-2, MM) % MM - modpow(two[i], MM-2, MM)) % MM;
    if (I[i][1] < 0) I[i][1] += MM;
    I[i][2] = ((i-1)*I[i-1][2] % MM) * modpow(i, MM-2, MM) % MM;
  }

  long a, b, c = 0;
  for (int i=0; i<N; i++) {
    a = (a + (A[i]*two[i] % MM)*I[i][0] % MM) % MM;
    b = (b + (A[i]*two[i] % MM)*I[i][1] % MM) % MM;
    c = (c + (A[i]*two[i] % MM)*I[i][2] % MM) % MM;
  }

  cout << a << b << c << endl;
}
0