結果
問題 | No.2810 Have Another Go (Hard) |
ユーザー | 👑 potato167 |
提出日時 | 2024-07-12 22:25:44 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,345 ms / 3,000 ms |
コード長 | 7,467 bytes |
コンパイル時間 | 3,981 ms |
コンパイル使用メモリ | 249,952 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-12 22:27:13 |
合計ジャッジ時間 | 86,589 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2,269 ms
6,940 KB |
testcase_02 | AC | 2,194 ms
6,944 KB |
testcase_03 | AC | 2,247 ms
6,940 KB |
testcase_04 | AC | 2,277 ms
6,940 KB |
testcase_05 | AC | 2,289 ms
6,940 KB |
testcase_06 | AC | 2,279 ms
6,940 KB |
testcase_07 | AC | 2,259 ms
6,944 KB |
testcase_08 | AC | 2,282 ms
6,944 KB |
testcase_09 | AC | 2,276 ms
6,944 KB |
testcase_10 | AC | 2,291 ms
6,940 KB |
testcase_11 | AC | 14 ms
6,944 KB |
testcase_12 | AC | 14 ms
6,944 KB |
testcase_13 | AC | 6 ms
6,940 KB |
testcase_14 | AC | 17 ms
6,940 KB |
testcase_15 | AC | 12 ms
6,944 KB |
testcase_16 | AC | 491 ms
6,944 KB |
testcase_17 | AC | 1,964 ms
6,940 KB |
testcase_18 | AC | 1,234 ms
6,940 KB |
testcase_19 | AC | 1,878 ms
6,940 KB |
testcase_20 | AC | 283 ms
6,944 KB |
testcase_21 | AC | 684 ms
6,944 KB |
testcase_22 | AC | 1,253 ms
6,940 KB |
testcase_23 | AC | 840 ms
6,944 KB |
testcase_24 | AC | 1,449 ms
6,940 KB |
testcase_25 | AC | 2,182 ms
6,944 KB |
testcase_26 | AC | 2,263 ms
6,940 KB |
testcase_27 | AC | 2,262 ms
6,940 KB |
testcase_28 | AC | 2,303 ms
6,940 KB |
testcase_29 | AC | 2,239 ms
6,940 KB |
testcase_30 | AC | 2,264 ms
6,944 KB |
testcase_31 | AC | 2,272 ms
6,940 KB |
testcase_32 | AC | 2,282 ms
6,940 KB |
testcase_33 | AC | 2,263 ms
6,944 KB |
testcase_34 | AC | 2,280 ms
6,940 KB |
testcase_35 | AC | 2,265 ms
6,940 KB |
testcase_36 | AC | 2,214 ms
6,944 KB |
testcase_37 | AC | 2,238 ms
6,940 KB |
testcase_38 | AC | 2,298 ms
6,940 KB |
testcase_39 | AC | 2,278 ms
6,940 KB |
testcase_40 | AC | 2,246 ms
6,944 KB |
testcase_41 | AC | 2,222 ms
6,940 KB |
testcase_42 | AC | 2,345 ms
6,940 KB |
testcase_43 | AC | 2,257 ms
6,940 KB |
testcase_44 | AC | 2,270 ms
6,940 KB |
testcase_45 | AC | 2,333 ms
6,940 KB |
testcase_46 | AC | 3 ms
6,944 KB |
testcase_47 | AC | 5 ms
6,944 KB |
testcase_48 | AC | 8 ms
6,944 KB |
testcase_49 | AC | 5 ms
6,944 KB |
testcase_50 | AC | 6 ms
6,940 KB |
testcase_51 | AC | 35 ms
6,940 KB |
testcase_52 | AC | 15 ms
6,940 KB |
testcase_53 | AC | 34 ms
6,940 KB |
testcase_54 | AC | 32 ms
6,944 KB |
testcase_55 | AC | 21 ms
6,944 KB |
testcase_56 | AC | 45 ms
6,944 KB |
testcase_57 | AC | 49 ms
6,944 KB |
testcase_58 | AC | 39 ms
6,944 KB |
testcase_59 | AC | 64 ms
6,940 KB |
testcase_60 | AC | 44 ms
6,940 KB |
ソースコード
#line 1 "cup.cpp" #include <bits/stdc++.h> using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; const ll ILL=2167167167167167167; const int INF=2100000000; const int mod=998244353; #define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define all(p) p.begin(),p.end() template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>; template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template<class T> bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;} template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;} template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());} template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} bool yneos(bool a,bool upp=0){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;} template<class T> void vec_out(vector<T> &p,int ty=0){ if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";} else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}} template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template<class T> T vec_sum(vector<T> &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;} int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;} template<class T> bool inside(T l,T x,T r){return l<=x&&x<r;} #include <atcoder/modint> using mint = atcoder::modint998244353; #line 3 "/Users/Shared/po167_library/fps/FPS_Boston_Mori.hpp" #include <atcoder/convolution> #line 4 "/Users/Shared/po167_library/fps/FPS_extend.hpp" namespace po167{ // in : DFT(v) (len(v) = z) // out : DFT(v) (len(v) = 2 * z) template<class T> void FPS_extend(std::vector<T> &v){ int z = v.size(); T e = (T(atcoder::internal::primitive_root_constexpr(T::mod()))).pow(T::mod() / (2 * z)); auto cp = v; atcoder::internal::butterfly_inv(cp); T tmp = (T)(1) / (T)(z); for (int i = 0; i < z; i++){ cp[i] *= tmp; tmp *= e; } atcoder::internal::butterfly(cp); for (int i = 0; i < z; i++) v.push_back(cp[i]); }; } #line 3 "/Users/Shared/po167_library/fps/FPS_pick_even_odd.hpp" namespace po167{ // s.t |v| = 2 ^ s (no assert) template<class T> void FPS_pick_even_odd(std::vector<T> &v, int odd){ int z = v.size() / 2; T half = (T)(1) / (T)(2); if (odd == 0){ for (int i = 0; i < z; i++){ v[i] = (v[i * 2] + v[i * 2 + 1]) * half; } v.resize(z); } else { T e = (T(atcoder::internal::primitive_root_constexpr(T::mod()))).pow(T::mod() / (2 * z)); T ie = T(1) / e; std::vector<T> es = {half}; while ((int)es.size() != z){ std::vector<T> n_es((int)es.size() * 2); for (int i = 0; i < (int)es.size(); i++){ n_es[i * 2] = (es[i]); n_es[i * 2 + 1] = (es[i] * ie); } ie *= ie; std::swap(n_es, es); } for (int i = 0; i < z; i ++){ v[i] = (v[i * 2] - v[i * 2 + 1]) * es[i]; } v.resize(z); } } } #line 7 "/Users/Shared/po167_library/fps/FPS_Boston_Mori.hpp" namespace po167{ // return [x^k] P(x) / Q(x) template<class T> T Boston_Mori(long long k, std::vector<T> P, std::vector<T> Q){ assert(!Q.empty() && Q[0] != 0); int z = 1; while (z < (int)std::max(P.size(), Q.size())) z *= 2; P.resize(z * 2, 0); Q.resize(z * 2, 0); atcoder::internal::butterfly(P); atcoder::internal::butterfly(Q); // fast while (k){ // Q(-x) std::vector<T> Q_n(z * 2); for (int i = 0; i < z; i++){ Q_n[i * 2] = Q[i * 2 + 1]; Q_n[i * 2 + 1] = Q[i * 2]; } for (int i = 0; i < z * 2; i++){ P[i] *= Q_n[i]; Q[i] *= Q_n[i]; } FPS_pick_even_odd(P, k & 1); FPS_pick_even_odd(Q, 0); k /= 2; if (k == 0) break; FPS_extend(P); FPS_extend(Q); } T SP = 0, SQ = 0; for (int i = 0; i < z; i++) SP += P[i], SQ += Q[i]; return SP / SQ; // simple /* while (k){ auto n_Q = Q; for (int i = 0; i < int(Q.size()); i++){ if (i & 1) n_Q[i] *= -1; } auto n_P = atcoder::convolution(P, n_Q); n_Q = atcoder::convolution(Q, n_Q); for (int i = 0; i < int(Q.size()); i++){ Q[i] = n_Q[i * 2]; } P.clear(); for (int i = (k & 1); i < int(n_P.size()); i += 2){ P.push_back(n_P[i]); } k >>= 1; } return P[0] / Q[0]; */ } template<class T> // 0 = a[i] * c[0] + a[i - 1] * c[1] + a[i - 2] * c[2] + ... + a[i - d] * c[d] // a.size() + 1 == c.size() // c[0] = - 1 ? // return a[k] T Kth_Linear(long long k, std::vector<T> a, std::vector<T> c){ int d = a.size(); assert(d + 1 == int(c.size())); std::vector<T> P = atcoder::convolution(a, c); P.resize(d); return Boston_Mori(k, P, c); } }; #line 32 "cup.cpp" using F = array<array<mint, 5>, 5>; void solve(); // CYAN / FREDERIC int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; rep(i, 0, t) solve(); } void solve(){ ll N, M, K; cin >> N >> M >> K; vector<mint> P = {1}; vector<mint> Q = {1, -1, -1, -1, -1, -1, -1}; auto f = [&](ll a) -> mint { if (a < 0) return 0; return po167::Boston_Mori(a, P, Q); }; F a; rep(i, 0, 5) rep(j, 0, 5){ a[i][j] = f(N - i - j - 2); } F b; rep(i, 0, 5) rep(j, 0, 5){ if (i + j + 2 <= 6){ b[i][j] = 1; } else{ b[i][j] = 0; } } auto mul = [&](F l, F r) -> F { F c; rep(i, 0, 5) rep(j, 0, 5) c[i][j] = 0; rep(i, 0, 5) rep(j, 0, 5) rep(k, 0, 5){ c[i][k] += l[i][j] * r[j][k]; } return c; }; auto pm = [&](F v, ll t) -> F { F c; rep(i, 0, 5) rep(j, 0, 5){ c[i][j] = 0; if (i == j) c[i][j] = 1; } while (t){ if (t & 1){ c = mul(c, v); } t /= 2; v = mul(v, v); } return c; }; F base = mul(b, pm(mul(a, b), M - 1)); mint al = 0; rep(i, 0, 6) al += f(N * M - 1 - i) * (6 - i); while (K--){ ll C; cin >> C; vector<mint> p(5); rep(i, 0, 5) p[i] = f(C - i - 1); vector<mint> q(5); rep(i, 0, 5) rep(j, 0, 5) q[j] += p[i] * base[i][j]; mint ans = al; vector<mint> r(10); if (N - C <= 10) rep(i, 0, 10) r[i] = f(N - 1 - C - 1 - i); else{ rep(i, 4, 10) r[i] = f(N - 1 - C - 1 - i); for (int j = 3; j >= 0; j--){ rep(k, 0, 6) r[j] += r[j + 1 + k]; } } rep(i, 0, 5) rep(j, 0, 6) rep(k, 0, 6){ if (j + 1 + k > 6) continue; ans -= q[i] * r[i + j]; } rep(j, 0, 5) if (C + j + 1 >= N) ans -= q[j]; cout << ans.val() << "\n"; } }