結果
| 問題 | No.346 チワワ数え上げ問題 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-04 14:58:08 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 2,363 bytes |
| 記録 | |
| コンパイル時間 | 2,056 ms |
| コンパイル使用メモリ | 215,160 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2026-02-04 14:58:14 |
| 合計ジャッジ時間 | 4,291 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define mod99 998244353
#define mod107 1000000007
#define endl "\n"
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define prep(i,a,n) for (ll i = a; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(), a.rend()
#define si(x) ((long long)(x).size())
#define yn(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define PRE(x) cout << fixed << setprecision(x)
#define yes cout << "Yes\n"
#define no cout << "No\n"
template <typename T> inline T gcd(T a,T b) {return (b==0)?a:gcd(b,a%b);}
template <typename T> inline T lcm(T a, T b) {return a/gcd(a,b)*b;}
#define sq(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
//const ld PI=3.141592653589793238462643383279;
const ll INF=5000000000000000000LL;
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string abc = "abcdefghijklmnopqrstuvwxyz";
#define next_p next_permutation
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
#define ull unsigned long long
#define u_map unordered_map
#define setting(x) sort(x.begin(),x.end());x.erase(unique(x.begin(),x.end()),x.end())
template<typename T> using vc = vector<T>; using vcc = vector<char>;
template<typename T> using vv = vc<vc<T>>; using vvc = vv<char>;
using vi = vc<int>; using vvi = vv<int>; using vvvi = vv<vi>;
using vl = vc<ll>; using vvl = vv<ll>; using vvvl = vv<vl>;
using vb = vc<bool>; using vvb = vv<bool>; using vvvb = vv<vb>;
using vs = vc<string>; using vvs = vv<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using vpii = vc<pii>; using vpll = vc<pll>;
using vvpii = vv<pii>; using vvpll = vv<pll>;
using vld = vc<ld>; using vvld = vv<ld>; using vvvld = vv<vld>;
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include<atcoder/all>
//using namespace atcoder;
//using mint=modint998244353;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;cin>>s;
ll n=si(s);
vl w(n);
for(ll i=n-1;i>=0;i--) {
if(i==n-1) {
if(s[i]=='w') w[i]++;
continue;
}
ll memo=0;
if(s[i]=='w') memo++;
w[i]+=memo+w[i+1];
}
ll ans=0;
rep(i,n) if(s[i]=='c') ans+=w[i]*(w[i]-1)/2;
cout<<ans<<endl;
}