結果

問題 No.346 チワワ数え上げ問題
ユーザー YamaKasaYamaKasa
提出日時 2018-09-17 03:10:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 546 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 72,056 KB
実行使用メモリ 58,096 KB
最終ジャッジ日時 2023-09-25 09:16:11
合計ジャッジ時間 7,462 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,812 KB
testcase_01 AC 123 ms
55,816 KB
testcase_02 AC 119 ms
55,460 KB
testcase_03 AC 119 ms
55,968 KB
testcase_04 AC 123 ms
55,808 KB
testcase_05 AC 120 ms
55,680 KB
testcase_06 AC 123 ms
55,980 KB
testcase_07 AC 121 ms
55,836 KB
testcase_08 AC 122 ms
55,804 KB
testcase_09 AC 123 ms
55,792 KB
testcase_10 AC 200 ms
56,072 KB
testcase_11 AC 182 ms
56,244 KB
testcase_12 AC 193 ms
56,352 KB
testcase_13 AC 188 ms
56,416 KB
testcase_14 AC 132 ms
55,800 KB
testcase_15 AC 184 ms
58,096 KB
testcase_16 AC 197 ms
56,000 KB
testcase_17 AC 197 ms
56,096 KB
testcase_18 AC 206 ms
56,388 KB
testcase_19 AC 193 ms
56,580 KB
testcase_20 AC 192 ms
56,548 KB
testcase_21 AC 200 ms
56,404 KB
testcase_22 AC 192 ms
56,388 KB
testcase_23 AC 118 ms
55,388 KB
testcase_24 AC 119 ms
55,680 KB
testcase_25 AC 118 ms
56,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		scan.close();
		int l = S.length();
		int[]k = new int[l];
		int cnt = 0;
		for(int i = 0; i < l; i++) {
			if(S.charAt(i) == 'w'){
				cnt++;
			}
			k[i] = cnt;
		}
		long ans = 0;
		for(int i = 0; i < l; i++) {
			if(S.charAt(i) == 'c') {
				int m = cnt - k[i];
				if(m >= 2) {
					ans += (long)m * (m - 1) / 2;
				}else {
					break;
				}
			}
		}
		System.out.println(ans);
	}
}
0