結果

問題 No.1204 お菓子配り-FINAL
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2020-08-03 21:19:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 4,339 bytes
コンパイル時間 4,656 ms
コンパイル使用メモリ 349,748 KB
実行使用メモリ 52,352 KB
最終ジャッジ日時 2024-04-26 10:57:05
合計ジャッジ時間 99,739 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
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 RE -
testcase_21 WA -
testcase_22 WA -
testcase_23 RE -
testcase_24 RE -
testcase_25 WA -
testcase_26 RE -
testcase_27 RE -
testcase_28 WA -
testcase_29 WA -
testcase_30 RE -
testcase_31 RE -
testcase_32 WA -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 WA -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 193 ms
51,968 KB
testcase_61 AC 186 ms
51,968 KB
testcase_62 AC 192 ms
51,968 KB
testcase_63 AC 187 ms
51,968 KB
testcase_64 AC 205 ms
51,968 KB
testcase_65 AC 194 ms
51,968 KB
testcase_66 WA -
testcase_67 AC 193 ms
52,076 KB
testcase_68 AC 194 ms
52,044 KB
testcase_69 WA -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 RE -
testcase_78 WA -
testcase_79 WA -
testcase_80 RE -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 RE -
testcase_85 RE -
testcase_86 AC 258 ms
51,840 KB
testcase_87 RE -
testcase_88 WA -
testcase_89 WA -
testcase_90 RE -
testcase_91 RE -
testcase_92 RE -
testcase_93 RE -
testcase_94 RE -
testcase_95 RE -
testcase_96 RE -
testcase_97 RE -
testcase_98 RE -
testcase_99 RE -
testcase_100 RE -
testcase_101 RE -
testcase_102 RE -
testcase_103 RE -
testcase_104 RE -
testcase_105 RE -
testcase_106 RE -
testcase_107 RE -
testcase_108 RE -
testcase_109 RE -
testcase_110 RE -
testcase_111 WA -
testcase_112 RE -
testcase_113 WA -
testcase_114 RE -
testcase_115 RE -
testcase_116 RE -
testcase_117 RE -
testcase_118 WA -
testcase_119 RE -
testcase_120 RE -
testcase_121 WA -
testcase_122 RE -
testcase_123 WA -
testcase_124 RE -
testcase_125 RE -
testcase_126 RE -
testcase_127 RE -
testcase_128 RE -
testcase_129 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <random>
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
using namespace mp;
using ull = __int128;
using ll = long long;
using cll = cpp_int;
#define sort(a) sort(a.begin(), a.end())
#define rep(i,a) for(int i=0;i<a;i++)
//const ll mod = 1000000007;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const ll mod = 998244353;
const ll MAX = 2000000;

long long fac[MAX],finv[MAX],inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

class mint {
    long long x;
public:
    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 {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 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 {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
  friend istream& operator>>(istream& lhs,mint& rhs) noexcept {
        lhs >> rhs.x;
        return lhs;
    }
};


int kkk(vector<int> n){
  ll b=n.size();
  if(b==1){
    return n.at(0);
  }
  else{
   ll  ans=0;
   vector<vector<int>> data(b-1, vector<int>(b-1));
    for(int i=0;i<b-1;i++){
      for(int j=0;j<b-1;j++){
        if(i==j){
          data.at(i).at(j)=n.at(j)+n.at(j+1);
        }
        else if(i>j){
          data.at(i).at(j)=n.at(j);
      }
        else{
          data.at(i).at(j)=n.at(j+1);
    }
  }
    }
    vector<int> k(b-1);
    for(int i=0;i<b-1;i++){
      k.at(i)=n.at(i);
    }
    ans=(ans+(n.at(b-1)%MOD)*(kkk(k)%MOD)%MOD);
      for(int i=0;i<b-1;i++){
        ans=(ans+((n.at(i)%MOD)*(kkk(data.at(i))%MOD))%MOD)%MOD;
      }
      return ans;
}
}

int modPow(long long a, long long n, long long p) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}
ll T(ll a,ll b){
  if(b!=0){
 return (a-b+1)*modPow(a+1,b-1,MOD)%MOD;
  }
  else{
    return 1;
  }
}
int main() {
  COMinit();
  ll kai[100001];
kai[0]=1;
  for(int i=1;i<=100000;i++){
    kai[i]=kai[i-1]*i%MOD;
  }
  ll gya[100001];
    for(int i=0;i<=100000;i++){
      gya[i]=modPow(kai[i],MOD-2,MOD);
    }
 ll a,b;
  cin>>a>>b;
  string c;
  cin>>c;
  ll d=0;
  ll mou=0;
  ll mada=0;
  for(int i=0;i<b;i++){
    if(c.at(i)=='-'){
      mou++;
    }
    else{
      mada++;
    }
  }
for(int i=0;i<b-1;i++){
  if(c.at(i)=='o'&&c.at(i+1)=='-'){
    d++;
  }
}
  vector<ll> before(d);
  ll e=0;
  for(int i=1;i<b;i++){
    if(c.at(i)=='-'){
      before.at(e)++;
    }
    if(c.at(i)=='o'&&c.at(i-1)=='-'){
      e++;
    }
  }
ll ans=1;
  for(int i=0;i<d;i++){
    ans=ans*T(before.at(i),before.at(i))%MOD;
  }
  ans=ans*kai[mou]%MOD;
  for(int i=0;i<d;i++){
    ans=ans*gya[before.at(i)]%MOD;
  }
  ll answer=0;
  for(int i=0;i<=a-b;i++){
   answer+=(T(a-b,i)*ans%MOD)*COM(mou+i,i)%MOD*modPow(a,(a-b-i)+mada,MOD)%MOD;
  }
  cout<<(answer%MOD)*(a-b+1)%MOD<<endl;
}
0