結果

問題 No.1204 お菓子配り-FINAL
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2020-08-01 16:42:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,283 bytes
コンパイル時間 7,915 ms
コンパイル使用メモリ 374,180 KB
実行使用メモリ 52,120 KB
最終ジャッジ日時 2023-08-08 18:29:34
合計ジャッジ時間 81,375 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 166 ms
51,884 KB
testcase_01 AC 205 ms
51,776 KB
testcase_02 AC 175 ms
51,748 KB
testcase_03 AC 156 ms
51,760 KB
testcase_04 AC 236 ms
51,708 KB
testcase_05 AC 196 ms
51,736 KB
testcase_06 AC 187 ms
51,812 KB
testcase_07 AC 210 ms
51,720 KB
testcase_08 AC 169 ms
51,888 KB
testcase_09 AC 167 ms
52,016 KB
testcase_10 AC 213 ms
51,736 KB
testcase_11 AC 201 ms
51,712 KB
testcase_12 AC 204 ms
51,812 KB
testcase_13 AC 208 ms
51,804 KB
testcase_14 AC 189 ms
51,812 KB
testcase_15 AC 148 ms
51,812 KB
testcase_16 AC 161 ms
51,736 KB
testcase_17 AC 143 ms
51,816 KB
testcase_18 AC 161 ms
51,760 KB
testcase_19 AC 174 ms
51,832 KB
testcase_20 RE -
testcase_21 WA -
testcase_22 WA -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 156 ms
51,884 KB
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 AC 241 ms
51,744 KB
testcase_41 AC 152 ms
51,756 KB
testcase_42 AC 148 ms
51,864 KB
testcase_43 AC 157 ms
51,736 KB
testcase_44 AC 149 ms
51,744 KB
testcase_45 AC 156 ms
51,752 KB
testcase_46 AC 150 ms
51,756 KB
testcase_47 AC 151 ms
51,764 KB
testcase_48 AC 236 ms
51,776 KB
testcase_49 AC 199 ms
51,740 KB
testcase_50 AC 207 ms
51,840 KB
testcase_51 AC 158 ms
51,808 KB
testcase_52 AC 156 ms
51,804 KB
testcase_53 AC 191 ms
51,872 KB
testcase_54 AC 227 ms
51,808 KB
testcase_55 AC 154 ms
51,740 KB
testcase_56 AC 206 ms
51,740 KB
testcase_57 AC 147 ms
51,736 KB
testcase_58 AC 171 ms
51,748 KB
testcase_59 AC 188 ms
51,708 KB
testcase_60 AC 141 ms
51,840 KB
testcase_61 AC 141 ms
51,780 KB
testcase_62 AC 145 ms
51,736 KB
testcase_63 AC 148 ms
51,864 KB
testcase_64 AC 145 ms
51,704 KB
testcase_65 AC 146 ms
51,972 KB
testcase_66 AC 145 ms
51,972 KB
testcase_67 AC 145 ms
51,760 KB
testcase_68 AC 139 ms
51,780 KB
testcase_69 AC 145 ms
51,752 KB
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 AC 154 ms
51,700 KB
testcase_74 WA -
testcase_75 WA -
testcase_76 AC 146 ms
51,760 KB
testcase_77 RE -
testcase_78 WA -
testcase_79 WA -
testcase_80 RE -
testcase_81 AC 139 ms
51,780 KB
testcase_82 WA -
testcase_83 AC 145 ms
51,988 KB
testcase_84 RE -
testcase_85 RE -
testcase_86 AC 148 ms
51,736 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 AC 252 ms
51,692 KB
testcase_119 RE -
testcase_120 RE -
testcase_121 WA -
testcase_122 RE -
testcase_123 AC 246 ms
51,736 KB
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 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