結果
問題 | No.346 チワワ数え上げ問題 |
ユーザー |
![]() |
提出日時 | 2020-03-05 09:36:08 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,308 bytes |
コンパイル時間 | 1,246 ms |
コンパイル使用メモリ | 79,772 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 00:47:39 |
合計ジャッジ時間 | 1,786 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include <algorithm>#include <bitset>#include <cassert>#include <cmath>#include <ctime>#include <cstring>#include <functional>#include <iostream>#include <map>#include <queue>#include <set>#include <stack>#include <string>#include <vector>#define rep(i,n) for (int i = 0; i < (n); ++i)#define sort(a) sort((a).begin(), (a).end());#define uniq(a) SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());#define find(a,x) find((a).begin(), (a).end(), (x)) != (a).end()#define reverse(a) reverse((a).begin(), (a).end());#define out(d) cout << (d);#define outl(d) std::cout<<(d)<<"\n";#define Yes() printf("Yes\n");#define No() printf("No\n");#define YES() printf("YES\n");#define NO() printf("NO\n");#define ceil(x, y) ((x + y - 1) / (y))using namespace std;using ll = long long;using P = pair<ll,ll>;const ll MOD = 1000000007; // 10^9 + 7int main() {cin.tie(0);ios::sync_with_stdio(false);srand((unsigned)time(NULL));string s; cin >> s;ll n = s.size();ll w[n]; memset(w, 0, sizeof(w));w[n - 1] = s[n - 1] == 'w' ? 1 : 0;for (int i = n - 2; i >= 0; i--) {w[i] += w[i + 1];if (s[i] == 'w') w[i]++;}ll sum = 0;for (int i = 0; i < n; i++)if (s[i] == 'c') {sum += w[i] * (w[i] - 1) / 2;}outl(sum)}