提出 #32446711


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5000005, mod = 998244353;
int n, a, b, c;
int fac[N], inv[N];
int ans;

int qpow(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;
		y >>= 1;
	}
	return res;
}

void init(int maxn) {
	fac[0] = 1;
	for (int i = 1; i <= maxn; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
	inv[maxn] = qpow(fac[maxn], mod - 2);
	for (int i = maxn - 1; ~i; --i) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
}

int C(int n, int m) {
	if (n < 0 || m < 0 || n < m) return 0;
	return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}

void add(int &a, int b) {
	a += b;
	if (a >= mod) a -= mod;
	if (a < 0) a += mod;
}

void mul(int &a, int b) {
	a = 1ll * a * b % mod;
}

int main() {
	scanf("%d%d%d%d", &n, &a, &b, &c);
	init(5000000);
	int x = 1, y = 1, z = 1, f;
	if (n & 1) f = -1; else f = 1;
	for (int i = 0; i <= n; ++i) {
		int tmp = C(n, i);
		mul(tmp, x), mul(tmp, y), mul(tmp, z);
		mul(x, 2), add(x, -C(i, a));
		mul(y, 2), add(y, -C(i, b));
		mul(z, 2), add(z, -C(i, c));
		add(ans, tmp * f);
		f *= -1;
	}
	printf("%d", ans);
	return 0;
}

提出情報

提出日時
問題 G - Gardens
ユーザ Kobe303
言語 C++ (GCC 9.2.1)
得点 600
コード長 1219 Byte
結果 AC
実行時間 211 ms
メモリ 42876 KiB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:42:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   42 |  scanf("%d%d%d%d", &n, &a, &b, &c);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 5
AC × 38
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 01_small_09.txt, 01_small_10.txt, 01_small_11.txt, 02_max_00.txt, 02_max_01.txt, 02_max_02.txt, 03_n_max_00.txt, 03_n_max_01.txt, 03_n_max_02.txt, 04_random_00.txt, 04_random_01.txt, 04_random_02.txt, 04_random_03.txt, 04_random_04.txt, 05_zero_00.txt, 05_zero_01.txt, 05_zero_02.txt, 05_zero_03.txt, 06_same_00.txt, 06_same_01.txt, 06_same_02.txt, 07_multinomial_00.txt, 07_multinomial_01.txt, 07_multinomial_02.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 78 ms 42748 KiB
00_sample_01.txt AC 73 ms 42748 KiB
00_sample_02.txt AC 72 ms 42876 KiB
00_sample_03.txt AC 74 ms 42676 KiB
00_sample_04.txt AC 211 ms 42868 KiB
01_small_00.txt AC 69 ms 42764 KiB
01_small_01.txt AC 69 ms 42732 KiB
01_small_02.txt AC 72 ms 42732 KiB
01_small_03.txt AC 72 ms 42804 KiB
01_small_04.txt AC 76 ms 42876 KiB
01_small_05.txt AC 73 ms 42776 KiB
01_small_06.txt AC 71 ms 42660 KiB
01_small_07.txt AC 73 ms 42816 KiB
01_small_08.txt AC 68 ms 42616 KiB
01_small_09.txt AC 70 ms 42752 KiB
01_small_10.txt AC 72 ms 42876 KiB
01_small_11.txt AC 71 ms 42768 KiB
02_max_00.txt AC 163 ms 42764 KiB
02_max_01.txt AC 165 ms 42876 KiB
02_max_02.txt AC 160 ms 42624 KiB
03_n_max_00.txt AC 211 ms 42624 KiB
03_n_max_01.txt AC 187 ms 42756 KiB
03_n_max_02.txt AC 194 ms 42676 KiB
04_random_00.txt AC 155 ms 42672 KiB
04_random_01.txt AC 142 ms 42820 KiB
04_random_02.txt AC 150 ms 42732 KiB
04_random_03.txt AC 162 ms 42768 KiB
04_random_04.txt AC 192 ms 42876 KiB
05_zero_00.txt AC 83 ms 42748 KiB
05_zero_01.txt AC 205 ms 42772 KiB
05_zero_02.txt AC 138 ms 42768 KiB
05_zero_03.txt AC 198 ms 42768 KiB
06_same_00.txt AC 156 ms 42616 KiB
06_same_01.txt AC 133 ms 42772 KiB
06_same_02.txt AC 141 ms 42620 KiB
07_multinomial_00.txt AC 141 ms 42732 KiB
07_multinomial_01.txt AC 183 ms 42876 KiB
07_multinomial_02.txt AC 152 ms 42756 KiB