結果

問題 No.295 hel__world
ユーザー shimomireshimomire
提出日時 2015-02-18 05:56:57
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 3,042 bytes
コンパイル時間 1,350 ms
コンパイル使用メモリ 136,684 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2023-09-06 02:00:32
合計ジャッジ時間 8,346 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>// c
#include <iostream>// io
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>// container
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <algorithm>// other
#include <complex>
#include <numeric>
#include <functional>
#include <random>
#include <regex>
using namespace std;

using ll =long long;

#define ALL(c) (begin(c)),(end(c))
#define REP(i,n) FOR(i,0,n)
#define REPr(i,n) FORr(i,0,n)
#define FOR(i,l,r) for(int i=(int)(l);i<(int)(r);++i)
#define FORr(i,l,r) for(int i=(int)(r)-1;i>=(int)(l);--i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end())
//debug
#define DUMP(x)  cerr << #x << " = " << (x)
#define LINE()    cerr<< " (L" << __LINE__ << ")"


template<typename T,typename U> T pmod(T v,U M){return (v%M+M)%M;}
ll gcd_positive(ll a,ll b) { return b == 0 ? a : gcd_positive(b,a%b); }
ll gcd(ll a,ll b) { return gcd_positive(abs(a), abs(b)); }

// a/b
template<typename T> struct Frac{
	T a,b;
	bool operator <(const Frac& r) const{
		return this->a * r.b < this->b * r.a;
	}
	bool operator > (const Frac& r) const{
		return this->a * r.b > this->b * r.a;
	}
};

bool is_zero_t(map<char,ll>& smap,string& t){
	map<char,ll> tmap;
	for(char c:t)tmap[c]++;
	for(pair<char,ll> sp:tmap){
		char c=sp.first;
		if(smap[c]<tmap[c])return true;
	}
	return false;
}

__int128_t INF =1LL<<62;
ll mult(__int128_t a,__int128_t b){// over flow check
	if(a * b >= INF) throw exception();
	return a * b;
}

// C(N,K)
ll C(ll N,ll K){
	ll v=1;
	for(int i=K-1;i>=0;i--){
		ll d = gcd(N - i,K - i);
		v = mult(v/((K-i)/d),(N-i)/d);
	}
	return v;
}

int main(){
	cout <<fixed<<setprecision(20);
	cin.tie(0);
	ios::sync_with_stdio(false);

	map<char,ll> smap;string t;
	for(char c='a';c<='z';c++)cin >> smap[c];
	cin >> t;
	
	if(is_zero_t(smap,t)){
		cout << 0 <<endl;return 0;
	}

	//cond: res >= 1
	map<char,vector<ll>> tmap;
	for(int i = 0 ; i< t.size();){
		char c=t[i];int count=0;
		while(i<t.size() && c==t[i]){i++;count++;}
		tmap[c].push_back(count);
	}
	for(pair<char,vector<ll>> tp:tmap)sort(ALL(tmap[tp.first]));
	
	ll res = 1;
	try{
		for(pair<char,vector<ll>> tp:tmap){
			char c=tp.first;vector<ll>& tcs=tp.second;
			ll sc=smap[c];
			ll tc=0;for(int v:tcs)tc+=v;
			ll n = tcs.size();
			ll delta = sc - tc;


			ll v = 1;
			priority_queue<pair<Frac<ll>,int> > que;
			vector<ll> scs(n);REP(i,n)scs[i]=tcs[i];
			REP(i,scs.size()){
				Frac<ll> fr={scs[i]+1,scs[i]+1 - tcs[i]};
				que.push(make_pair(Frac<ll>(fr),i));
			}
			while(!que.empty() && delta >0){
				auto p = que.top();que.pop();
				ll a = p.first.a,b = p.first.b;int i = p.second;

				ll d = gcd(a,b);
				v = mult(v/(b/d),a/d);

				scs[i]++;delta--;
				Frac<ll> fr={scs[i]+1,scs[i]+1 - tcs[i]};
				que.push(make_pair(Frac<ll>(fr),i));
			}
			res =mult(res,v);
		}
		cout << res <<endl;
	}catch(const exception& e){
		cout << "hel"<<endl;return 0;
		
	}

	return 0;
}
0