提出 #25500654
ソースコード 拡げる
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
template <typename T>
void read (T &x) {
x = 0; T f = 1;
char ch = getchar ();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar ();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + ch - '0';
ch = getchar ();
}
x *= f;
}
const int Maxn = 5000;
const LL Mod = 998244353;
LL dp[Maxn + 5], pre[Maxn + 5];
int n;
struct Node {
int x, y;
}a[Maxn + 5];
bool cmp (Node x, Node y) {
return x.x < y.x;
}
int main () {
read (n);
for (int i = 1; i <= n; i++) {
read (a[i].x);
}
for (int i = 1; i <= n; i++) {
read (a[i].y);
}
sort (a + 1, a + 1 + n, cmp);
dp[0] = 1; for (int i = 0; i <= Maxn; i++) pre[i] = 1;
LL ans = 0;
for (int i = 1; i <= n; i++) {
if (a[i].x >= a[i].y)
ans = (ans + pre[a[i].x - a[i].y]) % Mod;
for (int j = Maxn; j >= a[i].y; j--) {
dp[j] = (dp[j] + dp[j - a[i].y]) % Mod;
}
for (int j = 0; j <= Maxn; j++) {
if (j == 0) pre[j] = dp[j];
else pre[j] = (pre[j - 1] + dp[j]) % Mod;
}
// printf ("--------\n");
// printf ("i = %d\n", i);
// for (int j = 1; j <= 10; j++) {
// printf (" dp[%d] = %lld\n", j, dp[j]);
// }
}
printf ("%lld", ans);
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Max Sum Counting |
| ユーザ | C2022lihan |
| 言語 | C++ (Clang 10.0.0) |
| 得点 | 500 |
| コード長 | 1566 Byte |
| 結果 | AC |
| 実行時間 | 136 ms |
| メモリ | 3304 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt, example2.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 6 ms | 2976 KiB |
| 001.txt | AC | 126 ms | 3072 KiB |
| 002.txt | AC | 126 ms | 3236 KiB |
| 003.txt | AC | 124 ms | 2952 KiB |
| 004.txt | AC | 123 ms | 3204 KiB |
| 005.txt | AC | 65 ms | 3288 KiB |
| 006.txt | AC | 64 ms | 3124 KiB |
| 007.txt | AC | 100 ms | 2976 KiB |
| 008.txt | AC | 112 ms | 3140 KiB |
| 009.txt | AC | 132 ms | 3304 KiB |
| 010.txt | AC | 135 ms | 3072 KiB |
| 011.txt | AC | 132 ms | 2976 KiB |
| 012.txt | AC | 136 ms | 3020 KiB |
| 013.txt | AC | 135 ms | 3112 KiB |
| 014.txt | AC | 130 ms | 3020 KiB |
| 015.txt | AC | 134 ms | 3304 KiB |
| 016.txt | AC | 131 ms | 2952 KiB |
| 017.txt | AC | 135 ms | 3096 KiB |
| 018.txt | AC | 136 ms | 2988 KiB |
| 019.txt | AC | 132 ms | 2988 KiB |
| 020.txt | AC | 130 ms | 2948 KiB |
| 021.txt | AC | 134 ms | 3112 KiB |
| 022.txt | AC | 130 ms | 3096 KiB |
| 023.txt | AC | 131 ms | 2992 KiB |
| example0.txt | AC | 3 ms | 2972 KiB |
| example1.txt | AC | 2 ms | 2936 KiB |
| example2.txt | AC | 3 ms | 2976 KiB |