結果

問題 No.437 cwwゲーム
ユーザー bal4ubal4u
提出日時 2019-07-12 13:42:15
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,165 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 30,096 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-11 00:17:05
合計ジャッジ時間 3,157 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 AC 1 ms
4,380 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 0 ms
4,376 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 0 ms
4,380 KB
testcase_17 AC 0 ms
4,380 KB
testcase_18 AC 0 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 0 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 0 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 0 ms
4,376 KB
testcase_33 AC 0 ms
4,380 KB
testcase_34 AC 0 ms
4,376 KB
testcase_35 AC 0 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 0 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 0 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘ins’ 内:
main.c:7:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:16: 備考: in expansion of macro ‘gc’
   15 |         do c = gc(), *s++ = c & 0xf;
      |                ^~

ソースコード

diff #

// yukicoder: No.437 cwwゲーム
// 2019.7.12 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

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

char N[15], w;
int ans;
int two[200][2], sz;

void rec(int i, int j, int b, int s) {
	while (i < w-2) {
		while (j < sz && (two[j][0] <= i || N[i] == N[two[j][0]] || (b & two[j][1]))) j++;
		if (j < sz) {
			int bb = b | two[j][1], ss = s + N[i]*100 + N[two[j][0]]*11, ii = i+1;
			while (ii < w-2 && (N[ii] == 0 || (bb & (1<<ii)))) ii++;
			if (ii < w-2) rec(ii, 0, bb, ss);
			else if (ss > ans) ans = ss;
			j++;
		} else {
			i++, j = 0;
			while (i < w-2 && (N[i] == 0 || (b & (1<<i)))) i++;
			if (i >= w-2) { if (s > ans) ans = s; break; }
		}
	}
}
		
int main()
{
	int i, j, k;
	
	w = ins(N);
	if (w >= 3) {
		for (j = 1; j < w; j++) for (k = j+1; k < w; k++) {
			if (N[k] == N[j]) two[sz][0] = j, two[sz++][1] = (1<<j)|(1<<k);
		}
		if (sz) for (i = 0; i < w-2; i++) if (N[i]) rec(i, 0, 0, 0);
	}
	printf("%d\n", ans);
	return 0;
}
0