結果

問題 No.295 hel__world
ユーザー sugim48sugim48
提出日時 2015-10-23 23:53:33
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,531 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 82,760 KB
実行使用メモリ 203,364 KB
最終ジャッジ日時 2023-10-11 04:46:14
合計ジャッジ時間 13,681 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
		}
	}
	for (;;) {
		ll n, k; cin >> n >> k;
		cout << c(n, k, C) << endl;
	}
	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];
		ans = mul(ans, c(ma + a[k], ma, C));
	}
	if (ans == 0 || ans >= UNKO) cout << "hel" << endl;
	else cout << ans << endl;
}
0