結果

問題 No.346 チワワ数え上げ問題
ユーザー hanorverhanorver
提出日時 2016-02-26 22:55:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 681 bytes
コンパイル時間 1,090 ms
コンパイル使用メモリ 60,920 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 05:45:29
合計ジャッジ時間 2,069 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 95 ms
4,348 KB
testcase_11 AC 32 ms
4,348 KB
testcase_12 AC 57 ms
4,348 KB
testcase_13 AC 23 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 48 ms
4,348 KB
testcase_16 AC 63 ms
4,348 KB
testcase_17 AC 93 ms
4,348 KB
testcase_18 AC 95 ms
4,348 KB
testcase_19 AC 70 ms
4,348 KB
testcase_20 AC 5 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 5 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 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<long long> w(s.length());
	if (s.length() > 0 && s.back() == 'w') {
		w[s.length() - 1] = 1;
	} else if(s.length() > 0){
		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