結果

問題 No.2876 Infection
ユーザー HIcoderHIcoder
提出日時 2024-09-07 10:27:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 298 ms / 2,000 ms
コード長 2,970 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 129,300 KB
実行使用メモリ 234,296 KB
最終ジャッジ日時 2024-09-07 10:28:02
合計ジャッジ時間 9,539 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 179 ms
234,224 KB
testcase_01 AC 188 ms
234,136 KB
testcase_02 AC 181 ms
234,188 KB
testcase_03 AC 181 ms
234,200 KB
testcase_04 AC 180 ms
234,228 KB
testcase_05 AC 273 ms
234,168 KB
testcase_06 AC 272 ms
234,136 KB
testcase_07 AC 298 ms
234,224 KB
testcase_08 AC 270 ms
234,296 KB
testcase_09 AC 270 ms
234,200 KB
testcase_10 AC 191 ms
234,232 KB
testcase_11 AC 194 ms
234,156 KB
testcase_12 AC 192 ms
234,156 KB
testcase_13 AC 201 ms
234,200 KB
testcase_14 AC 254 ms
234,164 KB
testcase_15 AC 226 ms
234,188 KB
testcase_16 AC 183 ms
234,184 KB
testcase_17 AC 187 ms
234,232 KB
testcase_18 AC 196 ms
234,236 KB
testcase_19 AC 183 ms
234,248 KB
testcase_20 AC 210 ms
234,156 KB
testcase_21 AC 183 ms
234,220 KB
testcase_22 AC 218 ms
234,136 KB
testcase_23 AC 229 ms
234,268 KB
testcase_24 AC 195 ms
234,228 KB
testcase_25 AC 213 ms
234,132 KB
testcase_26 AC 184 ms
234,192 KB
testcase_27 AC 197 ms
234,184 KB
testcase_28 AC 191 ms
234,136 KB
testcase_29 AC 244 ms
234,132 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;
typedef long long ll;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,ll> P;
typedef pair<int,P> PP; 
const ll MOD=998244353;
const int dy[]={0,1,0,-1};
const int dx[]={1,0,-1,0};


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];
  }
};

combination comb(2*1000000+10);

const int MAXN=5000+10;

vector<mint> c(MAXN+1);
vector<vector<mint>> s(MAXN+1,vector<mint>(MAXN+1,0));
vector<bool> c_used(MAXN+1,false);
vector<vector<bool>> s_used(MAXN+1,vector<bool>(MAXN+1,false));

mint q;
mint p;

mint C(int n);
mint S(int n,int k);

mint C(int n){
    if(c_used[n])return c[n];
    c_used[n]=true;
    mint res=1;
    for(int i=1;i<=n-1;i++){
        res-=S(n,i);
    }
    return c[n]=res;
};

mint S(int n,int k){
    if(s_used[n][k])return s[n][k];
    s_used[n][k]=true;
    mint res=comb(n-1,k-1)*q.pow((n-k)*k)*C(k);
    return s[n][k]=res;
};


int main(){

    int N,x;
    cin>>N>>x;

    
    p=(mint)x/100;
    q=(mint)1-p;

    mint ans=0;
    for(int k=1;k<=N;k++){
        ans+=(mint)k*S(N,k);
    }
    cout<<ans<<endl;

}
0