結果

問題 No.346 チワワ数え上げ問題
ユーザー spaciaspacia
提出日時 2016-06-02 16:59:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 464 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 74,364 KB
実行使用メモリ 42,328 KB
最終ジャッジ日時 2024-04-16 23:06:51
合計ジャッジ時間 7,483 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
41,160 KB
testcase_01 AC 132 ms
41,452 KB
testcase_02 AC 130 ms
41,388 KB
testcase_03 AC 129 ms
41,244 KB
testcase_04 AC 131 ms
41,544 KB
testcase_05 AC 130 ms
41,164 KB
testcase_06 AC 130 ms
41,360 KB
testcase_07 AC 132 ms
41,268 KB
testcase_08 AC 130 ms
41,240 KB
testcase_09 AC 118 ms
39,984 KB
testcase_10 AC 193 ms
42,072 KB
testcase_11 AC 188 ms
41,812 KB
testcase_12 AC 190 ms
42,192 KB
testcase_13 AC 176 ms
41,676 KB
testcase_14 AC 144 ms
41,368 KB
testcase_15 AC 197 ms
42,164 KB
testcase_16 AC 193 ms
42,092 KB
testcase_17 AC 197 ms
42,008 KB
testcase_18 AC 203 ms
41,992 KB
testcase_19 AC 201 ms
42,328 KB
testcase_20 AC 200 ms
42,036 KB
testcase_21 AC 196 ms
42,088 KB
testcase_22 AC 203 ms
42,204 KB
testcase_23 AC 129 ms
41,164 KB
testcase_24 AC 129 ms
41,156 KB
testcase_25 AC 128 ms
41,408 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) {
		long wcnt = 0, 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