Submission #5075905
Source Code Expand
#include <stdio.h>
int exceedhalf(int a[], int rlimit, int n)
{
int dp[301][50000] = { };
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < rlimit + 1; j++) {
if (j < a[i]) {
dp[i + 1][j] = (2 * dp[i][j] % 998244353 + dp[i][0]) % 998244353;
} else {
dp[i + 1][j] = (2 * dp[i][j] % 998244353 + dp[i][j - a[i]]) % 998244353;
}
}
}
return dp[n][rlimit];
}
int exactlyhalf(int a[], int rest, int n)
{
int dp[301][50000] = { };
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < rest + 1; j++) {
if (j >= a[i]) {
dp[i + 1][j] = (dp[i][j] + dp[i][j - a[i]]) % 998244353;
} else {
dp[i + 1][j] = dp[i][j];
}
}
}
return dp[n][rest];
}
int main()
{
int n, a[300], sum = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
int limit = (sum + 1) / 2;
int total = 1;
for (int i = 0; i < n; i++) {
total += 2 * total % 998244353;
total %= 998244353;
}
for (int i = 0; i < 3; i++) {
total -= exceedhalf(a, limit, n);
if (total < 0) total += 998244353;
total %= 998244353;
}
if (sum % 2 == 0) {
for (int i = 0; i < 3; i++) {
total += exactlyhalf(a, sum / 2, n);
total %= 998244353;
}
}
printf("%d\n", total);
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Three Colors |
| User | Trineutron |
| Language | C (GCC 5.4.1) |
| Score | 600 |
| Code Size | 1409 Byte |
| Status | AC |
| Exec Time | 108 ms |
| Memory | 59008 KiB |
Compile Error
./Main.c: In function ‘main’:
./Main.c:38:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.c:40:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
^
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 600 / 600 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s1.txt, s2.txt, s3.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, s1.txt, s2.txt, s3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 42 ms | 59008 KiB |
| 02.txt | AC | 68 ms | 59008 KiB |
| 03.txt | AC | 68 ms | 59008 KiB |
| 04.txt | AC | 44 ms | 59008 KiB |
| 05.txt | AC | 28 ms | 59008 KiB |
| 06.txt | AC | 19 ms | 59008 KiB |
| 07.txt | AC | 19 ms | 59008 KiB |
| 08.txt | AC | 20 ms | 59008 KiB |
| 09.txt | AC | 18 ms | 59008 KiB |
| 10.txt | AC | 19 ms | 59008 KiB |
| 11.txt | AC | 67 ms | 59008 KiB |
| 12.txt | AC | 68 ms | 59008 KiB |
| 13.txt | AC | 18 ms | 59008 KiB |
| 14.txt | AC | 107 ms | 59008 KiB |
| 15.txt | AC | 68 ms | 59008 KiB |
| 16.txt | AC | 108 ms | 59008 KiB |
| 17.txt | AC | 19 ms | 59008 KiB |
| 18.txt | AC | 27 ms | 59008 KiB |
| 19.txt | AC | 19 ms | 59008 KiB |
| 20.txt | AC | 28 ms | 59008 KiB |
| 21.txt | AC | 19 ms | 59008 KiB |
| 22.txt | AC | 27 ms | 59008 KiB |
| 23.txt | AC | 26 ms | 59008 KiB |
| 24.txt | AC | 26 ms | 59008 KiB |
| s1.txt | AC | 18 ms | 59008 KiB |
| s2.txt | AC | 26 ms | 59008 KiB |
| s3.txt | AC | 18 ms | 59008 KiB |