結果

問題 No.346 チワワ数え上げ問題
ユーザー ぴろずぴろず
提出日時 2016-02-26 22:29:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 412 ms / 2,000 ms
コード長 492 bytes
コンパイル時間 1,995 ms
コンパイル使用メモリ 74,868 KB
実行使用メモリ 59,956 KB
最終ジャッジ日時 2023-10-23 20:29:16
合計ジャッジ時間 8,987 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
56,208 KB
testcase_01 AC 132 ms
57,096 KB
testcase_02 AC 120 ms
57,080 KB
testcase_03 AC 120 ms
57,116 KB
testcase_04 AC 131 ms
57,576 KB
testcase_05 AC 120 ms
57,016 KB
testcase_06 AC 111 ms
54,148 KB
testcase_07 AC 122 ms
57,084 KB
testcase_08 AC 122 ms
57,112 KB
testcase_09 AC 123 ms
56,972 KB
testcase_10 AC 371 ms
59,780 KB
testcase_11 AC 395 ms
59,716 KB
testcase_12 AC 412 ms
59,848 KB
testcase_13 AC 378 ms
57,700 KB
testcase_14 AC 241 ms
57,048 KB
testcase_15 AC 204 ms
59,908 KB
testcase_16 AC 193 ms
59,912 KB
testcase_17 AC 204 ms
59,932 KB
testcase_18 AC 189 ms
59,780 KB
testcase_19 AC 202 ms
59,780 KB
testcase_20 AC 208 ms
59,792 KB
testcase_21 AC 197 ms
59,956 KB
testcase_22 AC 196 ms
59,700 KB
testcase_23 AC 117 ms
57,120 KB
testcase_24 AC 116 ms
57,520 KB
testcase_25 AC 116 ms
57,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no346;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int n = s.length;
		long ans = 0;
		long[][] dp = new long[2][n+1];
		for(int i=0;i<n;i++) {
			if (s[i] == 'c') {
				dp[0][i+1] += 1;
			}else if(s[i] == 'w') {
				dp[1][i+1] = dp[0][i];
				ans += dp[1][i];
			}
			dp[0][i+1] += dp[0][i];
			dp[1][i+1] += dp[1][i];
		}
		System.out.println(ans);
	}

}
0