結果

問題 No.2752 文字列の数え上げ mod 998244353
ユーザー KeiKei
提出日時 2024-05-10 23:48:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 723 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 85,760 KB
実行使用メモリ 175,136 KB
最終ジャッジ日時 2024-05-10 23:48:08
合計ジャッジ時間 4,857 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 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 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 TLE -
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 - 1)) % 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