結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,888 KB
testcase_01 AC 1 ms
5,892 KB
testcase_02 AC 2 ms
5,936 KB
testcase_03 AC 1 ms
5,988 KB
testcase_04 AC 2 ms
5,988 KB
testcase_05 AC 2 ms
5,824 KB
testcase_06 AC 2 ms
5,892 KB
testcase_07 AC 2 ms
5,828 KB
testcase_08 AC 2 ms
5,832 KB
testcase_09 AC 1 ms
5,976 KB
testcase_10 AC 1 ms
5,992 KB
testcase_11 AC 2 ms
5,940 KB
testcase_12 AC 2 ms
5,952 KB
testcase_13 AC 2 ms
5,940 KB
testcase_14 AC 2 ms
6,004 KB
testcase_15 AC 1 ms
6,020 KB
testcase_16 AC 2 ms
5,944 KB
testcase_17 AC 2 ms
5,932 KB
testcase_18 AC 2 ms
5,948 KB
testcase_19 AC 1 ms
5,984 KB
testcase_20 AC 1 ms
6,016 KB
testcase_21 AC 2 ms
5,932 KB
testcase_22 AC 2 ms
5,836 KB
testcase_23 AC 2 ms
5,888 KB
testcase_24 AC 1 ms
5,888 KB
testcase_25 AC 24 ms
5,940 KB
testcase_26 AC 22 ms
5,936 KB
testcase_27 AC 30 ms
6,008 KB
testcase_28 AC 12 ms
5,936 KB
testcase_29 AC 30 ms
5,896 KB
testcase_30 AC 30 ms
5,828 KB
testcase_31 AC 19 ms
6,016 KB
testcase_32 AC 20 ms
6,004 KB
testcase_33 AC 18 ms
5,932 KB
testcase_34 AC 20 ms
5,952 KB
testcase_35 AC 17 ms
6,016 KB
testcase_36 AC 17 ms
5,940 KB
testcase_37 AC 5 ms
6,100 KB
testcase_38 AC 28 ms
5,832 KB
testcase_39 AC 29 ms
5,952 KB
testcase_40 AC 16 ms
5,932 KB
testcase_41 AC 17 ms
6,028 KB
testcase_42 AC 20 ms
5,892 KB
testcase_43 AC 29 ms
5,824 KB
testcase_44 AC 30 ms
5,996 KB
権限があれば一括ダウンロードができます

ソースコード

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++) {
		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]);
		a[i] %= FOD;
	}

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

	return 0;
}
0