結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー bal4ubal4u
提出日時 2019-08-20 13:48:03
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,073 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 29,128 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-28 18:11:49
合計ジャッジ時間 2,172 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 18 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 8 ms
4,376 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 18 ms
4,380 KB
testcase_14 AC 17 ms
4,376 KB
testcase_15 AC 17 ms
4,380 KB
testcase_16 AC 17 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 0 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 0 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:9:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:24: 備考: in expansion of macro ‘gc’
   15 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.507 ゲーム大会(チーム決め)
// bal4u 2019.8.20

#include <stdio.h>
#include <stdlib.h>

//// 入出力関係
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() { // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int N, M;
int a[100005];

int cmp(const void *u, const void *v) { return *(int *)u - *(int *)v; }

	
int ok(int x, int id)
{
	int i, j, n = 0;
	j = N-1; for (i = 1; i < j; i++) {
		if (j == id) j--;
		while (i < j && (i == id || a[i] + a[j] < x)) i++;
		if (i < j) { if (++n >= M) return 0; }
		j--;
	}
	return 1;
}

int resolv() {
	int t, f = 0, m, l = 1, r = N;
	
    while (l+1 < r) {
        m = (l+r) >> 1;
		t = ok(a[0]+a[m], m), f |= t;
        if (t) r = m; else l = m;
    }
	if (!f) return -1;
	return a[r];
}

int main()
{
	int i;

	N = in(), M = in();
	for (i = 0; i < N; i++) a[i] = in();
	if (N == 2) { printf("%d\n", a[1]); return 0; }
	qsort(a+1, N-1, sizeof(int), cmp);
	a[0]++;
	printf("%d\n", resolv());
	return 0;
}
0