結果

問題 No.346 チワワ数え上げ問題
ユーザー t8m8⛄️t8m8⛄️
提出日時 2016-02-26 22:38:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 945 bytes
コンパイル時間 4,558 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 58,524 KB
最終ジャッジ日時 2023-10-24 05:09:52
合計ジャッジ時間 10,624 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
56,316 KB
testcase_01 AC 148 ms
57,508 KB
testcase_02 AC 140 ms
57,516 KB
testcase_03 AC 142 ms
57,688 KB
testcase_04 AC 143 ms
57,588 KB
testcase_05 AC 129 ms
56,376 KB
testcase_06 AC 141 ms
57,336 KB
testcase_07 AC 146 ms
57,752 KB
testcase_08 AC 137 ms
57,204 KB
testcase_09 AC 143 ms
57,604 KB
testcase_10 AC 238 ms
58,200 KB
testcase_11 AC 203 ms
57,992 KB
testcase_12 AC 225 ms
58,280 KB
testcase_13 AC 204 ms
58,144 KB
testcase_14 AC 154 ms
57,600 KB
testcase_15 AC 213 ms
58,244 KB
testcase_16 AC 215 ms
58,164 KB
testcase_17 AC 215 ms
58,204 KB
testcase_18 AC 211 ms
58,132 KB
testcase_19 AC 225 ms
58,524 KB
testcase_20 AC 231 ms
57,976 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 141 ms
57,436 KB
testcase_24 AC 140 ms
57,644 KB
testcase_25 AC 128 ms
56,328 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;

		int[] f = new int[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];
		}

		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