結果

問題 No.2008 Super Worker
ユーザー ygussanyygussany
提出日時 2022-07-15 21:41:14
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,002 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 30,148 KB
実行使用メモリ 8,172 KB
最終ジャッジ日時 2023-09-10 01:04:21
合計ジャッジ時間 3,677 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 78 ms
8,072 KB
testcase_24 AC 79 ms
8,028 KB
testcase_25 AC 79 ms
8,112 KB
testcase_26 AC 79 ms
8,068 KB
testcase_27 AC 79 ms
8,084 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 55 ms
8,080 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];
		tmp = tmp * B[d[i].id] % Mod;
	}
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}
0