結果
問題 |
No.346 チワワ数え上げ問題
|
ユーザー |
![]() |
提出日時 | 2017-07-28 00:35:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 970 bytes |
コンパイル時間 | 967 ms |
コンパイル使用メモリ | 89,172 KB |
実行使用メモリ | 6,144 KB |
最終ジャッジ日時 | 2024-10-10 02:22:07 |
合計ジャッジ時間 | 1,944 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 3 WA * 20 |
ソースコード
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <cmath> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <stdlib.h> #include <stdio.h> #include <bitset> using namespace std; #define FOR(I,A,B) for(int I = (A); I < (B); ++I) typedef long long ll; const ll MOD = 1e9+7; const ll SIZE = 100010; // こっちの方が使いまわせて良い ll inv[SIZE],fac[SIZE],finv[SIZE]; void make(){ fac[0]=fac[1]=1; finv[0]=finv[1]=1; inv[1]=1; for(ll i=2;i<SIZE;i++){ inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD; fac[i]=fac[i-1]*(ll) i%MOD; finv[i]=finv[i-1]*inv[i]%MOD; } } ll C (ll a,ll b) { if(a<b) return 0; return fac[a]*(finv[b]*finv[a-b]); } int main() { make(); string s; cin >> s; ll cnt = 0; ll ans = 0; for(int i = s.length()-1; i >= 0; i--) { if(s[i]=='w') cnt++; if(s[i]=='c' && cnt >= 2) ans += C(cnt,2); } cout << ans << endl; return 0; }