結果

問題 No.269 見栄っ張りの募金活動
ユーザー Kenta NakajimaKenta Nakajima
提出日時 2020-04-29 12:18:55
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,248 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 29,580 KB
実行使用メモリ 17,540 KB
最終ジャッジ日時 2023-08-18 18:04:36
合計ジャッジ時間 1,796 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 16 ms
17,536 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 16 ms
17,524 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 7 ms
10,100 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 16 ms
17,412 KB
testcase_12 AC 6 ms
8,004 KB
testcase_13 AC 7 ms
10,104 KB
testcase_14 AC 17 ms
17,540 KB
testcase_15 AC 9 ms
11,068 KB
testcase_16 AC 8 ms
9,972 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 12 ms
16,168 KB
testcase_19 AC 8 ms
9,972 KB
testcase_20 AC 7 ms
7,788 KB
testcase_21 AC 15 ms
15,004 KB
testcase_22 AC 4 ms
6,088 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 10 ms
10,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 30


int get_int3(int *a1, int *a2, int *a3) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d", a1, a2, a3);
#else
#error
#endif
  return 0;
}

#define SUM_MAX 20000
#define NUM_MAX 100
#define DIVISOR 1000000007

int main(void) {
    int num, sum, step;
    static uint64_t dp[SUM_MAX+1][NUM_MAX];

    get_int3(&num, &sum, &step);

    // calc num-1 split in sum-**
    dp[0][0] = 1;
    int s, n;
    for(s = 0; s <= sum; s++) {
        for(n = 1; n < num; n++) {
            dp[s][n] = dp[s][n-1];
            if(s>=n) dp[s][n] = (dp[s][n] + dp[s-n][n]) % DIVISOR;
        }
    }

    uint64_t ans = 0;
    int base;
    for(base = 0; base <= sum; base++) {
        int base_sum = num * base + step * num * (num-1)/2;
        if(base_sum > sum) break;
        int rem = sum - base_sum;
#ifdef DEBUG
        printf("[%d] dp[%d][%d] = %llu\n", base_sum, rem ,num-1, dp[rem][num-1]);
#endif
        ans = (ans + dp[rem][num-1]) % DIVISOR;
    }
    printf("%d\n", (int)ans);

    return 0;
}
0