結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー bal4ubal4u
提出日時 2019-08-20 14:24:59
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 20 ms / 3,000 ms
コード長 1,097 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 31,104 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 02:17:00
合計ジャッジ時間 1,148 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 19 ms
5,376 KB
testcase_08 AC 18 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 8 ms
5,376 KB
testcase_11 AC 9 ms
5,376 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 20 ms
5,376 KB
testcase_14 AC 18 ms
5,376 KB
testcase_15 AC 19 ms
5,376 KB
testcase_16 AC 19 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:9:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:24: note: 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 && a[i] + a[j] < x) i++;
		if (i < j) { if (++n >= M) return 0; }
		j--;
	}
	return 1;
}

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

int main()
{
	int i, ans;

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