結果

問題 No.603 hel__world (2)
ユーザー 👑 kmjpkmjp
提出日時 2017-12-15 21:16:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 716 ms / 3,000 ms
コード長 2,446 bytes
コンパイル時間 2,998 ms
コンパイル使用メモリ 158,180 KB
実行使用メモリ 25,864 KB
最終ジャッジ日時 2023-08-21 06:46:52
合計ジャッジ時間 8,970 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 506 ms
11,368 KB
testcase_12 AC 504 ms
11,200 KB
testcase_13 AC 526 ms
11,340 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 52 ms
4,380 KB
testcase_21 AC 52 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 587 ms
11,368 KB
testcase_26 AC 581 ms
11,136 KB
testcase_27 AC 607 ms
11,432 KB
testcase_28 AC 716 ms
25,864 KB
testcase_29 AC 51 ms
4,380 KB
testcase_30 AC 26 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 51 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#undef _P
#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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll S[30];
string T;
int L;
vector<int> V[26];
int num[26];
ll mo=1000003;

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;
}

struct comp {
	bool operator()(const pair<ll,ll> a, const pair<ll,ll> b) const {
		return (__int128_t)a.first*b.second < (__int128_t)a.second*b.first;
	}
};

pair<ll,ll> comb(ll a,ll b) {
	ll p=1;
	ll q=1;
	int dif=0;
	while(b) {
		if(a%mo==0) {
			dif++;
			if(a/mo%mo==0) {
				dif++;
				(p*=a/mo/mo)%=mo;
			}
			else {
				(p*=a/mo)%=mo;
			}
		}
		else {
			(p*=a%mo)%=mo;
		}
		if(b%mo==0) {
			dif--;
			(q*=b/mo)%=mo;
		}
		else {
			(q*=b%mo)%=mo;
		}
		a--;
		b--;
	}
	return {p*modpow(q)%mo,dif};
}

ll hoge(ll s,vector<int> p) {
	if(p.empty()) return 1;
	sort(ALL(p));
	
	
	ll a=1,b=1;
	priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,comp> Q;
	ll sum=0;
	FORR(r,p) sum+=r;
	ll pre=s/sum;
	s%=sum;
	int dif=0;
	FORR(r,p) {
		auto c=comb(r*pre,r);
		(a*=c.first)%=mo;
		dif+=c.second;
		Q.push(make_pair(r*pre+1,r*(pre-1)+1));
	}
	while(s--) {
		auto r=Q.top();
		Q.pop();
		
		
		ll x=r.first;
		while(x%mo==0) {
			dif++;
			x/=mo;
		}
		a = x%mo*a%mo;
		x=r.second;
		while(x%mo==0) {
			dif--;
			x/=mo;
		}
		b = x%mo*b%mo;
		
		r.first++;
		r.second++;
		Q.push(r);
	}
	/*
	while(Q.size()) {
		auto a=Q.top();
		Q.pop();
		cout<<a.first<<" "<<a.second<<endl;
	}
	*/
	if(dif) return 0;
	return a*modpow(b)%mo;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	FOR(i,26) cin>>S[i];
	cin>>T;
	L=T.size();
	
	V[T[0]-'a'].push_back(1);
	FOR(i,L-1) {
		if(T[i]==T[i+1]) V[T[i+1]-'a'].back()++;
		else V[T[i+1]-'a'].push_back(1);
	}
	FOR(i,L) num[T[i]-'a']++;
	
	__int128 ret=1;
	FOR(i,26) if(num[i]>S[i]) return _P("0\n");
	FOR(i,26) (ret*=hoge(S[i],V[i]))%=mo;
	
	cout<<(ll)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