結果

問題 No.2752 文字列の数え上げ mod 998244353
ユーザー KeiKei
提出日時 2024-05-10 23:46:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 719 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 84,812 KB
実行使用メモリ 814,080 KB
最終ジャッジ日時 2024-05-10 23:46:38
合計ジャッジ時間 3,466 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 MLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
using namespace std;
const int MOD = 998244353;
map<long long, long long> mf, mg;
//26^N
long long g(long long N) {
  if (mg[N]) return mg[N];
  if (N == 0) return 1;
  if (N == 1) return 26;
  if (N % 2 == 1) {
    return mg[N] = (26 * g(N)) % MOD;
  }
  long long tmp = g(N / 2);
  return mg[N] = tmp * tmp % MOD;
}
long long f(long long L) {
  if (mf[L]) return mf[L];
  if (L == 0) return 0;
  if (L == 1) return 26;
  if (L % 2 == 1) {
    return mf[L] = (26 + 26 * f(L - 1)) % MOD;
  }
  return mf[L] = (f(L / 2) + g(L / 2) * f(L / 2) % MOD) % MOD;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long L;
    cin >> L;
    cout << f(L) << endl;
  }
}
0