結果

問題 No.346 チワワ数え上げ問題
ユーザー Akihiro ShojiAkihiro Shoji
提出日時 2016-02-27 22:09:16
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 791 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 85,948 KB
実行使用メモリ 11,192 KB
最終ジャッジ日時 2023-09-02 20:49:28
合計ジャッジ時間 12,224 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,748 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 1,252 ms
5,228 KB
testcase_11 AC 427 ms
4,372 KB
testcase_12 AC 743 ms
4,932 KB
testcase_13 AC 334 ms
4,368 KB
testcase_14 AC 4 ms
4,368 KB
testcase_15 AC 663 ms
6,180 KB
testcase_16 AC 872 ms
4,932 KB
testcase_17 AC 1,226 ms
5,228 KB
testcase_18 AC 1,204 ms
5,180 KB
testcase_19 AC 923 ms
5,848 KB
testcase_20 AC 7 ms
6,192 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

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() {
  string[] cwws = readln.chomp.split(string.init);
  string cww = "cww";
  size_t count;

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

    if (c == "c") {
      ulong ws = cwws[(idx + 1)..$].filter!(e => e.to!string == "w").count;
      if (1 < ws) {
        count += ws.c(2);
      } else {
        break;
      }
    } else {
      continue;
    }
  }

  writeln(count);
}
0