結果
| 問題 |
No.295 hel__world
|
| コンテスト | |
| ユーザー |
shimomire
|
| 提出日時 | 2015-02-18 05:56:57 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,042 bytes |
| コンパイル時間 | 1,478 ms |
| コンパイル使用メモリ | 141,432 KB |
| 実行使用メモリ | 10,144 KB |
| 最終ジャッジ日時 | 2024-06-23 21:02:55 |
| 合計ジャッジ時間 | 8,211 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 11 TLE * 1 -- * 41 |
ソースコード
#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;
}
shimomire