結果

問題 No.295 hel__world
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-14 14:07:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 403 ms / 5,000 ms
コード長 2,532 bytes
コンパイル時間 2,440 ms
コンパイル使用メモリ 212,688 KB
実行使用メモリ 17,036 KB
最終ジャッジ日時 2024-04-09 19:11:20
合計ジャッジ時間 5,295 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,812 KB
testcase_03 AC 1 ms
6,812 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 168 ms
6,944 KB
testcase_28 AC 397 ms
6,944 KB
testcase_29 AC 403 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 1 ms
6,944 KB
testcase_32 AC 65 ms
17,036 KB
testcase_33 AC 65 ms
16,524 KB
testcase_34 AC 64 ms
16,780 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 1 ms
6,940 KB
testcase_45 AC 1 ms
6,940 KB
testcase_46 AC 1 ms
6,944 KB
testcase_47 AC 1 ms
6,940 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 AC 77 ms
6,940 KB
testcase_52 AC 17 ms
6,940 KB
testcase_53 AC 23 ms
6,944 KB
testcase_54 AC 23 ms
6,944 KB
testcase_55 AC 21 ms
6,944 KB
testcase_56 AC 24 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//https://ncode.syosetu.com/n4830bu/295/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    vector<ll> S(26);
    string T;
    for (auto&& s : S) {
        cin >> s;
    }
    cin >> T;
    vector<vector<ll>> cnt(26);
    char c = '-';
    int len = 0;
    for (int i = 0; i < T.size(); i++) {
        char& t = T[i];
        if (t != c) {
            if (c != '-') {
                cnt[c - 'a'].emplace_back(len);
            }
            c = t;
            len = 0;
        }
        len++;
    }
    if (len)
        cnt[c - 'a'].emplace_back(len);
    for (int i = 0; i < 26; i++) {
        sort(begin(cnt[i]), end(cnt[i]));
    }
    __int128 ans = 1;
    auto honzuki = [&]() {
        if (ans >= (1ll << 62)) {
            cout << "hel" << endl;
            exit(0);
        }
    };
    for (int i = 0; i < 26; i++) {
        for (auto&& x : cnt[i]) {
            S[i] -= x;
        }
        if (S[i] < 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    for (int i = 0; i < 26; i++) {
        priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, function<bool(const pair<ll, ll>& x, const pair<ll, ll>& y)>> que([](const pair<ll, ll>& x, const pair<ll, ll>& y) {
            return __int128(x.first + 1) * (y.first - y.second + 1) < __int128(y.first + 1) * (x.first - x.second + 1);
        });
        for (auto&& x : cnt[i]) {
            que.push({x, x});
        }
        if (cnt[i].size() == 0)
            continue;
        if (S[i] > 1e7) {
            if (cnt[i].size() == 1) {
                if (cnt[i][0] == 1)
                    ans *= cnt[i][0] + S[i];
                else if (cnt[i][0] == 2) {
                    ans *= cnt[i][0] + S[i];
                    honzuki();
                    ans *= cnt[i][0] + S[i] - 1;
                    ans /= 2;
                }
            } else if (cnt[i].size() == 2) {
                if (cnt[i][0] == 1 && cnt[i][1] == 1) {
                    ans *= (2 + S[i]) / 2;
                    honzuki();
                    ans *= 2 + S[i] - (2 + S[i]) / 2;
                } else
                    ans *= (1ll << 62);
            } else
                ans *= (1ll << 62);
            honzuki();
            continue;
        }
        while (S[i]--) {
            auto [maine, book] = que.top();
            que.pop();
            ans *= (maine + 1);
            ans /= (maine - book + 1);
            honzuki();
            que.push({maine + 1, book});
        }
    }
    cout << (ll)ans << endl;
}
0