結果

問題 No.346 チワワ数え上げ問題
ユーザー hanorverhanorver
提出日時 2016-02-26 22:35:11
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 639 bytes
コンパイル時間 706 ms
コンパイル使用メモリ 61,088 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-23 20:33:24
合計ジャッジ時間 2,506 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 RE -
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 94 ms
4,368 KB
testcase_11 AC 31 ms
4,368 KB
testcase_12 AC 57 ms
4,368 KB
testcase_13 AC 23 ms
4,368 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 48 ms
4,368 KB
testcase_16 AC 62 ms
4,368 KB
testcase_17 AC 92 ms
4,368 KB
testcase_18 AC 94 ms
4,368 KB
testcase_19 AC 68 ms
4,368 KB
testcase_20 AC 4 ms
4,368 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
4,368 KB
testcase_24 AC 1 ms
4,368 KB
testcase_25 AC 1 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>

int main() {
	std::string s;
	std::cin >> s;

	// cとwだけの文字列にする
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != 'c' && s[i] != 'w') {
			s.erase(s.begin() + i);
			i--;
		}
	}

	std::vector<int> w(s.length());
	if (s.back() == 'w') {
		w[s.length() - 1] = 1;
	} else {
		w[s.length() - 1] = 0;
	}
	for (int i = s.length() - 2; i >= 0; i--) {
		w[i] = w[i + 1];
		if (s[i] == 'w') w[i]++;
	}

	long long ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'c') {
			ans += (w[i] * (w[i] - 1)) / 2;
		}
	}

	std::cout << ans << std::endl;
	return 0;
}
0