結果

問題 No.295 hel__world
ユーザー 👑 kmjpkmjp
提出日時 2015-10-23 23:51:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 617 ms / 5,000 ms
コード長 2,327 bytes
コンパイル時間 1,536 ms
コンパイル使用メモリ 160,800 KB
実行使用メモリ 13,116 KB
最終ジャッジ日時 2023-10-11 04:44:26
合計ジャッジ時間 5,476 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------



ll S[30];
string T;
int L;
vector<int> V[26];
int num[26];

struct comp {
	bool operator()(const pair<pair<ll,ll>,pair<ll,ll>> a, const pair<pair<ll,ll>,pair<ll,ll>> b) const {
		return (__int128)a.first.first*b.first.second < (__int128)a.first.second*b.first.first;
	}
};

ll hoge(ll s,vector<int> p) {
	if(p.empty()) return 1;
	sort(ALL(p));
	
	if(s>50000000) {
		if(p.size()==1) {
			if(p[0]==1) return s;
			if(p[0]==2) {
				__int128 ss=s;
				ss=ss*(ss-1)/2;
				if(ss>=1LL<<62) {
					_P("hel\n");
					exit(0);
				}
				return (ll)ss;
			}
		}
		if(p.size()==2 && p[0]==1 && p[1]==1) {
			__int128 ss=s;
			ss=(ss/2)*(ss-ss/2);
			if(ss>=1LL<<62) {
				_P("hel\n");
				exit(0);
			}
			return (ll)ss;
		}
		_P("hel\n");
		exit(0);
	}
	
	ll tot=0;
	ll pat=1;
	priority_queue<pair<pair<ll,ll>,pair<ll,ll>>,vector<pair<pair<ll,ll>,pair<ll,ll>>>,comp> Q;
	FORR(r,p) {
		s-=r;
		tot+=r;
		Q.push(make_pair(make_pair(r+1,1),make_pair(r,r)));
	}
	while(s--) {
		auto r=Q.top();
		Q.pop();
		
		__int128 ppat=pat;
		ppat *= r.first.first;
		ppat /= r.first.second;
		if(ppat>=1LL<<62) {
			_P("hel\n");
			exit(0);
		}
		pat=ppat;
		r.second.first++;
		Q.push(make_pair(make_pair(r.second.first+1,r.second.first+1-r.second.second),r.second));
	}
	return pat;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	FOR(i,26) cin>>S[i];
	cin>>T;
	L=T.size();
	V[T[0]-'a'].push_back(1);
	FOR(i,L-1) {
		if(T[i]==T[i+1]) V[T[i+1]-'a'].back()++;
		else V[T[i+1]-'a'].push_back(1);
	}
	FOR(i,L) num[T[i]-'a']++;
	
	__int128 ret=1;
	FOR(i,26) {
		if(num[i]>S[i]) return _P("0\n");
	}
	FOR(i,26) {
		ret*=hoge(S[i],V[i]);
		if(ret>=1LL<<62) return _P("hel\n");
	}
	cout<<(ll)ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0