結果

問題 No.1929 Exponential Sequence
ユーザー 👑 ygussanyygussany
提出日時 2022-05-06 22:28:37
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 636 ms / 2,000 ms
コード長 1,442 bytes
コンパイル時間 1,049 ms
コンパイル使用メモリ 30,208 KB
実行使用メモリ 61,328 KB
最終ジャッジ日時 2023-10-12 04:22:08
合計ジャッジ時間 5,644 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,348 KB
testcase_01 AC 0 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 630 ms
61,236 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 0 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 0 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 39 ms
37,128 KB
testcase_16 AC 4 ms
4,352 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 0 ms
4,352 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 608 ms
59,384 KB
testcase_22 AC 295 ms
51,152 KB
testcase_23 AC 579 ms
59,272 KB
testcase_24 AC 144 ms
43,356 KB
testcase_25 AC 564 ms
59,176 KB
testcase_26 AC 636 ms
61,328 KB
testcase_27 AC 0 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:35:11: 警告: 組み込み関数 ‘pow’ が非関数として宣言されました [-Wbuiltin-declaration-mismatch]
   35 | long long pow[31];
      |           ^~~

ソースコード

diff #

#include <stdio.h>

void merge_sort(int n, int x[])
{
	static int y[10] = {};
	if (n <= 1) return;
	merge_sort(n / 2, &(x[0]));
	merge_sort((n + 1) / 2, &(x[n/2]));
	
	int i, p, q;
	for (i = 0, p = 0, q = n / 2; i < n; i++) {
		if (p >= n / 2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

typedef struct List {
	struct List *next;
	int n, S;
	long long ans;
} list;

#define HASH 5000011
const int H_Mod = HASH;
int hn = 0;
list *hash[HASH] = {}, hd[20000000];

int hash_func(int n, int S)
{
	return (((long long)n << 30) + S) % H_Mod;
}

long long pow[31];

long long recursion(int n, int a[], int S)
{
	if (n == 0) return 1;
	
	int i;
	if (n == 1) {
		for (i = 1; pow[i] <= S; i++);
		return i - 1;
	}

	int h = hash_func(n, S);
	list *hp;
	for (hp = hash[h]; hp != NULL; hp = hp->next) if (hp->n == n && hp->S == S) break;
	if (hp != NULL) return hp->ans;
	
	hp = &(hd[hn++]);
	hp->n = n;
	hp->S = S;
	hp->ans = 0;
	hp->next = hash[h];
	hash[h] = hp;
	
	long long x;
	for (i = 1, x = a[n]; x <= S; i++, x *= a[n]) hp->ans += recursion(n - 1, a, S - x);
	return hp->ans;
}

int main()
{
	int i, n, S, a[10];
	scanf("%d %d", &n, &S);
	for (i = 1; i <= n; i++) scanf("%d", &(a[i]));
	merge_sort(n, &(a[1]));
	
	for (i = 1, pow[0] = 1; pow[i-1] <= S; i++) pow[i] = pow[i-1] * a[1];
	printf("%lld\n", recursion(n, a, S));
	fflush(stdout);
	return 0;
}
0