結果

問題 No.295 hel__world
ユーザー chocoruskchocorusk
提出日時 2020-02-23 14:22:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,059 bytes
コンパイル時間 1,352 ms
コンパイル使用メモリ 122,508 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-18 08:41:45
合計ジャッジ時間 8,660 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 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 <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef __int128_t lll;
const ll INF=1ll<<62;
struct R{
  ll x, y;
  R(ll x, ll y):x(x), y(y){}
  R(ll x):x(x), y(1ll){}
  bool operator==(const R a) const{
    return x*a.y==y*a.x;
  }
  bool operator<(const R a) const{
    return x*a.y<y*a.x;
  }
};
ll solve(ll x, vector<int> v){
    int m=v.size();
    if(m==0) return 1;
    int sum=0;
    for(auto a:v) sum+=a;
    if(x<sum) return 0;
    else if(x==sum) return 1;
    sort(v.begin(), v.end());
    ll ret=1;
    using Pr=pair<R, int>;
    vector<int> c(m);
    priority_queue<Pr> que;
    for(int i=0; i<m; i++){
        que.push({R(v[i]+1), i});
    }
    for(ll i=0; i<x-sum; i++){
        auto p=que.top(); que.pop();
        int k=p.second;
        lll ret1=(lll)ret*(v[k]+c[k]+1)/(c[k]+1);
        if(ret1>=INF) return INF;
        ret=ret1; c[k]++;
        que.push({R(v[k]+c[k]+1, c[k]+1), k});
    }
    return ret;
}
int main()
{
    ll x[26];
    for(int i=0; i<26; i++) cin>>x[i];
    string t; cin>>t;
    vector<int> v[26];
    int cnt=1;
    for(int i=1; i<t.size(); i++){
        if(t[i]!=t[i-1]){
            v[t[i-1]-'a'].push_back(cnt);
            cnt=0;
        }
        cnt++;
    }
    v[t.back()-'a'].push_back(cnt);
    ll ans=1;
    for(int i=0; i<26; i++){
        ll a=solve(x[i], v[i]);
        if(a==0){
            cout<<0<<endl;
            return 0;
        }else if(ans>INF/a){
            ans=INF;
        }else{
            ans*=a;
        }
    }
    if(ans>=INF) cout<<"hel"<<endl;
    else cout<<ans<<endl;
    return 0;
}
0