結果

問題 No.603 hel__world (2)
ユーザー 👑 kmjpkmjp
提出日時 2017-12-03 21:39:18
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,959 bytes
コンパイル時間 1,373 ms
コンパイル使用メモリ 173,928 KB
実行使用メモリ 31,408 KB
最終ジャッジ日時 2024-05-06 09:16:27
合計ジャッジ時間 18,363 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 378 ms
31,408 KB
testcase_01 AC 392 ms
11,116 KB
testcase_02 AC 384 ms
11,136 KB
testcase_03 AC 383 ms
11,136 KB
testcase_04 AC 382 ms
11,136 KB
testcase_05 AC 383 ms
11,136 KB
testcase_06 AC 387 ms
11,132 KB
testcase_07 AC 384 ms
11,076 KB
testcase_08 RE -
testcase_09 AC 382 ms
11,200 KB
testcase_10 AC 394 ms
11,136 KB
testcase_11 AC 426 ms
20,776 KB
testcase_12 AC 437 ms
20,608 KB
testcase_13 AC 487 ms
20,904 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 398 ms
11,136 KB
testcase_20 AC 389 ms
12,000 KB
testcase_21 AC 381 ms
12,124 KB
testcase_22 AC 380 ms
11,264 KB
testcase_23 AC 374 ms
11,196 KB
testcase_24 AC 382 ms
11,200 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

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 rev[1010101];

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<pair<ll,ll>,pair<ll,ll>> a, const pair<pair<ll,ll>,pair<ll,ll>> b) const {
		return a.first.first*b.first.second < a.first.second*b.first.first;
	}
};

__int128 hoge(ll s,vector<int> p) {
	if(p.empty()) return 1;
	sort(ALL(p));
	
	
	ll pat=1;
	priority_queue<pair<pair<ll,ll>,pair<ll,ll>>,vector<pair<pair<ll,ll>,pair<ll,ll>>>,comp> Q;
	FORR(r,p) s-=r, Q.push(make_pair(make_pair(r+1,1),make_pair(r,r)));
	
	while(s--) {
		auto r=Q.top();
		Q.pop();
		
		pat=pat * r.first.first * rev[r.first.second] % mo;
		
		r.second.first++;
		Q.push(make_pair(make_pair(r.second.first+1,r.second.first+1-r.second.second),r.second));
	}
	return pat%mo;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	for(i=1;i<mo;i++) rev[i]=modpow(i);
	
	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