結果

問題 No.1956 猫の額
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-05-24 00:58:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,812 bytes
コンパイル時間 1,608 ms
コンパイル使用メモリ 119,832 KB
実行使用メモリ 13,576 KB
最終ジャッジ日時 2023-10-20 18:40:26
合計ジャッジ時間 4,448 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
13,576 KB
testcase_01 AC 15 ms
13,576 KB
testcase_02 AC 150 ms
13,576 KB
testcase_03 AC 17 ms
13,576 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 118 ms
13,496 KB
testcase_09 AC 21 ms
13,528 KB
testcase_10 AC 101 ms
13,460 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 7 ms
13,272 KB
testcase_14 WA -
testcase_15 AC 17 ms
13,560 KB
testcase_16 AC 133 ms
13,540 KB
testcase_17 AC 153 ms
13,576 KB
testcase_18 AC 149 ms
13,576 KB
testcase_19 AC 149 ms
13,576 KB
testcase_20 AC 145 ms
13,576 KB
権限があれば一括ダウンロードができます

ソースコード

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;
void Add(unsigned &t, unsigned f) {
  t += f;
  t = (t >= M) ? (t - M) : t;
}
void Sub(unsigned &t, unsigned f) {
  t -= f;
  t = (t >= M) ? (t + M) : t;
}

int N, K;
int A[110];

int L;
int S;

unsigned dp[24][100'010];
unsigned ans[100'010];

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);
    
    const bool rev = chmin(K, N - K);
    
    L = ((K + 1) + 1) / 2;
    S = 0;
    for (int i = 0; i < N; ++i) {
      S += A[i];
    }
    
    M *= 2;
    
    // +
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1 % M;
    for (int i = 0; i < N; ++i) {
      for (int k = L; --k >= 0; ) {
        for (int x = 0; x + A[i] <= S; ++x) {
          Add(dp[k + 1][x + A[i]], dp[k][x]);
        }
      }
      for (int x = 0; x <= S; ++x) {
        Add(dp[0][x], dp[L][x]);
      }
      memset(dp[L], 0, (S + 1) * sizeof(dp[L][0]));
    }
    memcpy(ans, dp[K % L], (S + 1) * sizeof(dp[L][0]));
    
    // -
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1 % M;
    for (int i = 0; i < N; ++i) {
      for (int k = L; --k >= 0; ) {
        for (int x = 0; x + A[i] <= S; ++x) {
          Add(dp[k + 1][x + A[i]], dp[k][x]);
        }
      }
      for (int x = 0; x <= S; ++x) {
        Sub(dp[0][x], dp[L][x]);
      }
      memset(dp[L], 0, (S + 1) * sizeof(dp[L][0]));
    }
    for (int x = 0; x <= S; ++x) {
      unsigned a = ans[x];
      if (K >= L) {
        Sub(a, dp[K - L][x]);
      } else {
        Add(a, dp[K][x]);
      }
      assert(a % 2 == 0);
      ans[x] = a / 2;
    }
    
    
    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