結果
問題 | No.295 hel__world |
ユーザー | Min_25 |
提出日時 | 2017-05-04 21:51:18 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,083 bytes |
コンパイル時間 | 1,051 ms |
コンパイル使用メモリ | 104,800 KB |
実行使用メモリ | 10,780 KB |
最終ジャッジ日時 | 2024-09-14 07:16:27 |
合計ジャッジ時間 | 5,495 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 2 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 | WA | - |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 270 ms
5,376 KB |
testcase_29 | AC | 569 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | WA | - |
testcase_32 | AC | 70 ms
10,612 KB |
testcase_33 | AC | 69 ms
10,780 KB |
testcase_34 | AC | 70 ms
10,748 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 | 203 ms
5,376 KB |
testcase_44 | AC | 200 ms
5,376 KB |
testcase_45 | AC | 202 ms
5,376 KB |
testcase_46 | AC | 202 ms
5,376 KB |
testcase_47 | AC | 270 ms
5,376 KB |
testcase_48 | AC | 275 ms
5,376 KB |
testcase_49 | AC | 279 ms
5,376 KB |
testcase_50 | AC | 2 ms
5,376 KB |
testcase_51 | AC | 54 ms
5,376 KB |
testcase_52 | AC | 11 ms
5,376 KB |
testcase_53 | AC | 7 ms
5,376 KB |
testcase_54 | AC | 7 ms
5,376 KB |
testcase_55 | AC | 7 ms
5,376 KB |
testcase_56 | AC | 7 ms
5,376 KB |
ソースコード
#include <cstdio> #include <cassert> #include <cmath> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <map> #include <set> #include <functional> #include <stack> #include <queue> #include <tuple> #define getchar getchar_unlocked #define putchar putchar_unlocked #define _rep(_1, _2, _3, _4, name, ...) name #define rep2(i, n) rep3(i, 0, n) #define rep3(i, a, b) rep4(i, a, b, 1) #define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c)) #define rep(...) _rep(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__) using namespace std; using i64 = long long; using u32 = unsigned; using u64 = unsigned long long; using f80 = long double; using i128 = __int128_t; void solve() { const i64 lim = i64(1) << 62; i64 counts[26]; static char str[1000010]; while (~scanf("%lld", &counts[0])) { rep(i, 1, 26) scanf("%lld", &counts[i]); scanf("%s", str); const int slen = strlen(str); rep(i, slen) str[i] -= 'a'; vector<int> lens[26]; int freqs[26] = {}; { int i = 0; for (int j; i < slen; i = j) { int c = str[i]; j = i + 1; while (j < slen && str[j] == c) ++j; lens[c].push_back(j - i); freqs[c] += j - i; } } struct Fraction { Fraction() {} Fraction(int n, int d) : n(n), d(d) {} bool operator < (const Fraction& rhs) const { return i64(n) * rhs.d < i64(d) * rhs.n; } int n, d; }; i128 ans = 1; rep(i, 26) { if (freqs[i] == 0) continue; if (freqs[i] > counts[i]) { ans = 0; break; } i64 rest = counts[i] - freqs[i]; auto binom = [&] (i64 n, int k) { i128 ret = 1; rep(i, k) { ret = ret * (n - i) / (i + 1); if (ret >= lim) return i128(lim); } return ret; }; sort(lens[i].begin(), lens[i].end()); bool brute = false; i128 prod = 1; if (lens[i].size() <= 2) { if (lens[i].size() == 1) { prod = binom(counts[i], lens[i][0]); } else { if (lens[i][1] == 1) { prod = i128(counts[i] / 2) * (counts[i] - counts[i] / 2); } else brute = true; } } else brute = true; if (brute) { using P = pair<int, int>; priority_queue< pair<Fraction, P> > que; rep(id, lens[i].size()) { que.push({{lens[i][id] + 1, 1}, {id, 1}}); } for (; rest; --rest) { auto d = que.top(); que.pop(); auto f = d.first; int id, j; tie(id, j) = d.second; prod = prod * f.n / f.d; if (prod >= lim) break; auto nf = Fraction(lens[i][id] + j + 1, j + 1); que.push({nf, {id, j + 1}}); } } if (prod >= lim || (ans *= prod) >= lim) { ans = lim; break; } } if (ans >= lim) puts("hel"); else printf("%lld\n", i64(ans)); } } int main() { auto beg = clock(); solve(); auto end = clock(); fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC); }