結果

問題 No.346 チワワ数え上げ問題
ユーザー bal4u
提出日時 2019-04-15 16:17:25
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 494 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 29,824 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-22 07:56:19
合計ジャッジ時間 937 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'ins':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:17: note: in expansion of macro 'gc'
   14 |         do *s = gc();
      |                 ^~

ソースコード

diff #

// yukicoder: No.346 チワワ数え上げ問題
// 2019.4.15 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int ins(char *s)
{
	char *p = s;
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
	return s - p;
}

char S[100005];

int main()
{
	int w;
	long long ans;
	char *p;

	p = S + ins(S), w = 0, ans = 0;
	while (--p >= S) {
		if (*p == 'w') w++;
		else if (*p == 'c') ans += (long long)w*(w-1) >> 1;
	}
	printf("%lld\n", ans);
	return 0;
}
0