結果
問題 | No.295 hel__world |
ユーザー | kei |
提出日時 | 2018-10-07 00:38:12 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 544 ms / 5,000 ms |
コード長 | 3,877 bytes |
コンパイル時間 | 2,289 ms |
コンパイル使用メモリ | 188,244 KB |
実行使用メモリ | 18,316 KB |
最終ジャッジ日時 | 2024-10-12 14:06:50 |
合計ジャッジ時間 | 5,192 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 2 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 3 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 136 ms
5,248 KB |
testcase_28 | AC | 271 ms
5,248 KB |
testcase_29 | AC | 544 ms
5,248 KB |
testcase_30 | AC | 2 ms
5,248 KB |
testcase_31 | AC | 2 ms
5,248 KB |
testcase_32 | AC | 45 ms
18,144 KB |
testcase_33 | AC | 45 ms
17,856 KB |
testcase_34 | AC | 45 ms
18,316 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 2 ms
5,248 KB |
testcase_37 | AC | 2 ms
5,248 KB |
testcase_38 | AC | 2 ms
5,248 KB |
testcase_39 | AC | 2 ms
5,248 KB |
testcase_40 | AC | 2 ms
5,248 KB |
testcase_41 | AC | 2 ms
5,248 KB |
testcase_42 | AC | 2 ms
5,248 KB |
testcase_43 | AC | 2 ms
5,248 KB |
testcase_44 | AC | 2 ms
5,248 KB |
testcase_45 | AC | 2 ms
5,248 KB |
testcase_46 | AC | 1 ms
5,248 KB |
testcase_47 | AC | 2 ms
5,248 KB |
testcase_48 | AC | 2 ms
5,248 KB |
testcase_49 | AC | 2 ms
5,248 KB |
testcase_50 | AC | 2 ms
5,248 KB |
testcase_51 | AC | 51 ms
5,248 KB |
testcase_52 | AC | 10 ms
5,248 KB |
testcase_53 | AC | 7 ms
5,248 KB |
testcase_54 | AC | 6 ms
5,248 KB |
testcase_55 | AC | 6 ms
5,248 KB |
testcase_56 | AC | 6 ms
5,248 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; } template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; } template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; } template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; } /* <url:https://yukicoder.me/problems/no/295> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); } } return os; } __int128_t Lim = 1LL<<62; istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; } using Items = tuple<ll,ll,ll,ll>; struct comp{ bool operator()(const Items& a,const Items& b) const{ return get<0>(a)*get<1>(b) < get<1>(a)*get<0>(b); } }; __int128_t calc(ll S,vector<ll> ness){ if(ness.empty()) return 1; __int128_t ret = S; if(S > 1e7){ if(ness.size()==1){ if(ness[0]==1) return ret; if(ness[0]==2) return ret*(ret-1)/2; } if(ness.size()==2 && ness[0]==1 && ness[1]==1) return (ret/2)*(ret-ret/2); return Lim; } ret = 1; priority_queue<Items,vector<Items>,comp> pq; for(auto s:ness){ S -= s; pq.push(Items(s+1,1,s,s)); } while(S--){ ll a,b,c,d; tie(a,b,c,d) = pq.top(); pq.pop(); ret = ret*a/b; if(ret>=Lim) return ret; c++; pq.push(Items(c+1,c+1-d,c,d)); } return ret; } string solve(){ string res; vector<ll> S(26); for(auto& in:S){ cin >> in;} string T; cin >> T; vector<vector<ll>> ness(26); pll target = {T.front()-'a',1}; for(int i = 1; i < T.length();i++){ if(target.first==T[i]-'a') target.second++; else { ness[target.first].push_back(target.second); target = {T[i]-'a',1};} } ness[target.first].push_back(target.second); for(int i = 0; i < 26;i++){ if(S[i] < accumulate(ness[i].begin(),ness[i].end(),0LL)) return to_string(0); sort(ness[i].begin(),ness[i].end()); } __int128_t mul = 1; for(int i = 0; i < 26;i++){ __int128_t ret = calc(S[i],ness[i]); if(ret >= Lim) return "hel"; mul *= ret; if(mul >= Lim) return "hel"; } return to_string((ll)mul); } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); cout << solve() << endl; return 0; }