結果

問題 No.295 hel__world
ユーザー sigma425sigma425
提出日時 2017-09-15 01:13:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 378 ms / 5,000 ms
コード長 2,351 bytes
コンパイル時間 1,546 ms
コンパイル使用メモリ 171,892 KB
実行使用メモリ 27,840 KB
最終ジャッジ日時 2024-04-25 10:31:37
合計ジャッジ時間 6,494 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 147 ms
5,376 KB
testcase_28 AC 376 ms
5,376 KB
testcase_29 AC 375 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 63 ms
27,548 KB
testcase_33 AC 67 ms
27,840 KB
testcase_34 AC 62 ms
27,824 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 249 ms
5,376 KB
testcase_44 AC 250 ms
5,376 KB
testcase_45 AC 255 ms
5,376 KB
testcase_46 AC 252 ms
5,376 KB
testcase_47 AC 378 ms
5,376 KB
testcase_48 AC 367 ms
5,376 KB
testcase_49 AC 365 ms
5,376 KB
testcase_50 AC 1 ms
5,376 KB
testcase_51 AC 69 ms
5,376 KB
testcase_52 AC 15 ms
5,376 KB
testcase_53 AC 21 ms
5,376 KB
testcase_54 AC 21 ms
5,376 KB
testcase_55 AC 21 ms
5,376 KB
testcase_56 AC 20 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef __int128 ll;
istream& operator>>(istream& i, ll& x){
	x=0;
	string s;
	i>>s;
	int N=s.size(),it=0;
	if(s[0]=='-') it++;
	for(;it<N;it++) x=(x*10+s[it]-'0');
	if(s[0]=='-') x=-x;
	return i;
}
ostream& operator<<(ostream& o, const ll& x){
	ll tmp=x;
	if(tmp==0) return o<<0;
	if(tmp<0) o<<'-',tmp=-tmp;
	vector<int> ds;
	while(tmp) ds.pb(tmp%10),tmp/=10;
	reverse(all(ds));
	for(int d:ds) o<<d;
	return o;
}

ll INF = 1LL<<62;
ll xs[26];
vector<ll> c2ts[26];

using namespace rel_ops;

struct F{
	ll a,b;
	F(ll a,ll b):a(a),b(b){}
	bool operator<(const F& r) const {
		return a*r.b < b*r.a;
	}
};


int main(){
	rep(i,26) cin>>xs[i];
	{
		string t;
		cin>>t;
		int N = t.size();
		int num = 1;
		rep(i,N){
			if(i==N-1 || t[i]!=t[i+1]){
				c2ts[t[i]-'a'].pb(num);
				num = 0;
			}
			num++;
		}
	}
	rep(i,26){
		ll x = xs[i];
		vector<ll> ts = c2ts[i];
		ll T = 0;
		for(ll t:ts) T += t;
		if(T>x){
			puts("0");
			return 0;
		}
	}
	ll ans = 1;
	rep(i,26){
		ll x = xs[i];
		vector<ll> ts = c2ts[i];
		ll T = 0;
		for(ll t:ts) T += t;
		if(T==0) continue;
		if(T==1){
			ans *= x;
			if(ans>=INF) break;
			continue;
		}
		if(T==2){
			if(ts.size() == 1){
				if(x%2==0){
					ans *= x/2;
					if(ans>=INF) break;
					ans *= x-1;
					if(ans>=INF) break;
				}else{
					ans *= x;
					if(ans>=INF) break;
					ans *= (x-1)/2;
					if(ans>=INF) break;
				}
			}else{
				ans *= x/2;
				if(ans>=INF) break;
				ans *= (x+1)/2;
				if(ans>=INF) break;
			}
			continue;
		}
		priority_queue<F> que;
		for(ll t:ts) que.push(F(t+1,1));
		for(;x-T>0;x--){
			F f = que.top();
			que.pop();
			ans *= f.a;
			ans /= f.b;
			if(ans>=INF) break;
			que.push(F(f.a+1,f.b+1));
		}
	}
	if(ans >= INF){
		puts("hel");
	}else{
		cout<<ans<<endl;
	}
}
0