結果
| 問題 | No.346 チワワ数え上げ問題 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-02-27 22:13:20 |
| 言語 | C++11(old_compat) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 771 bytes |
| 記録 | |
| コンパイル時間 | 1,149 ms |
| コンパイル使用メモリ | 169,896 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-08 16:05:47 |
| 合計ジャッジ時間 | 1,806 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
using i64 = long long;
template<typename T>
class Range{private:struct I{T x;T operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:Range(T n):i({0}),n({n}){}Range(T i,T n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};
using range = Range<i64>;
vector<vector<i64>> nCr;
i64 nC2(i64 n) { return n * (n-1) / 2; }
int main(void) {
string s; cin >> s;
int n = s.size();
vector<int> ws(n, 0); // ws[n]
ws[0] = s[0]=='w';
for(auto&& i : range(1, n)) {
ws[i] = ws[i-1] + (s[i]=='w');
}
i64 res = 0;
for(auto&& i : range(n-1)) {
if(s[i]=='c') {
res += nC2(ws[n-1] - ws[i]);
}
}
printf("%lld\n", res);
return 0;
}