結果

問題 No.346 チワワ数え上げ問題
ユーザー t8m8⛄️t8m8⛄️
提出日時 2016-02-26 22:42:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 959 bytes
コンパイル時間 4,744 ms
コンパイル使用メモリ 84,488 KB
実行使用メモリ 60,664 KB
最終ジャッジ日時 2023-10-24 05:15:03
合計ジャッジ時間 11,117 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
57,568 KB
testcase_01 AC 146 ms
57,716 KB
testcase_02 AC 145 ms
57,584 KB
testcase_03 AC 145 ms
57,888 KB
testcase_04 AC 146 ms
57,784 KB
testcase_05 AC 141 ms
57,584 KB
testcase_06 AC 144 ms
57,844 KB
testcase_07 AC 146 ms
57,572 KB
testcase_08 AC 147 ms
57,804 KB
testcase_09 AC 146 ms
57,840 KB
testcase_10 AC 245 ms
60,064 KB
testcase_11 AC 217 ms
58,728 KB
testcase_12 AC 239 ms
60,196 KB
testcase_13 AC 224 ms
58,108 KB
testcase_14 AC 159 ms
57,888 KB
testcase_15 AC 221 ms
60,356 KB
testcase_16 AC 234 ms
60,216 KB
testcase_17 AC 244 ms
60,596 KB
testcase_18 AC 243 ms
58,516 KB
testcase_19 AC 240 ms
60,268 KB
testcase_20 AC 249 ms
60,664 KB
testcase_21 AC 237 ms
60,336 KB
testcase_22 AC 237 ms
60,568 KB
testcase_23 AC 142 ms
57,296 KB
testcase_24 AC 140 ms
57,636 KB
testcase_25 AC 142 ms
57,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class No0346 {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		String s = in.next();
		int n = s.length();
		long ans = 0;

		long[] f = new long[n+1];

		for (int i=0; i<n; i++) {
			if (s.charAt(i) == 'w') f[i]++;
		}

		for (int i=n-1; i>=0; i--) {
			f[i] += f[i+1];
		}

		dump(f);

		for (int i=0; i<n; i++) {
			if (s.charAt(i) != 'c') continue;
			ans += f[i]*(f[i]-1)/2;
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		dump((end-start) + "ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}
0