結果

問題 No.346 チワワ数え上げ問題
ユーザー spaciaspacia
提出日時 2016-06-02 16:56:17
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 470 bytes
コンパイル時間 2,239 ms
コンパイル使用メモリ 74,040 KB
実行使用メモリ 42,156 KB
最終ジャッジ日時 2024-04-16 23:06:07
合計ジャッジ時間 6,465 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
40,996 KB
testcase_01 AC 116 ms
40,756 KB
testcase_02 AC 119 ms
41,424 KB
testcase_03 AC 119 ms
40,956 KB
testcase_04 AC 118 ms
41,104 KB
testcase_05 AC 115 ms
41,132 KB
testcase_06 AC 122 ms
40,904 KB
testcase_07 AC 107 ms
41,260 KB
testcase_08 AC 101 ms
40,920 KB
testcase_09 AC 117 ms
40,768 KB
testcase_10 AC 164 ms
42,008 KB
testcase_11 AC 168 ms
41,540 KB
testcase_12 AC 169 ms
42,156 KB
testcase_13 AC 147 ms
41,404 KB
testcase_14 AC 116 ms
40,992 KB
testcase_15 AC 172 ms
41,928 KB
testcase_16 AC 177 ms
41,732 KB
testcase_17 AC 184 ms
42,136 KB
testcase_18 AC 164 ms
41,820 KB
testcase_19 AC 165 ms
41,880 KB
testcase_20 AC 174 ms
42,036 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 100 ms
40,780 KB
testcase_24 AC 106 ms
40,780 KB
testcase_25 AC 100 ms
40,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner(System.in);

		System.out.println(solve(sc.next()));

		sc.close();

	}

	public static long solve (String s) {
		int wcnt = 0;
		long sum = 0;
		int len = s.length();
		for (int i = len - 1; i >= 0; i--) {
			if (s.charAt(i) == 'w') {
				wcnt++;
				continue;
			}
			if (s.charAt(i) == 'c')
				sum += wcnt * (wcnt - 1) / 2;
		}
		return sum;
	}

}
0