結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー bal4ubal4u
提出日時 2019-04-13 12:46:37
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 1,248 bytes
コンパイル時間 953 ms
コンパイル使用メモリ 29,320 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 11:18:41
合計ジャッジ時間 3,120 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

// yukicoder: No.203 ゴールデン・ウィーク(1)
// 2019.4.13 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), c = gc(); while (c >= '0');
	return n;
}

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

int D;
char c[100];

int calc(char *p)
{
	int w, f, ans;

	ans = 0, f = 0, w = 0;
	while (*p) {
		if (*p == 'o') {
			if (!f) f = 1, w = 1;
			else w++;
		}
		else if (f) {
			if (w > ans) ans = w;
			f = 0;
		}
		p++;
	}
	if (f && w > ans) ans = w;
	return ans;
}

int main()
{
	int i, j, a, ans;
	char memo[20], *p;

	memset(c, 'x', sizeof(c));
	D = in();
	ins(memo), memcpy(c + D, memo, 7);
	ins(memo), memcpy(c + D + 7, memo, 7);

	ans = 0, p = c;
	for (i = 0; i < 2*D + 14; i++) {
		memcpy(memo, p, D);
		for (j = 0; j < D; j++) {
			if (c[i + j] == 'o') break;
			c[i + j] = 'o';
		}
		c[2 * D + 14] = 0;
		a = calc(c);
		if (a > ans) ans = a;
		memcpy(p++, memo, D);
	}
	printf("%d\n", ans);
	return 0;
}
0