結果
| 問題 |
No.603 hel__world (2)
|
| コンテスト | |
| ユーザー |
kuwa
|
| 提出日時 | 2017-12-03 03:12:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,085 bytes |
| コンパイル時間 | 1,283 ms |
| コンパイル使用メモリ | 107,580 KB |
| 実行使用メモリ | 21,768 KB |
| 最終ジャッジ日時 | 2024-11-28 08:11:02 |
| 合計ジャッジ時間 | 39,514 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 4 TLE * 9 |
ソースコード
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1000003;
struct R {
ll n, k;
R () {}
R (ll n, ll k) : n(n), k(k) { }
bool operator < (const R& o) const {
bool r1 = (n + 1) * (o.n + 1 - o.k) == (o.n + 1) * (n + 1 - k);
return r1 ? k < o.k : (n + 1) * (o.n + 1 - o.k) < (o.n + 1) * (n + 1 - k);
}
};
ll modpow(ll a, int b) {
if (b == 0) return 1LL;
if (b == 1) return a;
if (b % 2 == 1) return a * modpow(a, b-1);
ll h = modpow(a, b/2);
return h * h % MOD;
}
ll modinv(ll a) {
return modpow(a, MOD-2);
}
int main() {
cin.tie(0); ios::sync_with_stdio(false);
ll s[26];
string T; for (int j = 0; j < 26; ++j) {
cin >> s[j];
}
cin >> T;
int co[26];
fill(co, co+26, 0);
for (const char ch : T) {
++co[ch-'a'];
}
for (int j = 0; j < 26; ++j) {
if (co[j] > s[j]) {
cout << 0 << endl;
return 0;
}
}
vector<int> cu[26];
char prev = T[0]; int count = 0;
for (const char ch : T) {
if (prev == ch) {
++count;
} else {
cu[prev-'a'].push_back(count);
count = 1;
}
prev = ch;
}
cu[prev-'a'].push_back(count);
ll ans = 1LL;
for (int j = 0; j < 26; ++j) {
priority_queue<R> pq;
for (int v : cu[j]) {
pq.emplace(v, v);
}
if (pq.empty()) continue;
for (int k = 0; k < s[j] - co[j]; ++k) {
R r = pq.top(); pq.pop();
ans = ans * (r.n + 1) % MOD * modinv(r.n + 1 - r.k) % MOD;
pq.emplace(r.n+1, r.k);
}
}
cout << ans << endl;
return 0;
}
kuwa