結果

問題 No.346 チワワ数え上げ問題
ユーザー h_tyokinuhatah_tyokinuhata
提出日時 2016-02-28 01:28:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 389 bytes
コンパイル時間 1,889 ms
コンパイル使用メモリ 74,180 KB
実行使用メモリ 57,900 KB
最終ジャッジ日時 2023-10-24 18:42:30
合計ジャッジ時間 6,665 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,732 KB
testcase_01 AC 116 ms
57,368 KB
testcase_02 AC 116 ms
57,520 KB
testcase_03 AC 117 ms
57,328 KB
testcase_04 AC 121 ms
57,584 KB
testcase_05 AC 107 ms
56,268 KB
testcase_06 AC 119 ms
57,404 KB
testcase_07 AC 109 ms
56,828 KB
testcase_08 AC 116 ms
57,496 KB
testcase_09 AC 109 ms
56,284 KB
testcase_10 AC 182 ms
57,732 KB
testcase_11 AC 163 ms
57,896 KB
testcase_12 AC 182 ms
57,796 KB
testcase_13 AC 163 ms
57,408 KB
testcase_14 AC 125 ms
57,348 KB
testcase_15 AC 180 ms
57,644 KB
testcase_16 AC 179 ms
57,728 KB
testcase_17 AC 189 ms
57,736 KB
testcase_18 AC 186 ms
57,840 KB
testcase_19 AC 181 ms
57,724 KB
testcase_20 AC 187 ms
57,900 KB
testcase_21 AC 187 ms
57,876 KB
testcase_22 AC 181 ms
57,552 KB
testcase_23 AC 117 ms
57,292 KB
testcase_24 AC 114 ms
57,060 KB
testcase_25 AC 116 ms
57,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String S = sc.next();
		
		char[] charS = S.toCharArray();
		
		long c = 0, w = 0;
		
		for(int i = S.length() - 1; i >= 0; i--) {
			if(charS[i] == 'c') {
				c+=w * (w - 1) / 2;
			} else if(charS[i] == 'w') {
				w++;
			}
		}
		
		System.out.println(c);
	}
}
0