結果

問題 No.295 hel__world
ユーザー maine_honzuki
提出日時 2021-05-14 14:07:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 429 ms / 5,000 ms
コード長 2,532 bytes
コンパイル時間 2,446 ms
コンパイル使用メモリ 210,592 KB
最終ジャッジ日時 2025-01-21 10:53:39
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0