結果

問題 No.1504 ヌメロニム
ユーザー 👑 kmjpkmjp
提出日時 2021-05-08 13:09:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,321 ms / 2,000 ms
コード長 2,567 bytes
コンパイル時間 2,320 ms
コンパイル使用メモリ 208,936 KB
実行使用メモリ 53,160 KB
最終ジャッジ日時 2023-10-14 23:44:06
合計ジャッジ時間 28,523 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,368 KB
testcase_01 AC 5 ms
7,424 KB
testcase_02 AC 5 ms
7,400 KB
testcase_03 AC 5 ms
7,548 KB
testcase_04 AC 5 ms
7,348 KB
testcase_05 AC 5 ms
7,412 KB
testcase_06 AC 5 ms
7,412 KB
testcase_07 AC 5 ms
7,452 KB
testcase_08 AC 4 ms
7,408 KB
testcase_09 AC 5 ms
7,400 KB
testcase_10 AC 5 ms
7,360 KB
testcase_11 AC 5 ms
7,404 KB
testcase_12 AC 5 ms
7,540 KB
testcase_13 AC 5 ms
7,412 KB
testcase_14 AC 5 ms
7,368 KB
testcase_15 AC 5 ms
7,424 KB
testcase_16 AC 5 ms
7,372 KB
testcase_17 AC 5 ms
7,540 KB
testcase_18 AC 5 ms
7,388 KB
testcase_19 AC 5 ms
7,400 KB
testcase_20 AC 11 ms
7,516 KB
testcase_21 AC 8 ms
7,536 KB
testcase_22 AC 12 ms
7,608 KB
testcase_23 AC 5 ms
7,488 KB
testcase_24 AC 1,291 ms
52,560 KB
testcase_25 AC 636 ms
32,680 KB
testcase_26 AC 1,309 ms
53,116 KB
testcase_27 AC 653 ms
33,816 KB
testcase_28 AC 661 ms
33,964 KB
testcase_29 AC 1,243 ms
53,008 KB
testcase_30 AC 1,240 ms
53,040 KB
testcase_31 AC 609 ms
33,236 KB
testcase_32 AC 618 ms
33,504 KB
testcase_33 AC 386 ms
33,188 KB
testcase_34 AC 149 ms
13,512 KB
testcase_35 AC 139 ms
12,808 KB
testcase_36 AC 596 ms
29,956 KB
testcase_37 AC 70 ms
10,072 KB
testcase_38 AC 1,298 ms
53,068 KB
testcase_39 AC 1,306 ms
53,132 KB
testcase_40 AC 1,236 ms
53,092 KB
testcase_41 AC 1,248 ms
53,128 KB
testcase_42 AC 1,248 ms
53,076 KB
testcase_43 AC 1,259 ms
53,112 KB
testcase_44 AC 391 ms
33,616 KB
testcase_45 AC 389 ms
33,692 KB
testcase_46 AC 1,321 ms
53,152 KB
testcase_47 AC 1,311 ms
53,160 KB
testcase_48 AC 471 ms
31,004 KB
testcase_49 AC 465 ms
30,132 KB
testcase_50 AC 12 ms
7,600 KB
testcase_51 AC 8 ms
7,552 KB
testcase_52 AC 5 ms
7,416 KB
testcase_53 AC 8 ms
7,516 KB
testcase_54 AC 5 ms
7,500 KB
testcase_55 AC 137 ms
12,856 KB
testcase_56 AC 5 ms
7,436 KB
testcase_57 AC 5 ms
7,468 KB
testcase_58 AC 5 ms
7,392 KB
testcase_59 AC 5 ms
7,372 KB
testcase_60 AC 5 ms
7,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

const ll mo=998244353;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}


template<class T> vector<T> fft(vector<T> v, bool rev=false) {
	int n=v.size(),i,j,m;
	
	for(i=0,j=1;j<n-1;j++) {
		for(int k=n>>1;k>(i^=k);k>>=1);
		if(i>j) swap(v[i],v[j]);
	}
	for(int m=2; m<=n; m*=2) {
		T wn=modpow(5,(mo-1)/m);
		if(rev) wn=modpow(wn);
		for(i=0;i<n;i+=m) {
			T w=1;
			for(int j1=i,j2=i+m/2;j2<i+m;j1++,j2++) {
				T t1=v[j1],t2=(ll)w*v[j2]%mo;
				v[j1]=t1+t2;
				v[j2]=t1+mo-t2;
				while(v[j1]>=mo) v[j1]-=mo;
				while(v[j2]>=mo) v[j2]-=mo;
				w=(ll)w*wn%mo;
			}
		}
	}
	if(rev) {
		ll rv = modpow(n);
		FOR(i,n) v[i]=(ll)v[i]*rv%mo;
	}
	return v;
}


template<class T> vector<T> MultPoly(vector<T> P,vector<T> Q,bool resize=false) {
	if(resize) {
		int maxind=0,pi=0,qi=0,i;
		int s=2;
		FOR(i,P.size()) if(norm(P[i])) pi=i;
		FOR(i,Q.size()) if(norm(Q[i])) qi=i;
		maxind=pi+qi+1;
		while(s*2<maxind) s*=2;
		P.resize(s*2);Q.resize(s*2);
		if(s<=16) { //fastpath
			vector<T> R(s*2);
			for(int x=0;x<2*s;x++) for(int y=0;x+y<2*s;y++) (R[x+y]+=P[x]*Q[y])%=mo;
			return R;
		}
	}
	P=fft(P), Q=fft(Q);
	for(int i=0;i<P.size();i++) P[i]=(ll)P[i]*Q[i]%mo;
	return fft(P,true);
}

int N;
string S;
ll X[303030];
ll fact[303030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	fact[0]=1;
	FOR(i,301010) fact[i+1]=fact[i]*(i+1)%mo;
	
	cin>>N>>S;
	vector<ll> P(N),Q(N);
	FOR(i,N) {
		if(S[i]=='i') P[i]=1;
		else Q[N-1-i]=1;
	}
	
	P=MultPoly(P,Q,1);
	vector<ll> R(N),T(N);
	FOR(i,N) if(i) {
		if(N-1-i<P.size()) R[i-1]=P[N-1-i]*fact[i-1]%mo;
		T[i]=modpow(fact[N-1-i]);
	}
	R=MultPoly(R,T,1);
	ll ret=0;
	FOR(i,N) {
		if(N-1+i<R.size()) {
			ll x=R[N-1+i]*modpow(fact[i])%mo;
			ret^=x;
		}
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0