結果
問題 | No.295 hel__world |
ユーザー |
![]() |
提出日時 | 2021-05-14 14:03:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,609 bytes |
コンパイル時間 | 2,336 ms |
コンパイル使用メモリ | 210,704 KB |
最終ジャッジ日時 | 2025-01-21 10:53:27 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 49 WA * 4 |
ソースコード
//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; } honzuki(); continue; } else if (cnt[i].size() == 2) { if (cnt[i][0] == 1 && cnt[i][1] == 1) { ans *= (cnt[i][0] + S[i]) / 2; honzuki(); ans *= cnt[i][0] + S[i] - (cnt[i][0] + 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; }