結果

問題 No.1504 ヌメロニム
ユーザー milanis48663220milanis48663220
提出日時 2021-07-05 23:17:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 2,391 bytes
コンパイル時間 2,666 ms
コンパイル使用メモリ 156,372 KB
実行使用メモリ 28,580 KB
最終ジャッジ日時 2023-09-14 04:17:01
合計ジャッジ時間 10,396 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,808 KB
testcase_01 AC 10 ms
6,880 KB
testcase_02 AC 10 ms
6,852 KB
testcase_03 AC 10 ms
7,052 KB
testcase_04 AC 10 ms
6,856 KB
testcase_05 AC 11 ms
6,876 KB
testcase_06 AC 11 ms
6,808 KB
testcase_07 AC 11 ms
6,856 KB
testcase_08 AC 11 ms
6,988 KB
testcase_09 AC 11 ms
6,916 KB
testcase_10 AC 11 ms
6,804 KB
testcase_11 AC 10 ms
6,852 KB
testcase_12 AC 11 ms
6,808 KB
testcase_13 AC 11 ms
6,916 KB
testcase_14 AC 10 ms
7,008 KB
testcase_15 AC 10 ms
6,916 KB
testcase_16 AC 10 ms
6,916 KB
testcase_17 AC 10 ms
6,852 KB
testcase_18 AC 10 ms
6,808 KB
testcase_19 AC 11 ms
6,792 KB
testcase_20 AC 13 ms
7,048 KB
testcase_21 AC 11 ms
7,012 KB
testcase_22 AC 11 ms
6,928 KB
testcase_23 AC 10 ms
6,808 KB
testcase_24 AC 226 ms
27,724 KB
testcase_25 AC 146 ms
19,404 KB
testcase_26 AC 231 ms
28,528 KB
testcase_27 AC 152 ms
20,844 KB
testcase_28 AC 155 ms
20,972 KB
testcase_29 AC 226 ms
28,156 KB
testcase_30 AC 223 ms
28,244 KB
testcase_31 AC 139 ms
20,096 KB
testcase_32 AC 146 ms
20,616 KB
testcase_33 AC 227 ms
28,248 KB
testcase_34 AC 41 ms
9,904 KB
testcase_35 AC 36 ms
9,440 KB
testcase_36 AC 120 ms
17,264 KB
testcase_37 AC 25 ms
8,128 KB
testcase_38 AC 236 ms
28,572 KB
testcase_39 AC 231 ms
28,396 KB
testcase_40 AC 238 ms
28,560 KB
testcase_41 AC 231 ms
28,580 KB
testcase_42 AC 237 ms
28,564 KB
testcase_43 AC 230 ms
28,448 KB
testcase_44 AC 230 ms
28,388 KB
testcase_45 AC 225 ms
28,512 KB
testcase_46 AC 236 ms
28,384 KB
testcase_47 AC 234 ms
28,464 KB
testcase_48 AC 145 ms
20,200 KB
testcase_49 AC 141 ms
19,400 KB
testcase_50 AC 13 ms
7,100 KB
testcase_51 AC 11 ms
6,972 KB
testcase_52 AC 11 ms
6,808 KB
testcase_53 AC 11 ms
7,096 KB
testcase_54 AC 11 ms
6,788 KB
testcase_55 AC 37 ms
9,392 KB
testcase_56 AC 10 ms
6,928 KB
testcase_57 AC 11 ms
6,912 KB
testcase_58 AC 11 ms
7,016 KB
testcase_59 AC 11 ms
6,808 KB
testcase_60 AC 10 ms
6,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>
#include <atcoder/convolution>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;
using mint = atcoder::modint998244353;

const ll MOD = 998244353;

#define N_MAX 300002
mint inv[N_MAX],fac[N_MAX],finv[N_MAX];

void init(){
    fac[0]=1;fac[1]=1;
    finv[0]=1;finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=mint(MOD)-inv[MOD%i]*(MOD/i);
        fac[i]=fac[i-1]*(ll) i;
        finv[i]=finv[i-1]*inv[i];
    }
}

mint pow(mint a, ll n) {
    assert(n >= 0);
	mint ans = 1;
	mint tmp = a;
	for (int i = 0; i <= 60; i++) {
		ll m = (ll)1 << i;
		if (m & n) {
		ans *= tmp;
		}
		tmp *= tmp;
	}
	return ans;
}

/**
 * a0+a1*(x+c)^1+ ... + an*(x+c)^nの係数を求める
 */ 
vector<mint> slide_polynomial(vector<mint> a, int c){
    int n = a.size();
    vector<mint> u(n), v(n);
    for(int i = 0; i < n; i++) {
        u[i] = a[i]*fac[i];
        v[i] = pow(mint(c), n-i-1)*finv[n-i-1];
    }
    auto w = atcoder::convolution(u, v);
    vector<mint> ans(n);
    for(int i = 0; i < n; i++) ans[i] = finv[i]*w[i+n-1];
    return ans;
}

void print(vector<mint> v){
    for(mint x: v) cout << x.val() << ' ';
    cout << endl;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    int n;
    string s;
    cin >> n >> s;
    vector<mint> vi(n), vn(n);
    for(int i = 0; i < n; i++){
        if(s[i] == 'n'){
            vn[i] = 1;
        }else{
            vi[n-i-1] = 1;
        }
    }
    auto v = atcoder::convolution(vn, vi);
    vector<mint> u(n-1); // iとnの間がk個のものがu[k]個ある
    for(int i = 1; i < n; i++) u[i-1] = v[i+n-1];
    auto f = slide_polynomial(u, 1);
    int ans = 0;
    for(int i = 0; i < n-1; i++) ans ^= f[i].val();
    cout << ans << endl;
}
0