結果

問題 No.603 hel__world (2)
ユーザー tails
提出日時 2017-12-03 05:28:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,262 bytes
コンパイル時間 1,605 ms
コンパイル使用メモリ 173,512 KB
実行使用メモリ 28,260 KB
最終ジャッジ日時 2024-11-28 08:34:29
合計ジャッジ時間 43,639 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 TLE * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main(){
      | ^~~~

ソースコード

diff #

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

#define MD 1000003

long long S[26];
char T[1000010];
int xlen[1000010];
int xnnn[1000010];

int inv[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);
	}
}

main(){
	mkinv();
	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;
		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;
					xnnn[n]=xl;
					pq.push(make_pair(1.*(xl+1),n));
					++n;
					if((S[c]-=xl)<0){
						cout<<0;
						exit(0);
					}
					st=-1;
				}
			}
		}
		if(n)
		while(S[c]--){
			auto p=pq.top();pq.pop();
			n=p.second;
			++xnnn[n];
			pq.push(make_pair(1.*(xnnn[n]+1)/(xnnn[n]+1-xlen[n]),n));
			int t=xnnn[n];
			while(t%MD==0){
				t/=MD;
				++mc;
			}
			r=(long long)r*(t%MD)%MD;
			t=xnnn[n]-xlen[n];
			while(t%MD==0){
				t/=MD;
				--mc;
			}
			r=(long long)r*inv[t%MD]%MD;
		}
		if(mc){
			cout<<0;
			exit(0);
		}
	}
	cout<<r;
}
0