結果

問題 No.295 hel__world
ユーザー Yang33Yang33
提出日時 2018-09-29 02:31:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 628 ms / 5,000 ms
コード長 2,976 bytes
コンパイル時間 2,325 ms
コンパイル使用メモリ 175,260 KB
実行使用メモリ 13,012 KB
最終ジャッジ日時 2024-04-20 12:34:50
合計ジャッジ時間 5,321 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 1 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 2 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 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 154 ms
5,376 KB
testcase_28 AC 310 ms
5,376 KB
testcase_29 AC 628 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 44 ms
13,012 KB
testcase_33 AC 43 ms
12,764 KB
testcase_34 AC 43 ms
13,008 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 59 ms
5,376 KB
testcase_52 AC 13 ms
5,376 KB
testcase_53 AC 8 ms
5,376 KB
testcase_54 AC 9 ms
5,376 KB
testcase_55 AC 9 ms
5,376 KB
testcase_56 AC 8 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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; } // 逆だと思うんですよね
		};

		// sectionに対して、section(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;
}
0