結果

問題 No.295 hel__world
ユーザー sugim48sugim48
提出日時 2015-10-23 23:37:16
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,601 bytes
コンパイル時間 736 ms
コンパイル使用メモリ 86,116 KB
実行使用メモリ 304,472 KB
最終ジャッジ日時 2023-10-01 00:34:45
合計ジャッジ時間 16,700 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 232 ms
304,204 KB
testcase_01 AC 231 ms
303,868 KB
testcase_02 AC 236 ms
304,284 KB
testcase_03 AC 231 ms
304,280 KB
testcase_04 WA -
testcase_05 AC 215 ms
303,868 KB
testcase_06 WA -
testcase_07 AC 231 ms
304,276 KB
testcase_08 AC 230 ms
304,104 KB
testcase_09 AC 234 ms
304,156 KB
testcase_10 AC 235 ms
303,948 KB
testcase_11 AC 213 ms
303,912 KB
testcase_12 AC 214 ms
304,192 KB
testcase_13 AC 230 ms
304,244 KB
testcase_14 AC 230 ms
303,904 KB
testcase_15 AC 233 ms
304,312 KB
testcase_16 AC 233 ms
303,908 KB
testcase_17 AC 236 ms
304,136 KB
testcase_18 AC 231 ms
303,864 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 215 ms
303,952 KB
testcase_25 AC 233 ms
304,196 KB
testcase_26 AC 233 ms
303,904 KB
testcase_27 AC 233 ms
304,064 KB
testcase_28 AC 234 ms
304,228 KB
testcase_29 AC 233 ms
304,144 KB
testcase_30 AC 231 ms
304,144 KB
testcase_31 AC 233 ms
303,908 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 259 ms
304,140 KB
testcase_35 AC 233 ms
304,232 KB
testcase_36 AC 232 ms
303,872 KB
testcase_37 AC 215 ms
304,216 KB
testcase_38 AC 231 ms
303,908 KB
testcase_39 AC 230 ms
304,104 KB
testcase_40 AC 231 ms
304,068 KB
testcase_41 AC 231 ms
304,268 KB
testcase_42 AC 232 ms
304,216 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 232 ms
304,160 KB
testcase_47 AC 232 ms
304,288 KB
testcase_48 AC 231 ms
304,212 KB
testcase_49 AC 233 ms
303,944 KB
testcase_50 AC 230 ms
304,144 KB
testcase_51 AC 234 ms
304,068 KB
testcase_52 AC 231 ms
304,228 KB
testcase_53 AC 253 ms
304,204 KB
testcase_54 AC 249 ms
304,228 KB
testcase_55 WA -
testcase_56 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
ll UNKO = 1LL<<62;
double EPS = 1e-10;

ll gcd(ll a, ll b) {
	if (b == 0) return abs(a);
	else return gcd(b, a % b);
}

ll mul(ll x, ll y) {
	double xy = (double)x * y;
	if (xy > UNKO * 1.5) return 0;
	return x * y;
}

ll c(ll n, ll k, vector<vector<ll> >& C) {
	if (n < 5000) return C[n][k];
	if (k > n - k) k = n - k;
	if (k > 10) return 0;
	vector<ll> bunshi(k), bunbo(k);
	for (int i = 0; i < k; i++) {
		bunshi[i] = n - i;
		bunbo[i] = i + 1;
	}
	for (int i = 0; i < k; i++)
		for (int j = 0; j < k; j++) {
			ll d = gcd(bunshi[i], bunbo[j]);
			bunshi[i] /= d;
			bunbo[j] /= d;
		}
	ll ans = 1;
	for (int i = 0; i < k; i++)
		ans = mul(ans, bunshi[i]);
	return ans;
}

int main() {
	vector<vector<ll> > C(5000, vector<ll>(5000));
	for (int i = 0; i < 5000; i++) {
		C[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			if (!C[i - 1][j - 1] || (j <= i - 1 && !C[i - 1][j])) continue;
			C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
			if (C[i][j] >= UNKO) C[i][j] = 0;
		}
	}
	vector<ll> a(26);
	for (int k = 0; k < 26; k++)
		cin >> a[k];
	vector<int> sum(26);
	vector<vector<int> > b(26, vector<int>(1000001));
	string s; cin >> s;
	s.push_back(' ');
	char prev = 0;
	int x = 0;
	for (int i = 0; i < s.length(); i++) {
		char c = s[i];
		if (c == prev) x++;
		else {
			if (prev) {
				sum[prev - 'a'] += x;
				b[prev - 'a'][x]++;
			}
			prev = c;
			x = 1;
		}
	}
	for (int k = 0; k < 26; k++)
		if (a[k] < sum[k]) {
			cout << 0 << endl;
			return 0;
		}
	ll ans = 1;
	for (int k = 0; k < 26; k++) {
		int ma = 0;
		for (int x = 1; x <= 1000000; x++)
			if (b[k][x])
				ma = x;
		if (ma == 0) continue;
		// cout << (char)('a' + k) << ' ' << ma << endl;
		a[k] -= sum[k];
		int num = b[k][ma];
		for (int t = 0; t < a[k] % num; t++)
			ans = mul(ans, c(ma + a[k] / num + 1, ma, C));
		for (int t = 0; t < num - a[k] % num; t++)
			ans = mul(ans, c(ma + a[k] / num, ma, C));
	}
	if (ans == 0 || ans >= UNKO) cout << "hel" << endl;
	else cout << ans << endl;
}
0