結果

問題 No.346 チワワ数え上げ問題
ユーザー Akihiro ShojiAkihiro Shoji
提出日時 2016-02-27 22:37:08
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 3,903 ms
コンパイル使用メモリ 166,080 KB
実行使用メモリ 9,516 KB
最終ジャッジ日時 2023-09-02 20:51:33
合計ジャッジ時間 3,779 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 19 ms
8,200 KB
testcase_11 AC 12 ms
6,352 KB
testcase_12 AC 16 ms
7,132 KB
testcase_13 AC 11 ms
4,932 KB
testcase_14 AC 2 ms
4,372 KB
testcase_15 AC 15 ms
8,716 KB
testcase_16 AC 16 ms
7,200 KB
testcase_17 AC 19 ms
9,516 KB
testcase_18 AC 19 ms
7,488 KB
testcase_19 AC 17 ms
7,196 KB
testcase_20 AC 20 ms
8,272 KB
testcase_21 AC 20 ms
9,200 KB
testcase_22 AC 19 ms
8,424 KB
testcase_23 AC 1 ms
4,372 KB
testcase_24 AC 1 ms
4,368 KB
testcase_25 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

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;
  ulong ws;

  foreach_reverse (c; cwws) {
    if (cwws.length - 2 < idx) {
      break;
    }

    if (c == 'c') {
      count += ws.c(2);
    } else if (c == 'w'){
      ws++;
    }
    idx++;
  }

  writeln(count);
}
0