結果

問題 No.1840 Random Painting
ユーザー 👑 ygussanyygussany
提出日時 2022-01-22 20:32:43
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,156 ms / 2,000 ms
コード長 823 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 30,864 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-09 23:35:00
合計ジャッジ時間 14,171 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 0 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 0 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 39 ms
4,380 KB
testcase_10 AC 459 ms
4,384 KB
testcase_11 AC 848 ms
4,384 KB
testcase_12 AC 430 ms
4,384 KB
testcase_13 AC 18 ms
4,380 KB
testcase_14 AC 1,114 ms
4,384 KB
testcase_15 AC 771 ms
4,380 KB
testcase_16 AC 903 ms
4,384 KB
testcase_17 AC 269 ms
4,380 KB
testcase_18 AC 1,154 ms
4,380 KB
testcase_19 AC 1,150 ms
4,380 KB
testcase_20 AC 1,151 ms
4,380 KB
testcase_21 AC 1,150 ms
4,380 KB
testcase_22 AC 1,156 ms
4,380 KB
testcase_23 AC 1,150 ms
4,380 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 6 ms
4,384 KB
testcase_28 AC 6 ms
4,388 KB
testcase_29 AC 6 ms
4,384 KB
testcase_30 AC 0 ms
4,384 KB
testcase_31 AC 0 ms
4,384 KB
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 0 ms
4,384 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const long long Mod = 1000000000000000003, inv = 666666666666666669;

__int128 div_mod(__int128 x, __int128 y, __int128 z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

__int128 prob(int l, int k)
{
	return div_mod(l - k + 1, l + 1, Mod);
}

__int128 expect(int l, int k)
{
	return (__int128)k * (2 * l - k + 2) * inv % Mod;
}

int main()
{
	int N;
	char s[1000001];
	scanf("%d", &N);
	scanf("%s", s);
	
	int h, i, j, k, l;
	__int128 ans = 0;
	for (h = N - 1; s[h] != '0'; h--);
	for (i = 0, j = 1; j <= h; j++) {
		if (s[j] != '0') continue;
		
		l = j - (h - N) - 1;
		k = j - i;
		ans += (prob(l, k) * expect(l, k) + prob(l, l - k + 1) * expect(l, l - k + 1)) % Mod;
		
		i = j;
	}
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}
0