Submission #50246111


Source Code Expand

#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define FR first
#define SE second
#define int long long
using namespace std;
inline int read() {
  int x = 0; bool op = false;
  char c = getchar();
  while(!isdigit(c))op |= (c == '-'), c = getchar();
  while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return op ? -x : x;
}
const int N = 2e3 + 10;
const int P = 998244353;
void add(int &a, int b) {a += b; a >= P ? a -= P : 0;}
void sub(int &a, int b) {a -= b; a < 0 ? a += P : 0;}
int ksm(int x, int k) {
  int res = 1;
  for(int pw = x; k; (k & 1) ? res = 1ll * res * pw % P : 0, pw = 1ll * pw * pw % P, k >>= 1);
  return res;
}
int n, m;
int a[N], f[N], sf[N], fac[N], ifac[N];
void init() {
  fac[0] = ifac[0] = 1;
  for(int i = 1; i < N; i++)fac[i] = 1ll * fac[i - 1] * i % P;
  ifac[N - 1] = ksm(fac[N - 1], P - 2);
  for(int i = N - 2; i; i--)ifac[i] = 1ll * ifac[i + 1] * (i + 1) % P;
  return ;
}
int pre[N], suf[N];
int calc(int x, int n) {
  if(x <= n)return sf[x];
  pre[0] = suf[n + 1] = 1;
  for(int i = 1; i <= n; i++)pre[i] = suf[i] = (x - i) % P;
  for(int i = 1; i <= n; i++)pre[i] = 1ll * pre[i - 1] * pre[i] % P;
  for(int i = n; i; i--)suf[i] = 1ll * suf[i + 1] * suf[i] % P;
  int res = 0;
  for(int i = 1; i <= n; i++) {
    int c1 = 1ll * ifac[i - 1] * ifac[n - i] % P;
    int c2 = 1ll * pre[i - 1] * suf[i + 1] % P;
    int val = 1ll * c1 * c2 % P * sf[i] % P;
    ((n - i) & 1) ? sub(res, val) : add(res, val);
  }
  return res;
} 
signed main() {
  init();
  n = read(); m = read();
  for(int i = 1; i <= n; i++)a[i] = read();
  int lim = m;
  for(int i = 1; i <= min(lim, n + 2); i++)f[i] = 1;
  for(int i = n; i; i--) {
    for(int j = 1; j <= min(lim, n + 2); j++)sf[j] = (sf[j - 1] + f[j]) % P;
    int val = calc(lim, n + 2); lim /= a[i]; 
    // cout << i << ' ' << val << ' ' << lim << endl;
    for(int j = 1; j <= min(lim, n + 2); j++)f[j] = (val - calc(j * a[i] - 1, n + 2) + P) % P;
    // for(int j = 1; j <= min(lim, n + 10); j++)printf("%lld ", f[j]); putchar('\n');
  }
  for(int j = 1; j <= min(lim, n + 2); j++)sf[j] = (sf[j - 1] + f[j]) % P;
  printf("%lld\n", calc(lim, n + 2));
  return 0;
}

Submission Info

