AtCoder Grand Contest 019

Submission #3786048

Source codeソースコード

#include<cstdio>
#include<algorithm>

class Solution{
private :
	static const int maxn = 5e5 + 7;
	static const int maxm = 5e5;
	static const int mod = 998244353;
	
	int n, m, frac[maxn * 2], invf[maxn * 2], ans, tot, sum;
	
	void Init(int x) {
		frac[0] = 1;
		for (register int i = 1; i <= x; i++) {
			frac[i] = 1ll * frac[i - 1] * i % mod;
		}
		invf[x] = Kasumi(frac[x], mod - 2);
		for (register int i = x - 1; i >= 0; i--) {
			invf[i] = 1ll * invf[i + 1] * (i + 1) % mod;
		}
	}
	
	int Kasumi(int a, int b) {
		int res = 1, base = a;
		for (; b; b >>= 1) {
			if (b & 1) {
				res = 1ll * res * base % mod;
			}
			base = 1ll * base * base % mod;
		}
		return res;
	}
	
	int Inv(int x) {
		return Kasumi(x, mod - 2);
	}
	
	int A(int n, int m) {
		if (n == m || !m) {
			return frac[n];
		}
		return 1ll * frac[n] * invf[m] % mod;
	}
	
	int C(int n, int m) {
		if (n == m || !m) {
			return 1;
		}
		return 1ll * A(n, m) * invf[n - m] % mod;
	}
	
public :
	Solution() {
		Get();
		Solve();
	}
	
	void Get() {
		scanf("%d %d", &n, &m);
	}
	
	void Solve() {
        Init(n + m);
        if (n > m) {
            std :: swap(n, m);
        }
        for (register int i = 1; i <= n; i++) {
            tot += 1ll * C(2 * i, i) * C(n - i + m - i, n - i) % mod;
            if (tot >= mod) {
                tot -= mod;
            }
        }
        sum = C(n + m, n);
        printf("%lld\n", (1ll * tot * Inv(sum) % mod * Inv(2) + m) % mod);
	}
};
Solution sol;

int main() {}

Submission

