結果
| 問題 |
No.1956 猫の額
|
| ユーザー |
|
| 提出日時 | 2022-05-24 01:56:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,131 bytes |
| コンパイル時間 | 2,187 ms |
| コンパイル使用メモリ | 143,268 KB |
| 最終ジャッジ日時 | 2025-01-29 14:56:59 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 7 RE * 11 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:61:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
61 | scanf("%d", &A[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#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, T;
unsigned dp[47][50'010];
unsigned ans0[50'010];
unsigned ans1[50'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);
L = ((N + 1) + 1) / 2;
assert(N < 2 * L);
S = 0;
for (int i = 0; i < N; ++i) {
S += A[i];
}
T = S / 2;
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; ) if (i >= k) {
for (int x = 0; x + A[i] <= T; ++x) {
Add(dp[k + 1][x + A[i]], dp[k][x]);
}
}
if (i + 1 >= L) {
for (int x = 0; x <= T; ++x) {
Add(dp[0][x], dp[L][x]);
}
memset(dp[L], 0, (T + 1) * sizeof(dp[0][0]));
}
}
memcpy(ans0, dp[K % L], (T + 1) * sizeof(dp[0][0]));
memcpy(ans1, dp[(N - K) % L], (T + 1) * sizeof(dp[0][0]));
// -
#ifdef LOCAL
memset(dp, 0, sizeof(dp));
#endif
dp[0][0] = 1 % M;
for (int i = 0; i < N; ++i) {
for (int k = L; --k >= 0; ) if (i >= k) {
for (int x = 0; x + A[i] <= T; ++x) {
Add(dp[k + 1][x + A[i]], dp[k][x]);
}
}
if (i + 1 >= L) {
for (int x = 0; x <= T; ++x) {
Sub(dp[0][x], dp[L][x]);
}
memset(dp[L], 0, (T + 1) * sizeof(dp[0][0]));
}
}
for (int x = 0; x <= T; ++x) {
unsigned a = ans0[x];
(K >= L) ? Sub(a, dp[K - L][x]) : Add(a, dp[K][x]);
assert(a % 2 == 0);
ans0[x] = a / 2;
}
for (int x = 0; x <= T; ++x) {
unsigned a = ans1[x];
(N - K >= L) ? Sub(a, dp[(N - K) - L][x]) : Add(a, dp[N - K][x]);
assert(a % 2 == 0);
ans1[x] = a / 2;
}
for (int x = 1; x <= S; ++x) {
if (x > 1) printf(" ");
printf("%u", (x <= T) ? ans0[x] : ans1[S - x]);
}
puts("");
}
return 0;
}