結果
| 問題 |
No.346 チワワ数え上げ問題
|
| コンテスト | |
| ユーザー |
newlife171128
|
| 提出日時 | 2018-01-18 20:50:38 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 1,005 bytes |
| コンパイル時間 | 1,752 ms |
| コンパイル使用メモリ | 161,580 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-24 11:23:33 |
| 合計ジャッジ時間 | 3,061 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#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;
}
newlife171128