結果

問題 No.2429 Happiest Tabehodai Ways
ユーザー polylogK
提出日時 2023-09-28 17:02:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,767 bytes
コンパイル時間 1,924 ms
コンパイル使用メモリ 197,112 KB
最終ジャッジ日時 2025-02-17 02:47:56
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 44
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:68:20: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘i64’ {aka ‘long int’} [-Wformat=]
   68 |     printf("%d\n%lld\n", dp[k], sum);
      |                 ~~~^            ~~~
      |                    |            |
      |                    |            i64 {aka long int}
      |                    long long int
      |                 %ld
main.cpp:26:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~
main.cpp:28:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |     for (auto& v : c) scanf("%d", &v);
      |                       ~~~~~^~~~~~~~~~
main.cpp:29:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |     for (auto& v : d) scanf("%d", &v);
      |                       ~~~~~^~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
#if defined(DONLINE_JUDGE)
#define NDEBUG
#elif defined(ONLINE_JUDGE)
#define NDEBUG
#endif
template <typename T>
std::vector<T> make_v(size_t a) {
return std::vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
int main() {
int n, k;
scanf("%d%d", &n, &k);
std::vector<int> c(n), d(n);
for (auto& v : c) scanf("%d", &v);
for (auto& v : d) scanf("%d", &v);
std::vector<int> max(1001, -1);
for (int i = 0; i < n; ++i) max[c[i]] = std::max(max[c[i]], d[i]);
std::vector<int> cnt(1001, 0);
for (int i = 0; i < n; ++i)
if (max[c[i]] == d[i]) cnt[c[i]] += 1;
std::vector<int> dp(k + 1);
for (int i = 0; i < k; ++i) {
for (int j = 0; j < 1001 and i + j <= k; ++j) {
if (max[j] == -1) continue;
dp[i + j] = std::max(dp[i + j], dp[i] + max[j]);
}
}
for (int i = 0; i < k; ++i) dp[i + 1] = std::max(dp[i + 1], dp[i]);
const int MOD = 998244353;
std::vector<i64> ans(k + 1);
ans[0] = 1;
for (int i = 0; i < k; ++i) {
for (int j = 0; j < 1001 and i + j <= k; ++j) {
if (cnt[j] == 0) continue;
if (dp[i] + max[j] + dp[k - (i + j)] != dp[k]) continue;
ans[i + j] += ans[i] * cnt[j] % MOD;
ans[i + j] %= MOD;
}
}
i64 sum = 0;
for (int i = 0; i <= k; ++i) {
if (dp[i] != dp[k]) continue;
sum = (sum + ans[i]) % MOD;
}
printf("%d\n%lld\n", dp[k], sum);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0