結果

問題 No.603 hel__world (2)
ユーザー tails
提出日時 2017-12-10 23:26:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,045 bytes
コンパイル時間 1,685 ms
コンパイル使用メモリ 174,320 KB
実行使用メモリ 39,944 KB
最終ジャッジ日時 2024-11-30 20:58:17
合計ジャッジ時間 12,518 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main(){
      | ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define M 1000003
#define m(t)r=r*fac[(t)%M]%M*fac[(t)/M%M]%M*fac[(t)/M/M]%M

char T[M];
long S[26],x[M],y[M];
int inv[M],fac[M];
long r=1;

main(){
	fac[0]=1;
	for(int i=1;i<M;++i){
		fac[i]=1ll*fac[i-1]*i%M;
		long e,s=M,t=i,u=1,v=0;
		while(s){
			e=t/s;
			t-=e*s;
			u-=e*v;
			swap(t,s);
			swap(u,v);
		}
		inv[i]=(u+M)%M;
	}
	for(int c=0;c<26;++c)cin>>S[c];
	cin>>T;
	for(int c=0;c<26;++c){
		priority_queue<pair<double,int>> q;
		int n=0,s=0,t=-1;
		for(int i=0;!i||T[i-1];++i){
			if(T[i]==c+'a'){
				if(t<0)t=i;
			}else{
				if(t>=0){
					int xl=i-t;
					x[n]=xl;
					++n;
					s+=xl;
					if(s>S[c])r=0;
					t=-1;
				}
			}
		}
		if(s) {
			long d=S[c]/s;
			for(int j=0;j<n;++j){
				y[j]=x[j]*d;
				q.push(make_pair(1.*~y[j]/x[j],j));
			}
			for(S[c]%=s;S[c]--;){
				int j=q.top().second;q.pop();
				++y[j];
				q.push(make_pair(1.*~y[j]/x[j],j));
			}
			for(int j=0;j<n;++j){
				m(y[j]);
				r=inv[r];
				m(y[j]-x[j]);
				m(x[j]);
				r=inv[r];
			}
		}
	}
	cout<<r;
}
0