結果

問題 No.346 チワワ数え上げ問題
ユーザー newlife171128newlife171128
提出日時 2018-01-18 20:50:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,005 bytes
コンパイル時間 1,196 ms
コンパイル使用メモリ 147,104 KB
実行使用メモリ 4,780 KB
最終ジャッジ日時 2023-08-25 23:25:50
合計ジャッジ時間 2,379 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 7 ms
4,776 KB
testcase_22 AC 7 ms
4,780 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <map>
#include <string.h>
#include <utility>

typedef long long ll;
using namespace std;

typedef pair<int, int> P;

long dp[100001][3];
long nCr(int n, int r) {
	if (n == r)
		return dp[n][r]=1;
	if (r == 0)
		return dp[n][r]=1;
	if (r == 1)
		return dp[n][r]=n;
	if(dp[n][r]) return dp[n][r];
	return dp[n][r] =nCr(n - 1, r) + nCr(n - 1, r - 1);
}
int main() {

	string s;
	cin >> s;

	string ss = "";
	stringstream sss;

	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'c') {
			sss << s[i];
		}
		if (s[i] == 'w') {
			sss << s[i];
		}
	}
	ss = sss.str();


	int cp=0;
	ll ans =0;
	for(int i=ss.length(); i>=0;i--){
		if(ss[i] =='w'){
			cp++;
		}
		if(ss[i] =='c'){
			if(cp !=1 && cp!=0){
			ans += nCr(cp,2);
			}
		}
	}

	cout<<ans<<endl;


	return 0;
}
0