Task問題 F - Yes or No
User nameユーザ名 luogu_bot2
Created time投稿日時
Language言語 C++ (GCC 5.4.1)
Status状態 AC
Score得点 2000
Source lengthソースコード長 1483 Byte
File nameファイル名
Exec time実行時間 23 ms
Memory usageメモリ使用量 7936 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In member function ‘void Solution::Get()’:
./Main.cpp:59:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,sample_05.txt
Partial 1500 / 1500 sample_01.txt,sample_02.txt,sample_04.txt,subtask_1_01.txt,subtask_1_02.txt,subtask_1_03.txt,subtask_1_04.txt,subtask_1_05.txt,subtask_1_06.txt,subtask_1_07.txt,subtask_1_08.txt,subtask_1_09.txt,subtask_1_10.txt,subtask_1_11.txt,subtask_1_12.txt,subtask_1_13.txt,subtask_1_14.txt,subtask_1_15.txt,subtask_1_16.txt,subtask_1_17.txt,subtask_1_18.txt,subtask_1_19.txt,subtask_1_20.txt,subtask_1_21.txt,subtask_1_22.txt,subtask_1_23.txt,subtask_1_24.txt,subtask_1_25.txt
All 500 / 500 sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,sample_05.txt,sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,sample_05.txt,subtask_1_01.txt,subtask_1_02.txt,subtask_1_03.txt,subtask_1_04.txt,subtask_1_05.txt,subtask_1_06.txt,subtask_1_07.txt,subtask_1_08.txt,subtask_1_09.txt,subtask_1_10.txt,subtask_1_11.txt,subtask_1_12.txt,subtask_1_13.txt,subtask_1_14.txt,subtask_1_15.txt,subtask_1_16.txt,subtask_1_17.txt,subtask_1_18.txt,subtask_1_19.txt,subtask_1_20.txt,subtask_1_21.txt,subtask_1_22.txt,subtask_1_23.txt,subtask_1_24.txt,subtask_1_25.txt,subtask_2_01.txt,subtask_2_02.txt,subtask_2_03.txt,subtask_2_04.txt,subtask_2_05.txt,subtask_2_06.txt,subtask_2_07.txt,subtask_2_08.txt,subtask_2_09.txt,subtask_2_10.txt,subtask_2_11.txt,subtask_2_12.txt,subtask_2_13.txt,subtask_2_14.txt,subtask_2_15.txt,subtask_2_16.txt,subtask_2_17.txt,subtask_2_18.txt,subtask_2_19.txt,subtask_2_20.txt,subtask_2_21.txt,subtask_2_22.txt,subtask_2_23.txt,subtask_2_24.txt,subtask_2_25.txt,subtask_2_26.txt,subtask_2_27.txt,subtask_2_28.txt,subtask_2_29.txt,subtask_2_30.txt,subtask_2_31.txt,subtask_2_32.txt,subtask_2_33.txt,subtask_2_34.txt,subtask_2_35.txt,subtask_2_36.txt,subtask_2_37.txt,subtask_2_38.txt,subtask_2_39.txt,subtask_2_40.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 1 ms 2176 KB
sample_02.txt AC 1 ms 2176 KB
sample_03.txt AC 1 ms 2176 KB
sample_04.txt AC 1 ms 2176 KB
sample_05.txt AC 1 ms 2176 KB
subtask_1_01.txt AC 1 ms 2176 KB
subtask_1_02.txt AC 1 ms 2176 KB
subtask_1_03.txt AC 1 ms 2176 KB
subtask_1_04.txt AC 1 ms 2176 KB
subtask_1_05.txt AC 1 ms 2176 KB
subtask_1_06.txt AC 1 ms 2176 KB
subtask_1_07.txt AC 1 ms 2176 KB
subtask_1_08.txt AC 1 ms 2176 KB
subtask_1_09.txt AC 1 ms 2176 KB
subtask_1_10.txt AC 1 ms 2176 KB
subtask_1_11.txt AC 1 ms 2176 KB
subtask_1_12.txt AC 1 ms 2176 KB
subtask_1_13.txt AC 1 ms 2304 KB
subtask_1_14.txt AC 3 ms 4480 KB
subtask_1_15.txt AC 6 ms 4992 KB
subtask_1_16.txt AC 6 ms 4992 KB
subtask_1_17.txt AC 6 ms 4992 KB
subtask_1_18.txt AC 6 ms 4992 KB
subtask_1_19.txt AC 6 ms 4992 KB
subtask_1_20.txt AC 6 ms 4992 KB
subtask_1_21.txt AC 6 ms 4992 KB
subtask_1_22.txt AC 6 ms 4992 KB
subtask_1_23.txt AC 6 ms 4992 KB
subtask_1_24.txt AC 5 ms 4992 KB
subtask_1_25.txt AC 5 ms 4992 KB
subtask_2_01.txt AC 1 ms 2176 KB
subtask_2_02.txt AC 1 ms 2176 KB
subtask_2_03.txt AC 1 ms 2176 KB
subtask_2_04.txt AC 23 ms 7936 KB
subtask_2_05.txt AC 23 ms 7936 KB
subtask_2_06.txt AC 23 ms 7936 KB
subtask_2_07.txt AC 23 ms 7936 KB
subtask_2_08.txt AC 23 ms 7936 KB
subtask_2_09.txt AC 23 ms 7936 KB
subtask_2_10.txt AC 23 ms 7936 KB
subtask_2_11.txt AC 23 ms 7936 KB
subtask_2_12.txt AC 23 ms 7936 KB
subtask_2_13.txt AC 23 ms 7936 KB
subtask_2_14.txt AC 23 ms 7936 KB
subtask_2_15.txt AC 23 ms 7936 KB
subtask_2_16.txt AC 23 ms 7936 KB
subtask_2_17.txt AC 22 ms 7936 KB
subtask_2_18.txt AC 21 ms 7680 KB
subtask_2_19.txt AC 18 ms 7168 KB
subtask_2_20.txt AC 8 ms 6272 KB
subtask_2_21.txt AC 8 ms 6272 KB
subtask_2_22.txt AC 8 ms 6272 KB
subtask_2_23.txt AC 8 ms 6272 KB
subtask_2_24.txt AC 8 ms 6272 KB
subtask_2_25.txt AC 8 ms 6272 KB
subtask_2_26.txt AC 8 ms 6272 KB
subtask_2_27.txt AC 8 ms 6272 KB
subtask_2_28.txt AC 9 ms 6272 KB
subtask_2_29.txt AC 9 ms 6272 KB
subtask_2_30.txt AC 11 ms 6400 KB
subtask_2_31.txt AC 14 ms 6784 KB
subtask_2_32.txt AC 23 ms 7936 KB
subtask_2_33.txt AC 23 ms 7936 KB
subtask_2_34.txt AC 23 ms 7936 KB
subtask_2_35.txt AC 23 ms 7936 KB
subtask_2_36.txt AC 22 ms 7936 KB
subtask_2_37.txt AC 11 ms 6144 KB
subtask_2_38.txt AC 8 ms 5888 KB
subtask_2_39.txt AC 22 ms 7808 KB
subtask_2_40.txt AC 11 ms 6400 KB