結果

問題 No.346 チワワ数え上げ問題
ユーザー Akihiro ShojiAkihiro Shoji
提出日時 2016-02-27 22:23:01
言語 D
(dmd 2.106.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 869 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 166,332 KB
実行使用メモリ 10,516 KB
最終ジャッジ日時 2023-09-02 20:49:56
合計ジャッジ時間 9,153 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 1 ms
4,368 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 84 ms
9,804 KB
testcase_11 AC 29 ms
5,104 KB
testcase_12 AC 50 ms
7,200 KB
testcase_13 AC 23 ms
6,512 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 44 ms
7,140 KB
testcase_16 AC 58 ms
7,456 KB
testcase_17 AC 82 ms
8,744 KB
testcase_18 AC 81 ms
8,476 KB
testcase_19 AC 62 ms
8,460 KB
testcase_20 AC 22 ms
9,336 KB
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 1 ms
4,372 KB
testcase_24 AC 1 ms
4,372 KB
testcase_25 AC 1 ms
4,368 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;
  size_t idx;
  size_t count;

  foreach (c; readln.chomp.split(string.init).to!(dchar[])) {
    if (c == 'c' || c == 'w') {
      cwws ~= c;
    }
  }

  foreach (c; cwws) {
    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