結果

問題 No.794 チーム戦 (2)
ユーザー KotRmKotRm
提出日時 2019-03-15 09:21:06
言語 JavaScript
(node v20.8.0)
結果
WA  
実行時間 -
コード長 1,475 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 81,460 KB
最終ジャッジ日時 2023-08-03 03:06:18
合計ジャッジ時間 5,023 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
42,544 KB
testcase_01 AC 86 ms
42,640 KB
testcase_02 WA -
testcase_03 AC 85 ms
42,592 KB
testcase_04 AC 85 ms
42,668 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 88 ms
42,704 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

process.stdin.resume();
process.stdin.setEncoding('utf8');
var lines = [];
var reader = require('readline').createInterface({
		input: process.stdin,
		output: process.stdout
});
reader.on('line', (line) => {
		lines.push(line);
});

/*nPr*/
function P(n, r) {
    var ans = 1
    for(var i = 0; i < r; i++) {
        ans *= n - i;
    }
    return ans;
}
/*nCr*/
function C(n, r) {
    return P(n, r) / P(r, r);
}
/*N人を二人組みに分ける通りの数*/
function Func(N){
    var ans = 1;
    for(var i = N; i >= 2; i-=2){
        ans *= C(i, 2);
    }
    return ans/P(N/2, N/2);
}

reader.on('close', () => {
    /*標準入力の受け取り*/
	var N = Number(lines[0].split(' ')[0]);
	var K = Number(lines[0].split(' ')[1]);
	var A = lines[1].split(' ').map(Number).sort(function(a,b){return b - a;});
	var mod = 10^9 + 7;
  
	/*Aiの値で二組に分配*/	
	var X = Array(); /*誰とでも組める人 Ai≦K/2*/
	var Y = Array(); /*Xの人と組まないとKを超えてしまう人*/
	for(var i=0; i<N && 2*A[i]>K; i++){
        Y.push(A[i]);
	}
	for(var j=i; j<N; j++){
	    X.push(A[j]);
	}	
	
	/*Yを含む2人組の組み方*/
	var result = 1;
	for(i=0; i<Y.length; i++){
	    for(j=0; j<X.length; j++){
            if(Y[i]+X[j]<=K){
                result *= (X.length-(i+1))%mod;
                break;
            }
        }
    }
	/*残った(X.length-i)人を二人組みに分ける通り*/
	result *= Func(X.length-i);
	
	console.log(result);
});
0