結果

問題 No.346 チワワ数え上げ問題
ユーザー Mcpu3
提出日時 2018-09-26 16:44:02
言語 Java
(openjdk 23)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 2,968 ms
コンパイル使用メモリ 74,692 KB
実行使用メモリ 43,404 KB
最終ジャッジ日時 2024-10-11 06:09:08
合計ジャッジ時間 8,109 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        sc.close();
        int length = S.length();
        long cum[] = new long[length], ans = 0;
        if (S.charAt(length - 1) == 'w') cum[length - 1] = 1;
        else cum[length - 1] = 0;
        for (int i = length - 2; 0 <= i; --i) {
            if (S.charAt(i) == 'w') cum[i] = cum[i + 1] + 1;
            else cum[i] = cum[i + 1];
        }
        for (int i = 0; i < length; ++i) {
            if (S.charAt(i) == 'c') ans += ((cum[i] - 1) * cum[i]) / 2;
        }
        System.out.print(ans);
    }
}
0