結果

問題 No.444 旨味の相乗効果
ユーザー akakimidoriakakimidori
提出日時 2019-06-13 11:11:19
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 86 ms / 2,500 ms
コード長 1,500 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 32,896 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 07:06:12
合計ジャッジ時間 1,812 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 86 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 45 ms
6,944 KB
testcase_13 AC 25 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 86 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 12 ms
6,940 KB
testcase_20 AC 83 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;
typedef int64_t i64;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

const i32 mod = 1000000007;

void matmul (i32 *c, i32 *a, i32 *b, i32 n) {
  static i32 *tmp = NULL;
  if (tmp == NULL) {
    tmp = ALLOC (n * n, i32);
  }
  memset (tmp, 0, sizeof (i32) * n * n);
  for (i32 i = 0; i < n; ++i) {
    for (i32 k = 0; k < n; ++k) {
      for (i32 j = 0; j < n; ++j) {
        tmp[i * n + j] = (tmp[i * n + j] + (i64) a[i * n + k] * b[k * n + j]) % mod;
      }
    }
  }
  memcpy (c, tmp, sizeof (i32) * n * n);
}

i32 mod_pow (i32 r, i64 n) {
  i64 t = 1;
  i64 s = r;
  while (n > 0) {
    if (n & 1) t = t * s % mod;
    s = s * s % mod;
    n >>= 1;
  }
  return t;
}

void run (void) {
  i32 n;
  i64 c;
  scanf ("%" SCNi32 "%" SCNi64, &n, &c);
  i32 *a = ALLOC (n, i32);
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  i32 *t = ALLOC (n * n, i32);
  i32 *s = ALLOC (n * n, i32);
  for (i32 i = 0; i < n; ++i) {
    t[i * n + i] = 1;
  }
  for (i32 i = 0; i < n; ++i) {
    for (i32 j = 0; j <= i; ++j) {
      s[i * n + j] = a[i];
    }
  }
  i64 x = c;
  while (x > 0) {
    if (x & 1) matmul (t, s, t, n);
    matmul (s, s, s, n);
    x >>= 1;
  }
  i64 ans = 0;
  for (i32 i = 0; i < n; ++i) {
    ans += mod + t[i * n] - mod_pow (a[i], c);
  }
  ans %= mod;
  printf ("%" PRIi64 "\n", ans);
}

int main (void) {
  run();
  return 0;
}
0