結果

問題 No.2817 Competition
ユーザー HIcoderHIcoder
提出日時 2024-08-28 23:19:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 6,339 bytes
コンパイル時間 1,727 ms
コンパイル使用メモリ 131,992 KB
実行使用メモリ 20,180 KB
最終ジャッジ日時 2024-08-28 23:20:08
合計ジャッジ時間 26,264 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 AC 286 ms
6,940 KB
testcase_09 AC 519 ms
7,516 KB
testcase_10 AC 823 ms
10,624 KB
testcase_11 AC 1,473 ms
13,528 KB
testcase_12 AC 5 ms
6,940 KB
testcase_13 AC 598 ms
7,588 KB
testcase_14 AC 943 ms
10,752 KB
testcase_15 AC 505 ms
7,296 KB
testcase_16 AC 1,004 ms
10,752 KB
testcase_17 AC 680 ms
8,064 KB
testcase_18 TLE -
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int inf=1<<30;
const ll INF=1LL<<62;
using P = pair<int,int>;
typedef pair<int,P> PP; 
const ll MOD=998244353;
const int MAXN=100000;


class NTT{

    private:
        long long int mod;
        const long long root=3;
        long long int add(const long long int x, const long long int y)
        {
            return (x + y <  mod ? x + y : x + y -  mod);
        }
        
        long long int sub(const long long int x, const long long int y)
        {
            return (x >= y) ? (x - y) : ( mod- y + x);
        }
        
        long long int mul(const long long int x, const long long int y)
        {
            return x * y %  mod;
        }
        
        long long int mod_pow(long long int x, long long int n)
        {
            long long int res = 1;
            while(n > 0){
                if(n & 1){ res = mul(res, x); }
                x = mul(x, x);
                n >>= 1;
            }
            return res;
        }

        long long int inverse(const long long int x)
        {
            return mod_pow(x,  mod- 2);
        }


        void ntt(std::vector<long long int>& a, const bool rev = false){

                unsigned int i, j, k, l, p, q, r, s;
                const unsigned int size = a.size();
                if(size == 1) return;
                std::vector<long long int> b(size);
                r = rev ? ( mod- 1 - ( mod- 1) / size) : ( mod- 1) / size;
                s = mod_pow(root, r);
                std::vector<long long int> kp(size / 2 + 1, 1);
                for(i = 0; i < size / 2; ++i) kp[i + 1] = mul(kp[i], s);
                for(i = 1, l = size / 2; i < size; i <<= 1, l >>= 1){
                    for(j = 0, r = 0; j < l; ++j, r += i){
                        for(k = 0, s = kp[i * j]; k < i; ++k){
                            p = a[k + r], q = a[k + r + size / 2];
                            b[k + 2 * r] = add(p, q);
                            b[k + 2 * r + i] = mul(sub(p, q), s);
                        }
                    }
                    swap(a, b);
                }
                if(rev){
                    s = inverse(size);
                    for(i = 0; i < size; i++){ a[i] = mul(a[i], s); }
                }
            }

    public:
        NTT(long long int mod_=998244353): mod(mod_){}; 

        //
        //vector<ll> c = ntt(a,b)みたいにして使う
        std::vector<long long int> operator()(const std::vector<long long int>& a, const std::vector<long long int>& b){
            const int size = (int)a.size() + (int)b.size() - 1;
            ll t = 1;
            while(t < size){ t <<= 1; }

            std::vector<long long int> A(t, 0), B(t, 0);
            
            for(int i = 0; i < (int)a.size(); i++){ A[i] = a[i]; }
            for(int i = 0; i < (int)b.size(); i++){ B[i] = b[i]; }
            
            ntt(A), ntt(B);
            for (int i = 0; i < t; i++){ A[i] = mul(A[i], B[i]); }
            ntt(A, true);
            A.resize(size);
            
            return A;
        }


        //vector<ll> c;
        //  res[j]= ∑(a[i+j]*b[i])(i=[0,b.size()))  j=[0,a.size())

        std::vector<long long int>  filter(const std::vector<long long int>& a,const std::vector<long long int>& b){
            std::vector<long long int> revb=b;
            int lena=a.size(),lenb=b.size();
            
            assert(lena>=lenb);
            

            std::reverse(revb.begin(),revb.end());
            
            std::vector<long long int> filt=this->operator()(a,revb);

            std::vector<long long int> res;
            for(int i=lenb-1;i<lena;i++){
                //[lenb-1,lena)
                res.push_back(filt[i]);
            }
            return res;
            

        }
};




const int mod = 998244353;
struct mint {
  long long x; // typedef long long long long;
  mint(long long x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}//後ろのconstはメンバxを変更しないことを示す
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  bool operator==(const mint a) const {return a.x==x;}
  mint pow(unsigned long long int t) const {
    assert(t>=0);
    if (!t) return 1;
    //aがtで割り切れない場合には t%=(mod-1)をして良い
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x;}
std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x;}



struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};




int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    queue<vector<ll>> que;
    for(int i=0;i<N;i++){
        cin>>A[i];
        A[i]%=MOD;
        que.push({1,A[i]});
    }
    NTT ntt;

    while(que.size()>1){
        vector<ll> a=que.front();que.pop();
        vector<ll> b=que.front();que.pop();
        NTT ntt;
        vector<ll> c=ntt(a,b);
        que.push(c);
    }

    vector<ll> data = que.front();

    mint ans=0;
    for(int i=1;i<=N;i++){
        ans+=(mint)data[i]*mint(i).pow(N-i);
    }
    cout<<ans<<endl;
}
0