結果

問題 No.1645 AB's abs
ユーザー bal4ubal4u
提出日時 2021-08-14 08:10:15
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 936 bytes
コンパイル時間 495 ms
コンパイル使用メモリ 31,872 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 05:25:03
合計ジャッジ時間 1,299 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:12:28: note: in expansion of macro 'gc'
   12 |         int n = 0; int c = gc();
      |                            ^~

ソースコード

diff #

// yuki 1645 AB's abs
// 2021.8.13

#include <stdio.h>
#include <string.h>

typedef long long ll;
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

const int mod = 998244353;
inline static int ABS(int a) { return a >= 0? a: -a; }
inline static void add_mod(int *a, int b) { *a = (*a + b) % mod; }
int dp[2][10010]; int N;

int main()
{
	int i, j, k0, k1;

	N = in();;
	dp[0][0] = 1, k0 = 0, k1 = 1;
	int s = 0; for (i = 0; i < N; ++i) {
		int A = in();
		memset(dp[k1], 0, sizeof(dp[0]));
		for (j = 0; j <= s; ++j) if (dp[k0][j]) {
			add_mod(&dp[k1][j+A], dp[k0][j]);
			add_mod(&dp[k1][ABS(j-A)], dp[k0][j]);
		}
		k1 = k0, k0 = !k0;
		s += A;
	}
	int ans = 0;
	for (j = 0; j <= s; ++j) if (dp[k0][j]) {
		add_mod(&ans, (ll)j * dp[k0][j] % mod);
	}
	printf("%d\n", ans);
	return 0;
}
0