結果
問題 | No.1929 Exponential Sequence |
ユーザー |
👑 |
提出日時 | 2022-05-06 22:28:37 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 556 ms / 2,000 ms |
コード長 | 1,442 bytes |
コンパイル時間 | 294 ms |
コンパイル使用メモリ | 31,488 KB |
実行使用メモリ | 59,648 KB |
最終ジャッジ日時 | 2024-09-14 03:53:17 |
合計ジャッジ時間 | 4,262 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 24 |
コンパイルメッセージ
main.c:35:11: warning: built-in function 'pow' declared as non-function [-Wbuiltin-declaration-mismatch] 35 | long long pow[31]; | ^~~
ソースコード
#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 5000011const 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;}