結果

問題 No.346 チワワ数え上げ問題
ユーザー Akihiro Shoji
提出日時 2016-02-27 22:32:21
言語 D
(dmd 2.109.1)
結果
TLE  
実行時間 -
コード長 885 bytes
コンパイル時間 2,905 ms
コンパイル使用メモリ 165,888 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-06-12 03:10:33
合計ジャッジ時間 11,904 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 21 TLE * 1 -- * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm,
       std.string,
       std.range,
       std.stdio,
       std.conv;

ulong factorial(ulong n) {
  ulong t = 1;

  for (ulong i; i < n; i++)
    t *= (n - i);

  return t;
}

ulong p(ulong n, ulong r) {
  ulong t = 1;

  for (ulong i; i < r; i++)
    t *= (n - i);

  return t;
}

ulong c(ulong n, ulong r) {
  return p(n, r) / r.factorial; 
}

void main() {
  dchar[] cwws = readln.chomp.split(string.init).to!(dchar[]);
  size_t idx;
  size_t count;

  foreach (c; cwws) {
    if (c == 'c' || c == 'w') {
      if (cwws.length - 2 < idx) {
        break;
      }

      if (c == 'c') {
        ulong ws;
        foreach (w; cwws[(idx + 1)..$]) {
          if (w == 'w') {
            ws++;
          }
        }

        if (1 < ws) {
          count += ws.c(2);
        } else {
          break;
        }
      }

    }
    idx++;
  }

  writeln(count);
}
0