結果

問題 No.2008 Super Worker
ユーザー 👑 ygussanyygussany
提出日時 2022-07-15 21:41:47
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,008 bytes
コンパイル時間 1,371 ms
コンパイル使用メモリ 30,180 KB
実行使用メモリ 8,148 KB
最終ジャッジ日時 2023-09-10 01:05:31
合計ジャッジ時間 4,175 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 0 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 79 ms
8,016 KB
testcase_24 AC 79 ms
8,040 KB
testcase_25 AC 79 ms
8,148 KB
testcase_26 AC 79 ms
8,148 KB
testcase_27 AC 79 ms
8,080 KB
testcase_28 AC 88 ms
8,064 KB
testcase_29 AC 87 ms
8,140 KB
testcase_30 AC 88 ms
7,972 KB
testcase_31 AC 89 ms
8,140 KB
testcase_32 AC 88 ms
8,124 KB
testcase_33 AC 66 ms
8,040 KB
testcase_34 AC 88 ms
8,012 KB
testcase_35 AC 55 ms
8,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int Mod = 1000000007;

typedef struct {
	int key[2], id;
} data;

void merge_sort(int n, data x[])
{
	static data y[200001] = {};
	if (n <= 1) return;
	merge_sort(n / 2, &(x[0]));
	merge_sort((n + 1) / 2, &(x[n/2]));
	
	int i, p, q;
	for (i = 0, p = 0, q = n / 2; i < n; i++) {
		if (p >= n / 2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = ((long long)x[p].key[0] * x[q].key[1] <= (long long)x[q].key[0] * x[p].key[1])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, A[200001], B[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	for (i = 1; i <= N; i++) scanf("%d", &(B[i]));
	
	data d[200001];
	for (i = 1; i <= N; i++) {
		d[i-1].key[0] = A[i];
		d[i-1].key[1] = B[i] - 1;
		d[i-1].id = i;
	}
	merge_sort(N, d);
	
	long long ans = 0, tmp = 1;
	for (i = 0; i < N; i++) {
		ans += tmp * A[d[i].id] % Mod;
		tmp = tmp * B[d[i].id] % Mod;
	}
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}
0