結果
問題 |
No.2846 Birthday Cake
|
ユーザー |
![]() |
提出日時 | 2024-08-23 21:54:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,179 bytes |
コンパイル時間 | 3,599 ms |
コンパイル使用メモリ | 261,240 KB |
最終ジャッジ日時 | 2025-02-23 23:43:35 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 WA * 4 |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 long long N,K; long long En = 1; vector<long long> la,lb; long long L; map<long long,long long> mp[25]; map<long long,long long> mp2[25]; void dfs(int ci,int ck,long long cx,long long cv){ if(cx > L)return; if(ck>=la.size()){ long long t = 1; rep(i,K){ t *= i+1; } mp[ci][cx] += t/cv; return; } long long t = 1LL; rep(i,K-ci+1){ if(i==0){ dfs(ci,ck+1,cx,cv); } else{ long long ncx = cx; ncx += (L / la[ck])*i; dfs(ci+i,ck+1,ncx,cv*t); } t *= i+1; } } int main(){ cin>>K>>N; rep(i,K)En *= i+1; L = 1; rep(i,N)L = lcm(L,i+1); rep(i,N){ if(i%2)la.push_back(i+1); else lb.push_back(i+1); } dfs(0,0,0,1); swap(la,lb); swap(mp,mp2); dfs(0,0,0,1); __int128 ans =0; rep(i,K+1){ for(auto x:mp[i]){ long long A = x.first,B = x.second; __int128 X = B; X *= mp2[K-i][L-A]; ans += X; } } rep(i,K)ans /=i+1; long long aa = ans; cout<<aa<<endl; return 0; }