結果

問題 No.1504 ヌメロニム
ユーザー そすうぽよそすうぽよ
提出日時 2020-12-12 07:30:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,220 bytes
コンパイル時間 1,458 ms
コンパイル使用メモリ 97,692 KB
実行使用メモリ 19,804 KB
最終ジャッジ日時 2023-10-20 10:36:48
合計ジャッジ時間 5,922 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
17,256 KB
testcase_01 AC 13 ms
12,908 KB
testcase_02 AC 13 ms
12,908 KB
testcase_03 AC 15 ms
12,908 KB
testcase_04 AC 13 ms
12,908 KB
testcase_05 AC 13 ms
12,908 KB
testcase_06 AC 13 ms
12,908 KB
testcase_07 AC 13 ms
12,908 KB
testcase_08 AC 13 ms
12,908 KB
testcase_09 AC 14 ms
12,908 KB
testcase_10 AC 13 ms
12,908 KB
testcase_11 AC 14 ms
12,908 KB
testcase_12 AC 14 ms
12,908 KB
testcase_13 AC 13 ms
12,908 KB
testcase_14 AC 14 ms
12,908 KB
testcase_15 AC 13 ms
12,908 KB
testcase_16 AC 14 ms
12,908 KB
testcase_17 AC 14 ms
12,908 KB
testcase_18 AC 14 ms
12,908 KB
testcase_19 AC 13 ms
12,908 KB
testcase_20 AC 85 ms
12,908 KB
testcase_21 AC 50 ms
13,036 KB
testcase_22 AC 80 ms
12,908 KB
testcase_23 AC 17 ms
12,908 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// bit並列+NTTで畳み込む ver
#include <cmath>
#include <cstdint>
#include <bitset>
#include <complex>
#include <iostream>
#include <vector>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;
using vecll = vector<ll>;

const double pi = acos(-1.0);

constexpr ll MOD = 998244353;
constexpr ll MAX_F = 600000;

struct Mod {
  int n;
  Mod () : n(0) {;}
  Mod (int m) : n(m) {
    if (n >= MOD) n %= MOD;
    else if (n < 0) n = (n % MOD + MOD) % MOD;
  }
  operator int() { return n; }
};

bool operator==(Mod a, Mod b) { return a.n == b.n; }
Mod operator+=(Mod &a, Mod b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
Mod operator-=(Mod &a, Mod b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
Mod operator*=(Mod &a, Mod b) { a.n = ((long long)a.n * b.n) % MOD; return a; }
Mod operator+(Mod a, Mod b) { return a += b; }
Mod operator-(Mod a, Mod b) { return a -= b; }
Mod operator*(Mod a, Mod b) { return a *= b; }
Mod operator^(Mod a, int n) {
  if (n == 0) return Mod(1);
  Mod res = (a * a) ^ (n / 2);
  if (n % 2) res = res * a;
  return res;
}

ll inv(ll a, ll p) {
  return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
Mod operator/(Mod a, Mod b) { return a * Mod(inv(b, MOD)); }

using P = Mod;

vector<P> NTT(P omega, const vector<P> &a) {
  const int n = a.size();
  vector<P> ret = a;
  for (int m = n; m >= 2; m >>= 1, omega *= omega) {
    P rho = 1;
    REP(i,m/2) {
      for (int j = i; j < n; j += m) {
        int k = j + m / 2;
        P x = ret[j] - ret[k];
        ret[j] += ret[k];
        ret[k] = rho * x;
      }
      rho *= omega;
    }
  }
  for (int i = 0, j = 1; j < n - 1; j++) {
    for (int k = n >> 1; k > (i ^= k); k >>= 1) {;}
    if (j < i) swap(ret[i], ret[j]);
  }
  return ret;
}

vector<ll> convolution(const vector<ll> &lhs, const vector<ll> &rhs) {
  int n = 1, a = lhs.size(), b = rhs.size();
  while (n < max(a, b) * 2) n <<= 1;
  vector<P> temp1(n), temp2(n);
  REP(i,n/2) {
    if (i < a) temp1[i] = P(lhs[i]);
    if (i < b) temp2[i] = P(rhs[i]);
  }
  P root = 3;
  int index = (MOD - 1) / n;
  P omega = root ^ index;
  temp1 = NTT(omega, temp1);
  temp2 = NTT(omega, temp2);
  REP(i,n) temp1[i] *= temp2[i];
  temp1 = NTT(P(1)/omega, temp1);
  vector<ll> ret(n);
  REP(i,n) ret[i] = temp1[i] / P(n);
  return ret;
}

int main() {
  vecll fact(MAX_F+1), finv(MAX_F+1);
  fact[0] = 1;
  REP(i,MAX_F) {
    fact[i+1] = fact[i] * (i+1) % MOD;
  }
  finv[MAX_F] = inv(fact[MAX_F], MOD);
  REP(ri,MAX_F) {
    int i = MAX_F - ri;
    finv[i-1] = finv[i] * i % MOD;
  }
  ll n;
  cin>>n;
  string s;
  cin>>s;
  bitset<300000> bit_i, bit_n;
  REP(i,n) {
    if (s[i] == 'i') bit_i.set(i);
    else bit_n.set(i);
  }
  vecll poly(n+1);
  REP(k,n-1) {
    auto intersect = bit_i & (bit_n >> (k+1));
    poly[k] = intersect.count();
  }
  vecll a(n+1);
  REP(i,n-1) {
    a[i] = poly[i] * fact[i] % MOD;
  }
  vecll b(n+1);
  REP(i,n+1) {
    b[i] = finv[n-i];
  }
  vecll poly2 = convolution(a, b);
  ll ans = 0;
  REP(i,n-1) {
    ll tmp = poly2[i+n] * finv[i] % MOD;
    ans ^= tmp;
  }
  cout<<ans<<"\n";
  return 0;
}
0