結果

問題 No.133 カードゲーム
ユーザー bal4ubal4u
提出日時 2019-05-20 06:24:40
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,142 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 31,328 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 08:04:43
合計ジャッジ時間 1,508 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:13:24: note: in expansion of macro 'gc'
   13 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: 133 カードゲーム
// 2019.5.20 bal4u

#include <stdio.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 A[5], B[5];
int ord[30][5], sz;

void genperm(int K)
{
	int i, k, t;
	char c[12], *pc, *q;
	static char p[12] = { 1,1,1,1 };

	q = p, pc = c;
	for (k = 1; k <= K; ) *q++ = *pc++ = k++;  // 1 2 3 のように1から
	k = 1, pc = c;
	do {
		t = *(p + k);
		*(p + k) = *(q = p + ((k & 1) ? *pc : 0));
		*q = t;
		
		for (i = 0; i < K; i++) ord[sz][i] = p[i];
		sz++;
		
		k = 1, pc = c;
		while (*pc == 0) *pc++ = k++;
		(*pc)--;
	} while (k < K);
}

int main()
{
	int i, j, k, N, a, b, s;
	
	N = in();
	for (i = 1; i <= N; i++) A[i] = in();
	for (j = 1; j <= N; j++) B[j] = in();
	genperm(N);
	
	s = 0; for (i = 0; i < sz; i++) for (j = 0; j < sz; j++) {
		a = b = 0; for (k = 0; k < N; k++) {
			if (A[ord[i][k]] > B[ord[j][k]]) a++;
			else if (A[ord[i][k]] < B[ord[j][k]]) b++;
		}
		if (a > b) s++;
	}
	printf("%lf\n", (double)s / (sz*sz));
	return 0;
}
0