結果

問題 No.154 市バス
ユーザー bal4ubal4u
提出日時 2019-05-10 06:57:46
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,220 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 30,068 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 17:49:53
合計ジャッジ時間 881 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:7:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:24: 備考: in expansion of macro ‘gc’
   15 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘outs’ 内:
main.c:8:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:30:33: 備考: in expansion of macro ‘pc’
   30 | void outs(char *s) { while (*s) pc(*s++); }
      |                                 ^~

ソースコード

diff #

// yukicoder: No.154 市バス
// 2019.5.10 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()    // 非負整数の入力
{
	int n = 0, c = gc();
	//	while (isspace(c)) 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;
}

void outs(char *s) { while (*s) pc(*s++); }

char S[1005];
int q[3][1005], sz[3];
int id[128];

int main()
{
	int i, j, k, T, len;
	
	id['W'] = 0, id['G'] = 1, id['R'] = 2;
	T = in(); while (T--) {
		sz[0] = sz[1] = sz[2] = 0;
		len = ins(S);
		if (*(S+len-1) != 'R') goto NG;
		for (i = 0; i < len; i++)
			j = id[S[i]], q[j][sz[j]++] = i;
		if (sz[0] < sz[1] || sz[1] != sz[2]) goto NG;
		k = 0; for (j = 0; j < sz[1]; j++) {
			while (q[2][k] < q[1][j]) k++;
			if (k > j) goto NG;
		}
		i = sz[0]-1; for (j = sz[1]-1; j >= 0; j--) {
			while (q[0][i] > q[1][j]) i--;
			if (sz[0]-i > sz[1]-j) goto NG;
		}
		outs("possible\n");
		continue;
NG:		outs("impossible\n");
	}
	return 0;
}
0