結果
| 問題 |
No.346 チワワ数え上げ問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-26 16:36:40 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 544 bytes |
| コンパイル時間 | 350 ms |
| コンパイル使用メモリ | 29,568 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-11 06:07:50 |
| 合計ジャッジ時間 | 1,235 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <stdio.h>
#include <string.h>
int main(void)
{
char S[100001];
int length, i;
long cum[100000], ans = 0;
scanf("%s", S);
length = strlen(S);
if (S[length - 1] == 'w') cum[length - 1] = 1;
else cum[length - 1] = 0;
for (i = length - 2; 0 <= i; --i) {
if (S[i] == 'w') cum[i] = cum[i + 1] + 1;
else cum[i] = cum[i + 1];
}
for (i = 0; i < length; ++i) {
if (S[i] == 'c') ans += ((cum[i] - 1) * cum[i]) / 2;
}
printf("%ld", ans);
return 0;
}