結果
問題 |
No.346 チワワ数え上げ問題
|
ユーザー |
![]() |
提出日時 | 2016-11-03 07:01:57 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,655 ms / 2,000 ms |
コード長 | 881 bytes |
コンパイル時間 | 1,208 ms |
コンパイル使用メモリ | 159,772 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-25 01:59:31 |
合計ジャッジ時間 | 5,944 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> //const static double de_PI = 3.14159265358979323846; //const static int de_MOD = 1000000007; //const static int de_MAX = 999999999; //const static int de_MIN = -999999999; inline double nCr(const int n, int r) { if (n == 0) { return 0; } if (r == 0) { return 1; } if (r == 1) { return n; } if (n == r) { return 1; } if (r > n / 2) { r = n / 2; } double result = 1; for (double i = 1; i <= r; i++) { result *= (n - i + 1) / i; } return(result); } int main(void) { //std::ifstream in("123.txt"); std::cin.rdbuf(in.rdbuf()); std::string S; std::cin >> S; double ans = 0; int st = 0, n = 0; while (S.find('c', st) != std::string::npos) { st = S.find('c', st) + 1; n = std::count(S.begin() + st, S.end(), 'w'); if (n >= 2) { ans += nCr(n, 2); } else { break; } } std::cout << std::setprecision(20) << ans << std::endl; }