結果

問題 No.3328 岩井ツリーグラフ
コンテスト
ユーザー pengin_2000
提出日時 2025-11-01 15:28:58
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 27,468 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-11-01 15:29:01
合計ジャッジ時間 1,912 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:14:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         scanf("%lld", &x);
      |         ^~~~~~~~~~~~~~~~~
main.c:17:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |                 scanf("%lld", &y[i]);
      |                 ^~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
long long int modpow(long long int a, long long int n, long long int p)
{
	long long int res = 1;
	for (; n > 0; n /= 2, a = a * a % p)
		if (n % 2 > 0)
			res = res * a % p;
	return res;
}
long long int y[200005];
int main()
{
	long long int x;
	scanf("%lld", &x);
	long long int i;
	for (i = 0; i < x; i++)
		scanf("%lld", &y[i]);
	const long long int p = 998244353;
	long long int s = 1;
	for (i = 0; i < x; i++)
		s += y[i];
	s %= p;
	long long int ans = 0, inv = modpow(6, p - 2, p);
	for (i = 0; i < x; i++)
		ans = (ans + y[i] * (y[i] + 1) / 2 % p * s % p - y[i] * (y[i] + 1) % p * (2 * y[i] + 1) % p * inv % p + p) % p;
	printf("%lld\n", ans);
	return 0;
}
0