結果
| 問題 | No.603 hel__world (2) | 
| コンテスト | |
| ユーザー |  tails | 
| 提出日時 | 2017-12-03 06:27:56 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,377 bytes | 
| コンパイル時間 | 1,577 ms | 
| コンパイル使用メモリ | 174,692 KB | 
| 実行使用メモリ | 34,052 KB | 
| 最終ジャッジ日時 | 2024-11-28 08:39:57 | 
| 合計ジャッジ時間 | 11,148 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 WA * 5 | 
コンパイルメッセージ
main.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   42 | main(){
      | ^~~~
            
            ソースコード
#include <bits/stdc++.h>
using namespace std;
#define MD 1000003
long long S[26];
char T[1000010];
int xlen[1000010];
long long xnnn[1000010];
int inv[1000010];
int fac[1000010];
int get_inv(long long a, int md){
long long e, s=md, t=a, u=1, v=0;
while(s){
e=t/s;
t-=e*s;
u-=e*v;
swap(t,s);
swap(u,v);
}
if(u<0){
u+=md;
}
return u;
}
void mkinv(){
	for(int i=1;i<MD;++i){
		inv[i]=get_inv(i,MD);
	}
}
void mkfac(){
	fac[0]=1;
	for(int i=1;i<MD;++i){
		fac[i]=(long long)fac[i-1]*i%MD;
	}
}
main(){
	mkinv();
	mkfac();
	for(int c=0;c<26;++c){
		cin>>S[c];
	}
	cin>>T;
	int tlen=strlen(T);
	int r=1;
	int mc=0;
	for(int c=0;c<26;++c){
		priority_queue<pair<double,int>> pq;
		int n=0;
		int st=-1;
		int xsum=0;
		for(int i=0;i<=tlen;++i){
			if(T[i]==c+'a'){
				if(st<0){
					st=i;
				}
			}else{
				if(st>=0){
					int xl=i-st;
					xlen[n]=xl;
					//pq.push(make_pair(1.*(xl+1),n));
					++n;
					//if((S[c]-=xl)<0){
					xsum+=xl;
					if(xsum>S[c]){
						cout<<0;
						exit(0);
					}
					st=-1;
				}
			}
		}
		if(xsum) {
#if 1
			long long xdiv = S[c]/xsum;
			S[c]%=xsum;
			for(int j=0;j<n;++j){
				xnnn[j]=xlen[j]*xdiv;
				r=(long long)r*fac[xnnn[j]%MD]%MD;
				r=(long long)r*fac[xnnn[j]/MD%MD]%MD;
				r=(long long)r*fac[xnnn[j]/MD/MD%MD]%MD;
				if(xnnn[j]/MD%2) r=(MD-r)%MD;
				if(xnnn[j]/MD/MD%2) r=(MD-r)%MD;
				mc+=xnnn[j]/MD;
				mc+=xnnn[j]/MD/MD;
				r=(long long)r*inv[fac[(xnnn[j]-xlen[j])%MD]]%MD;
				r=(long long)r*inv[fac[(xnnn[j]-xlen[j])/MD%MD]]%MD;
				r=(long long)r*inv[fac[(xnnn[j]-xlen[j])/MD/MD%MD]]%MD;
				if((xnnn[j]-xlen[j])/MD%2) r=(MD-r)%MD;
				if((xnnn[j]-xlen[j])/MD/MD%2) r=(MD-r)%MD;
				mc-=(xnnn[j]-xlen[j])/MD;
				mc-=(xnnn[j]-xlen[j])/MD/MD;
				r=(long long)r*inv[fac[xlen[j]%MD]]%MD;
				pq.push(make_pair(1.*(xnnn[j]+1)/(xnnn[j]+1-xlen[j]),j));
			}
#else
			S[c]-=xsum;
			for(int j=0;j<n;++j){
				xnnn[j]=xlen[j];
				pq.push(make_pair(1.*(xnnn[j]+1)/(xnnn[j]+1-xlen[j]),j));
			}
#endif
			while(S[c]--){
				auto p=pq.top();pq.pop();
				int j=p.second;
				++xnnn[j];
				int t=xnnn[j];
				while(t%MD==0){
					t/=MD;
					++mc;
				}
				r=(long long)r*(t%MD)%MD;
				t=xnnn[j]-xlen[j];
				while(t%MD==0){
					t/=MD;
					--mc;
				}
				r=(long long)r*inv[t%MD]%MD;
				pq.push(make_pair(1.*(xnnn[j]+1)/(xnnn[j]+1-xlen[j]),j));
			}
			if(mc){
				cout<<0;
				exit(0);
			}
		}
	}
	cout<<r;
}
            
            
            
        