結果

問題 No.346 チワワ数え上げ問題
ユーザー Akihiro ShojiAkihiro Shoji
提出日時 2016-02-27 22:32:21
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 885 bytes
コンパイル時間 2,644 ms
コンパイル使用メモリ 166,160 KB
実行使用メモリ 12,600 KB
最終ジャッジ日時 2023-09-02 20:50:59
合計ジャッジ時間 15,215 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,740 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 2 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 1,377 ms
8,712 KB
testcase_11 AC 469 ms
5,068 KB
testcase_12 AC 820 ms
7,188 KB
testcase_13 AC 367 ms
4,936 KB
testcase_14 AC 4 ms
4,368 KB
testcase_15 AC 726 ms
7,404 KB
testcase_16 AC 957 ms
8,192 KB
testcase_17 AC 1,343 ms
8,672 KB
testcase_18 AC 1,320 ms
8,992 KB
testcase_19 AC 1,015 ms
7,420 KB
testcase_20 AC 18 ms
8,208 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() {
  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