結果

問題 No.346 チワワ数え上げ問題
コンテスト
ユーザー Grenache
提出日時 2016-02-26 22:36:40
言語 Java
(openjdk 26.0.2.1 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 126 ms / 2,000 ms
+ 54µs
コード長 649 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,517 ms
コンパイル使用メモリ 83,716 KB
実行使用メモリ 49,204 KB
最終ジャッジ日時 2026-09-02 19:15:27
合計ジャッジ時間 6,586 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.Scanner;


public class Main_yukicoder346 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char[] s = sc.next().toCharArray();
        int n = s.length;

        int[] cnt = new int[n + 1];
        for (int i = n - 1; i >= 0; i--) {
    		cnt[i] = cnt[i + 1];
        	if (s[i] == 'w') {
        		cnt[i]++;
        	}
        }

        long ret = 0;
        for (int i = 0; i < n; i++) {
        	if (s[i] == 'c' && cnt[i + 1] >= 2) {
        		ret += (long)cnt[i + 1] * (cnt[i + 1] - 1) / 2;
        	}
        }

        System.out.println(ret);

        sc.close();
    }
}
0