結果

問題 No.3084 ゲームブックにトライ!
ユーザー hirakich1000000007hirakich1000000007
提出日時 2021-03-29 00:32:33
言語 C
(gcc 12.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,492 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 30,400 KB
実行使用メモリ 6,076 KB
最終ジャッジ日時 2023-08-19 15:59:13
合計ジャッジ時間 2,201 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,888 KB
testcase_01 AC 1 ms
6,016 KB
testcase_02 AC 1 ms
5,832 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
5,924 KB
testcase_08 AC 1 ms
5,932 KB
testcase_09 WA -
testcase_10 AC 1 ms
5,952 KB
testcase_11 AC 2 ms
5,884 KB
testcase_12 WA -
testcase_13 AC 1 ms
6,032 KB
testcase_14 AC 1 ms
5,924 KB
testcase_15 AC 1 ms
5,952 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
5,956 KB
testcase_20 AC 2 ms
6,028 KB
testcase_21 AC 2 ms
5,896 KB
testcase_22 AC 1 ms
5,948 KB
testcase_23 AC 2 ms
6,036 KB
testcase_24 AC 2 ms
5,948 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 17 ms
6,024 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 15 ms
5,964 KB
testcase_37 AC 4 ms
6,076 KB
testcase_38 AC 26 ms
5,884 KB
testcase_39 AC 26 ms
5,920 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>


typedef uint64_t ull;
typedef  int64_t ll;

#ifdef __cplusplus

#include <vector>
using std::vector;
using std::pair;
#include <set>
using std::set;
#include <map>
using std::map;

typedef pair<ll, ll> P;

#endif

static const ll MOD = 1000000007LL;
static const ll FOD =  998244353LL;

ll n, k, m, q;
ll h, w, r;

char s[2019100];
ll a[201910], b[201910], c[201910];
ll qx[201910], qy[201910];

ll smin (ll a, ll b) {
	return (a < b) ? a : b;
}
ll smax (ll a, ll b) {
	return (a > b) ? a : b;
}

typedef struct {
	ll a;
	ll b;
} hwll;

int cmp (const void *left, const void *right) {
	ll l = *(ll*)left, r = *(ll*)right;

	if (l < r) return -1;
	if (l > r) return +1;
	return 0;
}

ll frac[5050505], invf[5050505];

ll bpow (ll x, ll y) {
	if (y == 0) return 1;
	return bpow(x * x % MOD, y / 2) * ((y % 2) ? x : 1) % MOD;
}
ll binv (ll x) {
	return bpow(x, MOD - 2);
}

ull solve () {
	ll i, j, ki;
	ull res = 0;

	qsort(a, n, sizeof(ll), cmp);


	b[0] = 0;
	for (i = 0; i < n; i++) {
		a[i] %= FOD;
		b[i + 1] = b[i] + a[i];
	}

	i = 0;
	j = n;
	for (i = 0; i < n; i++) {
		while (j > i && a[i] + a[j - 1] >= FOD) j--;
		if (j <= i) j = i + 1;

		ull item = (b[n] - b[i + 1]) + a[i] * (n - i - 1) - (n - j) * FOD;

		res += item;
	}

	return res;
}

int main(void){

	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}

	printf("%llu\n", solve());

	return 0;
}
0