結果

問題 No.3046 yukicoderの過去問
ユーザー risujirohrisujiroh
提出日時 2019-04-02 03:07:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,660 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 2,482 ms
コンパイル使用メモリ 179,864 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 07:59:48
合計ジャッジ時間 11,274 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1,581 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1,582 ms
4,380 KB
testcase_06 AC 1,660 ms
4,380 KB
testcase_07 AC 1,621 ms
4,376 KB
testcase_08 AC 1,616 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
int read_int(){int c,r;while((c=getchar())<48);r=c-48;while((c=getchar())>47)r=r*10+c-48;return r;}
void write_int(int x){int b[10],*p=b;do*p++=48+x%10,x/=10;while(x);do putchar(*--p);while(p>b);}

constexpr int mod = 1e9 + 7;

constexpr int N = 1e5;
int dp[N + 1], f[N + 1];

int main() {
  int k = read_int();
  int n = read_int();
  for (int i = 0; i < n; ++i) {
    f[read_int()] = 1;
  }
  dp[0] = 1;
  for (int i = 0; i < k; ++i) {
    const int c = dp[i];
    for (int x = 0; i + x <= k; ++x) {
      dp[i + x] += f[x] * c;
      dp[i + x] -= (dp[i + x] >= mod) * mod;
    }
  }
  cout << dp[k] << '\n';
}
0