結果

問題 No.346 チワワ数え上げ問題
ユーザー KinaKina
提出日時 2021-02-06 18:00:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,071 bytes
コンパイル時間 2,020 ms
コンパイル使用メモリ 74,184 KB
実行使用メモリ 52,536 KB
最終ジャッジ日時 2023-09-16 04:07:19
合計ジャッジ時間 4,703 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,192 KB
testcase_01 AC 43 ms
49,368 KB
testcase_02 AC 42 ms
49,312 KB
testcase_03 AC 41 ms
49,228 KB
testcase_04 AC 43 ms
49,396 KB
testcase_05 AC 43 ms
49,276 KB
testcase_06 AC 44 ms
49,440 KB
testcase_07 AC 42 ms
49,572 KB
testcase_08 AC 44 ms
49,220 KB
testcase_09 AC 44 ms
49,224 KB
testcase_10 AC 76 ms
52,536 KB
testcase_11 AC 73 ms
51,984 KB
testcase_12 AC 77 ms
52,312 KB
testcase_13 AC 72 ms
51,620 KB
testcase_14 AC 44 ms
49,276 KB
testcase_15 AC 69 ms
49,704 KB
testcase_16 AC 79 ms
51,976 KB
testcase_17 AC 81 ms
51,920 KB
testcase_18 AC 81 ms
52,452 KB
testcase_19 AC 81 ms
52,372 KB
testcase_20 AC 80 ms
52,324 KB
testcase_21 AC 79 ms
52,392 KB
testcase_22 AC 79 ms
51,868 KB
testcase_23 AC 41 ms
49,344 KB
testcase_24 AC 42 ms
49,524 KB
testcase_25 AC 43 ms
49,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		var S = sc.get().toCharArray();
		var cumOfW = new int[S.length];
		for (int i = 1; i < cumOfW.length; i++) {
			cumOfW[i] = cumOfW[i - 1] + (S[i] == 'w' ? 1 : 0);
		}

		long sumOfCWW = 0;
		for (int i = 0; i < S.length; i++) {
			if (S[i] != 'c') continue;
			long trailingWs = cumOfW[S.length - 1] - cumOfW[i];
			sumOfCWW += trailingWs * (trailingWs - 1) / 2;
		}

		System.out.println(sumOfCWW);
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}
0