Submission #33934208


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/modint>
using mint = atcoder::modint998244353;
using namespace std;

typedef long long ll;
#define rep(i,a,n) for (ll i=a;i<(ll)n;i++)
#define per(i,a,n) for (ll i=n;i-->(ll)a;)

ll read(){ll r;scanf("%lld",&r);return r;} // read
ll gcd(int a,int b){ return b == 0? a: gcd(b,a%b);}

map<int,mint> dp[60][60]; // dp[选最小i个][最大的环为j] = {lcm, count}
mint fac[100] = {1};
mint ifac[100];
mint binom(int n,int m) { return fac[n] * ifac[m] * ifac[n-m];}

int main(){
  rep(i,1,51) fac[i] = fac[i-1] * i;
  ifac[50] = fac[50].inv();
  per(i,0,50) ifac[i] = ifac[i+1] * (i+1);

  int n = read();
  int k = read();
  dp[0][0][1] = 1;
  rep(i,1,n+1) rep(j,1,i+1){
    mint invj = mint(j).inv();
    rep(t,1,n+1){
      int oldi = i - j*t; // [i - j*t][<j]
      if(oldi < 0) break;
      rep(k,0,j) for(auto [lcm,cnt]: dp[oldi][k]){
        int newlcm = lcm * j / gcd(lcm,j);
        dp[i][j][newlcm] += cnt * binom(n-oldi,j*t) * fac[j*t] * ifac[t] * invj.pow(t);
      }
    }
  }
  mint ans = 0;
  rep(j,1,n+1) for(auto [lcm,cnt]:dp[n][j]) ans += cnt * mint(lcm).pow(k);
  printf("%d\n",ans.val());
  return 0;
}

Submission Info

Submission Time
Task F - Score of Permutations
User cromarmot
Language C++ (GCC 9.2.1)
Score 500
Code Size 1165 Byte
Status AC
Exec Time 21 ms
Memory 4916 KiB

Compile Error

./Main.cpp: In function ‘ll read()’:
./Main.cpp:10:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   10 | ll read(){ll r;scanf("%lld",&r);return r;} // read
      |                ~~~~~^~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 41
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 01_small_09.txt, 02_n_max_00.txt, 02_n_max_01.txt, 02_n_max_02.txt, 03_random_00.txt, 03_random_01.txt, 03_random_02.txt, 03_random_03.txt, 03_random_04.txt, 03_random_05.txt, 03_random_06.txt, 03_random_07.txt, 03_random_08.txt, 03_random_09.txt, 03_random_10.txt, 03_random_11.txt, 03_random_12.txt, 03_random_13.txt, 03_random_14.txt, 04_k_eq_1_00.txt, 04_k_eq_1_01.txt, 04_k_eq_1_02.txt, 04_k_eq_1_03.txt, 04_k_eq_1_04.txt, 04_k_eq_1_05.txt, 04_k_eq_1_06.txt, 04_k_eq_1_07.txt, 04_k_eq_1_08.txt, 04_k_eq_1_09.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 6 ms 3776 KiB
00_sample_01.txt AC 2 ms 3888 KiB
00_sample_02.txt AC 19 ms 4740 KiB
01_small_00.txt AC 2 ms 3864 KiB
01_small_01.txt AC 2 ms 3976 KiB
01_small_02.txt AC 2 ms 3760 KiB
01_small_03.txt AC 3 ms 3784 KiB
01_small_04.txt AC 3 ms 3860 KiB
01_small_05.txt AC 2 ms 3784 KiB
01_small_06.txt AC 3 ms 3780 KiB
01_small_07.txt AC 3 ms 3920 KiB
01_small_08.txt AC 3 ms 3816 KiB
01_small_09.txt AC 2 ms 3760 KiB
02_n_max_00.txt AC 15 ms 4768 KiB
02_n_max_01.txt AC 14 ms 4916 KiB
02_n_max_02.txt AC 14 ms 4744 KiB
03_random_00.txt AC 4 ms 3812 KiB
03_random_01.txt AC 3 ms 3900 KiB
03_random_02.txt AC 2 ms 3864 KiB
03_random_03.txt AC 21 ms 4800 KiB
03_random_04.txt AC 10 ms 4284 KiB
03_random_05.txt AC 3 ms 4024 KiB
03_random_06.txt AC 2 ms 3916 KiB
03_random_07.txt AC 8 ms 4244 KiB
03_random_08.txt AC 4 ms 4048 KiB
03_random_09.txt AC 7 ms 4316 KiB
03_random_10.txt AC 4 ms 4000 KiB
03_random_11.txt AC 7 ms 4052 KiB
03_random_12.txt AC 2 ms 3900 KiB
03_random_13.txt AC 10 ms 4280 KiB
03_random_14.txt AC 11 ms 4272 KiB
04_k_eq_1_00.txt AC 16 ms 4844 KiB
04_k_eq_1_01.txt AC 2 ms 3980 KiB
04_k_eq_1_02.txt AC 2 ms 3868 KiB
04_k_eq_1_03.txt AC 2 ms 3904 KiB
04_k_eq_1_04.txt AC 2 ms 3936 KiB
04_k_eq_1_05.txt AC 2 ms 3780 KiB
04_k_eq_1_06.txt AC 9 ms 4396 KiB
04_k_eq_1_07.txt AC 14 ms 4892 KiB
04_k_eq_1_08.txt AC 2 ms 3888 KiB
04_k_eq_1_09.txt AC 2 ms 3940 KiB