結果
問題 | No.2113 Distance Sequence 1.5 |
ユーザー | bayashiko |
提出日時 | 2022-10-04 05:47:39 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,052 bytes |
コンパイル時間 | 5,175 ms |
コンパイル使用メモリ | 269,632 KB |
実行使用メモリ | 58,256 KB |
最終ジャッジ日時 | 2024-06-09 16:11:48 |
合計ジャッジ時間 | 19,268 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 82 ms
18,816 KB |
testcase_02 | AC | 209 ms
18,816 KB |
testcase_03 | AC | 257 ms
57,920 KB |
testcase_04 | AC | 320 ms
18,944 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
ソースコード
#include<bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx2") #pragma GCC optimize("unroll-loops") using namespace std; //#include<boost/multiprecision/cpp_int.hpp> //#include<boost/multiprecision/cpp_dec_float.hpp> //namespace mp=boost::multiprecision; //#define mulint mp::cpp_int //#define mulfloat mp::cpp_dec_float_100 struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init; #define INF (1<<30) #define LINF (lint)(1LL<<56) #define endl "\n" #define rep(i,n) for(lint (i)=0;(i)<(n);(i)++) #define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--) #define flc(x) __builtin_popcountll(x) #define pint pair<int,int> #define pdouble pair<double,double> #define plint pair<lint,lint> #define fi first #define se second #define all(x) x.begin(),x.end() #define vec vector<lint> #define nep(x) next_permutation(all(x)) typedef long long lint; int dx[8]={1,1,0,-1,-1,-1,0,1}; int dy[8]={0,1,1,1,0,-1,-1,-1}; const int MAX_N=4e5+5; template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;} //vector<int> bucket[MAX_N/1000]; //constexpr int MOD=1000000007; constexpr int MOD=998244353; #include<atcoder/all> using namespace atcoder; typedef __int128_t llint; template< int mod > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; template< typename T > struct Combination { vector< T > _fact, _rfact, _inv; Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) { _fact[0] = _rfact[sz] = _inv[0] = 1; for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i; _rfact[sz] /= _fact[sz]; for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1); for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1]; } inline T fact(int k) const { return _fact[k]; } inline T rfact(int k) const { return _rfact[k]; } inline T inv(int k) const { return _inv[k]; } T P(int n, int r) const { if(r < 0 || n < r) return 0; return fact(n) * rfact(n - r); } T C(int p, int q) const { if(q < 0 || p < q) return 0; return fact(p) * rfact(q) * rfact(p - q); } T H(int n, int r) const { if(n < 0 || r < 0) return (0); return r == 0 ? 1 : C(n + r - 1, r); } }; using modint = ModInt< MOD >; template< typename T > T lagrange_polynomial(const vector< T > &y, int64_t t) { int N = y.size() - 1; Combination< T > comb(N); if(t <= N) return y[t]; T ret(0); vector< T > dp(N + 1, 1), pd(N + 1, 1); for(int i = 0; i < N; i++) dp[i + 1] = dp[i] * (t - i); for(int i = N; i > 0; i--) pd[i - 1] = pd[i] * (t - i); for(int i = 0; i <= N; i++) { T tmp = y[i] * dp[i] * pd[i] * comb.rfact(i) * comb.rfact(N - i); if((N - i) & 1) ret -= tmp; else ret += tmp; } return ret; } lint powmod(lint a,lint b,lint mod=MOD){ return b?(powmod((a*a)%mod,b/2,mod)*(b%2?a:1))%mod:1; } int main(void){ lint N,M,K; cin >> N >> M >> K; N*=2; if(K==1){ cout << M%MOD << endl; return 0; } using mint = ModInt<MOD>; vector<mint> f(2000100); mint powN[2001000]; rep(i,2001000) powN[i]=pow_mod(i,N,MOD); for(lint k=2;k<=2000101;k++){ if(k>2) f[k-2]+=f[k-3]; mint add1=(M+1-k); mint add2=powN[k]; add2-=powN[k-1]*2; add2+=powN[k-2]; f[k-2]+=add1*add2; } if(K<=1000000) cout << f[K-2]+M << endl; else cout << lagrange_polynomial(f,K-2)+M << endl; }