結果

問題 No.200 カードファイト!
ユーザー bal4ubal4u
提出日時 2019-08-24 16:38:24
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 2,080 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 30,360 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-04 15:39:31
合計ジャッジ時間 1,940 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// yukicoder: No.200 カードファイト!
// bal4u 2019.8.24

#include <stdio.h>
#include <stdlib.h>
#include <string.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()) > ' ');
	return n;
}


//// 本問題関連
int N, A, B;
int a[55], b[55];
int aq[55]; int at, aw; // キュー、その先頭、サイズ
int bq[55]; int bw; 

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

// バイナリサーチ。見つからなければ、一つ小さい要素を返す
int bsLE(int x) {
	int m, l = 0, r = bw;
    while (l < r) {
        m = (l+r) >> 1;
        if (bq[m] <= x) l = m + 1; else r = m;
    }
	return l-1;
}

// 見つからなければ、一つ大きい要素を返す。
int bsGE(int x) {
	int m, l = at, r = at+aw;
    while (l < r) {
        m = (l+r) >> 1;
        if (aq[m] < x) l = m + 1; else r = m;
    }
	return l;
}

void erase(int *p, int w) { while (w--) *p = *(p+1), p++; }

int main()
{
	int i, j, x, y, ans;

	N = in() + 1;
	A = in(); i = A; while (i--) a[i] = in();
	B = in(); i = B; while (i--) b[i] = in();
	qsort(a, A, sizeof(int), cmp);
	qsort(b, B, sizeof(int), cmp);

	if (a[0] > b[B-1]) { printf("%d\n", N); return 0; }
	if (b[0] >= a[A-1]) { puts("0"); return 0; }
	
	ans = 0;
	while (--N) {
		if (aw == 0) {
			aw = (N < A)? N: A;
			memcpy(aq, a+A-aw, sizeof(int)*aw);  // 大きいカードを優先的に場から回収
			at = 0;
		}
		if (bw == 0) {
			bw = (N < B)? N: B;
			memcpy(bq, b, sizeof(int)*bw);
		}
		
		// Aは勝てる最小カードを出す。なければ、最小カードを
		if (aw == 1 || aq[at+aw-1] <= bq[0]) x = aq[at++], aw--;
		else { j = bsGE(bq[0]+1), x = aq[j], aw--, erase(aq+j, aw); }
		
		// Bは負ける最大カードを出す。なければ、最大カードを
		if (bw > 1 && bq[0] < x) { j = bsLE(x-1), y = bq[j], bw--, erase(bq+j, bw); }
		else y = bq[--bw];
		
		if (x > y) ans++;
	}
	printf("%d\n", ans);
	return 0;
}
0