結果

問題 No.295 hel__world
ユーザー Yang33
提出日時 2018-09-29 02:31:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 602 ms / 5,000 ms
コード長 2,976 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 179,368 KB
実行使用メモリ 12,996 KB
最終ジャッジ日時 2024-10-12 07:56:18
合計ジャッジ時間 5,176 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9; const LL LINF = 1e16;
const LL MOD = 1000000007; const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- 2018/09/28 Problem: yukicoder 295 / Link: http://yukicoder.me/problems/no/295 ----- */
/* ------------
---------- */
/* ----------
-------- */
using LLL = __int128;
const LLL Max = 1LL << 62;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
VL a(26);
FOR(i, 0, 26) {
cin >> a[i];
}
string t; cin >> t;
{
VI alphanum(26);
FOR(i, 0, SZ(t)) {
alphanum[t[i] - 'a']++;
}
FOR(i, 0, 26) {
if (alphanum[i] > a[i]) { cout << 0 << endl; return 0; }
}
}
{
VVI alpha(26);
alpha[t[0] - 'a'].push_back(1);
FOR(i, 0, SZ(t) - 1) {
if (t[i] == t[i + 1]) {
alpha[t[i] - 'a'].back()++;
}
else {
alpha[t[i + 1] - 'a'].push_back(1);
}
}
struct Frac {
LLL n, d;
Frac(LL n, LL d) :n(n), d(d) {}
bool operator < (const Frac& a) const { return n * (a.n - a.d) < (n - d)*a.n; } //
};
// sectionsection(i)<=a[i]a
auto f = [](LLL a, const VI& section) ->LLL {
LLL ret = 1;
if (!SZ(section))return 1;
if (a > 5e6) {
if (SZ(section) == 1) {
if (section.front() == 1)return a;
if (section.front() == 2)return a * (a - 1) / 2;
LLL ret = a * (a - 1)*(a - 2) / 6;
assert(ret >= Max);
return Max;
}
if (SZ(section) == 2) {
if (section.front() == 1 && section.back() == 1) {
return (a) / 2 * (a - a / 2);
}
}
return Max;
}
priority_queue<Frac, vector<Frac>>pq;
FOR(i, 0, SZ(section)) {
a -= section[i];
pq.push(Frac(section[i] + 1, section[i]));
}
while (a > 0) {
Frac high = pq.top(); pq.pop();
ret = ret * high.n / (high.n - high.d);
if (ret >= Max)return Max;
high.n++;
pq.push(high);
a--;
}
return ret;
};
LLL ans = 1;
FOR(i, 0, 26) {
LLL ret = f(a[i], alpha[i]);
if (ret >= Max) { cout << "hel" << endl; return 0; }
ans *= ret;
if (ans >= Max) { cout << "hel" << endl; return 0; }
}
cout << (LL)ans << "\n";
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0