結果

問題 No.1956 猫の額
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-05-23 22:34:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,673 bytes
コンパイル時間 1,738 ms
コンパイル使用メモリ 116,828 KB
実行使用メモリ 13,748 KB
最終ジャッジ日時 2023-10-20 18:28:18
合計ジャッジ時間 5,051 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 18 ms
13,748 KB
testcase_02 WA -
testcase_03 AC 20 ms
13,748 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 24 ms
13,748 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 64 ms
13,444 KB
testcase_12 WA -
testcase_13 AC 8 ms
13,256 KB
testcase_14 WA -
testcase_15 AC 18 ms
13,728 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


unsigned M;
int N, K;
int A[110];

int S;

short dp[46][100'010];
short anss[3][100'010];
unsigned ans[100'010];

/*
m0 = NextPrime[2^15, -1]
m1 = NextPrime[2^15, -2]
m2 = NextPrime[2^15, -3]
m1 m2 PowerMod[m1 m2, -1, m0]
m2 m0 PowerMod[m2 m0, -1, m1]
m0 m1 PowerMod[m0 m1, -1, m2]
Clear[m0, m1, m2]
*/
constexpr short MOS[3] = {32749, 32719, 32717};
constexpr unsigned long long PROD = 1ULL * MOS[0] * MOS[1] * MOS[2];
constexpr unsigned long long COEFS[3] = {26694248621051ULL, 11101283430913ULL, 32317949769491ULL};
unsigned calc(unsigned a0, unsigned a1, unsigned a2) {
  return (COEFS[0] * a0 + COEFS[1] * a1 + COEFS[2] * a2) % PROD % M;
}
template <int H> void add(short &t, short f) {
  t += f;
  t = (t >= MOS[H]) ? (t - MOS[H]) : t;
}
template <int H> void solve() {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    for (int k = K; --k >= 0; ) {
      for (int x = 0; x + A[i] <= S; ++x) {
        add<H>(dp[k + 1][x + A[i]], dp[k][x]);
      }
    }
  }
  for (int x = 0; x <= S; ++x) {
    anss[H][x] = dp[K][x];
  }
}

int main() {
  for (; ~scanf("%d%u%d", &N, &M, &K); ) {
    for (int i = 0; i < N; ++i) {
      scanf("%d", &A[i]);
    }
    sort(A, A + N);
    
    S = 0;
    for (int i = 0; i < N; ++i) {
      S += A[i];
    }
    
    const bool rev = chmin(K, N - K);
    solve<0>();
    solve<1>();
    solve<2>();
    for (int x = 0; x <= S; ++x) {
      ans[x] = calc(anss[0][x], anss[1][x], anss[2][x]);
    }
    
    if (rev) {
      reverse(ans, ans + (S + 1));
    }
    for (int x = 1; x <= S; ++x) {
      if (x > 1) printf(" ");
      printf("%u", ans[x]);
    }
    puts("");
  }
  return 0;
}
0