Submission Time
Task F - Growth Rate
User thebighead
Language C++ 20 (gcc 12.2)
Score 1000
Code Size 2322 Byte
Status AC
Exec Time 438 ms
Memory 3972 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 4
AC × 60
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt, 02_rand_01.txt, 02_rand_02.txt, 02_rand_03.txt, 02_rand_04.txt, 02_rand_05.txt, 03_rand_fill_01.txt, 03_rand_fill_02.txt, 03_rand_fill_03.txt, 03_rand_fill_04.txt, 03_rand_fill_05.txt, 03_rand_fill_06.txt, 03_rand_fill_07.txt, 03_rand_fill_08.txt, 03_rand_fill_09.txt, 03_rand_fill_10.txt, 04_only_small_01.txt, 04_only_small_02.txt, 04_only_small_03.txt, 04_only_small_04.txt, 04_only_small_05.txt, 05_only_small_fill_01.txt, 05_only_small_fill_02.txt, 05_only_small_fill_03.txt, 05_only_small_fill_04.txt, 05_only_small_fill_05.txt, 05_only_small_fill_06.txt, 05_only_small_fill_07.txt, 05_only_small_fill_08.txt, 05_only_small_fill_09.txt, 05_only_small_fill_10.txt, 06_only_1_01.txt, 06_only_1_02.txt, 06_only_1_03.txt, 06_only_1_04.txt, 06_only_1_05.txt, 07_only_2_01.txt, 07_only_2_02.txt, 07_only_2_03.txt, 07_only_2_04.txt, 07_only_2_05.txt, 08_only_1_2_01.txt, 08_only_1_2_02.txt, 08_only_1_2_03.txt, 08_only_1_2_04.txt, 08_only_1_2_05.txt, 09_N_equal_1_01.txt, 09_N_equal_1_02.txt, 09_N_equal_1_03.txt, 09_N_equal_1_04.txt, 09_N_equal_1_05.txt, 10_handmade_01.txt, 10_handmade_02.txt, 10_handmade_03.txt, 10_handmade_04.txt, 10_handmade_05.txt, 10_handmade_06.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 1 ms 3644 KiB
01_sample_02.txt AC 1 ms 3752 KiB
01_sample_03.txt AC 1 ms 3868 KiB
01_sample_04.txt AC 1 ms 3796 KiB
02_rand_01.txt AC 1 ms 3652 KiB
02_rand_02.txt AC 1 ms 3648 KiB
02_rand_03.txt AC 2 ms 3908 KiB
02_rand_04.txt AC 2 ms 3880 KiB
02_rand_05.txt AC 2 ms 3808 KiB
03_rand_fill_01.txt AC 39 ms 3876 KiB
03_rand_fill_02.txt AC 273 ms 3792 KiB
03_rand_fill_03.txt AC 332 ms 3756 KiB
03_rand_fill_04.txt AC 103 ms 3792 KiB
03_rand_fill_05.txt AC 241 ms 3736 KiB
03_rand_fill_06.txt AC 216 ms 3704 KiB
03_rand_fill_07.txt AC 158 ms 3880 KiB
03_rand_fill_08.txt AC 119 ms 3904 KiB
03_rand_fill_09.txt AC 285 ms 3736 KiB
03_rand_fill_10.txt AC 307 ms 3728 KiB
04_only_small_01.txt AC 2 ms 3940 KiB
04_only_small_02.txt AC 2 ms 3908 KiB
04_only_small_03.txt AC 1 ms 3880 KiB
04_only_small_04.txt AC 1 ms 3876 KiB
04_only_small_05.txt AC 2 ms 3700 KiB
05_only_small_fill_01.txt AC 351 ms 3704 KiB
05_only_small_fill_02.txt AC 349 ms 3764 KiB
05_only_small_fill_03.txt AC 336 ms 3760 KiB
05_only_small_fill_04.txt AC 338 ms 3952 KiB
05_only_small_fill_05.txt AC 343 ms 3684 KiB
05_only_small_fill_06.txt AC 339 ms 3836 KiB
05_only_small_fill_07.txt AC 349 ms 3796 KiB
05_only_small_fill_08.txt AC 308 ms 3728 KiB
05_only_small_fill_09.txt AC 348 ms 3704 KiB
05_only_small_fill_10.txt AC 342 ms 3728 KiB
06_only_1_01.txt AC 23 ms 3916 KiB
06_only_1_02.txt AC 23 ms 3856 KiB
06_only_1_03.txt AC 23 ms 3900 KiB
06_only_1_04.txt AC 23 ms 3904 KiB
06_only_1_05.txt AC 23 ms 3876 KiB
07_only_2_01.txt AC 3 ms 3816 KiB
07_only_2_02.txt AC 3 ms 3912 KiB
07_only_2_03.txt AC 3 ms 3756 KiB
07_only_2_04.txt AC 3 ms 3648 KiB
07_only_2_05.txt AC 3 ms 3788 KiB
08_only_1_2_01.txt AC 424 ms 3788 KiB
08_only_1_2_02.txt AC 437 ms 3900 KiB
08_only_1_2_03.txt AC 436 ms 3972 KiB
08_only_1_2_04.txt AC 437 ms 3848 KiB
08_only_1_2_05.txt AC 417 ms 3708 KiB
09_N_equal_1_01.txt AC 1 ms 3796 KiB
09_N_equal_1_02.txt AC 1 ms 3864 KiB
09_N_equal_1_03.txt AC 1 ms 3692 KiB
09_N_equal_1_04.txt AC 1 ms 3700 KiB
09_N_equal_1_05.txt AC 1 ms 3696 KiB
10_handmade_01.txt AC 1 ms 3792 KiB
10_handmade_02.txt AC 1 ms 3696 KiB
10_handmade_03.txt AC 438 ms 3880 KiB
10_handmade_04.txt AC 434 ms 3884 KiB
10_handmade_05.txt AC 416 ms 3972 KiB
10_handmade_06.txt AC 414 ms 3708 KiB