結果

問題 No.43 野球の試合
ユーザー bal4ubal4u
提出日時 2019-07-17 17:57:24
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,451 bytes
コンパイル時間 1,620 ms
コンパイル使用メモリ 29,800 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 16:07:24
合計ジャッジ時間 1,365 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 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.43 野球の試合
// 2019.7.17 bal4u

#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()) >= '0');
	return n;
}

void ins(char *s)  // 文字列の入力 スペース以下の文字で入力終了
{
	do *s = gc();
	while (*s++ > ' ');
	*(s-1) = 0;
}

typedef struct { int a, id; } T;
T t[8];
int N;
char s[8][8];
int a[8];
int ans = 10;

int cmp(const void *a, const void *b) { return ((T *)b)->a - ((T *)a)->a; }

int rec(int i, int j) {
	int k;
	
	if (i == N) {
		for (i = 0; i < N; i++) t[i].id = i, t[i].a = a[i];
		qsort(t, N, sizeof(T), cmp);
		k = 1; if (t[0].id) {
			for (i = 1; i < N; i++) {
				if (t[i].a != t[i-1].a) k++;
				if (t[i].id == 0) break;
			}
		}
		if (k < ans) {
			if ((ans = k) == 1) return 1;
		}
		return 0;
	}
	if (j == N) return rec(i+1, i+2);

	if (s[i][j] == 'o') { a[i]++; if (rec(i, j+1)) return 1; a[i]--; }
	else if (s[i][j] == 'x') { a[j]++; if (rec(i, j+1)) return 1; a[j]--; }
	else {
		a[i]++, s[i][j] = 'o', s[j][i] = 'x';
		if (rec(i, j+1)) return 1;
		a[i]--, a[j]++, s[i][j] = 'x', s[j][i] = 'o';
		if (rec(i, j+1)) return 1;
		a[j]--; s[i][j] = s[j][i] = '#';
	}
	return 0;
}	
	
int main()
{
	int r;
	
	N = in(); for (r = 0; r < N; r++) ins(s[r]);
	rec(0, 1);
	printf("%d\n", ans);
	return 0;
}
0