結果

問題 No.603 hel__world (2)
ユーザー chocoruskchocorusk
提出日時 2020-02-23 14:35:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,373 bytes
コンパイル時間 1,309 ms
コンパイル使用メモリ 121,232 KB
実行使用メモリ 36,304 KB
最終ジャッジ日時 2024-04-18 08:41:50
合計ジャッジ時間 4,187 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 WA -
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 35 ms
12,560 KB
testcase_12 WA -
testcase_13 AC 33 ms
12,452 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
5,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 23 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
    if(m==1){
        ll ret=1;
        for(int i=0; i<v[0]; i++){
            lll ret1=(lll)ret*(x-i)/(i+1);
            if(ret1>=INF) return INF;
            ret=ret1;
        }
        return ret;
    }else if(m==2 && v[0]==1 && v[1]==1){
        lll ret=(lll)(x/2)*((x+1)/2);
        if(ret>=INF) return INF;
        else return ret;
    }
    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