結果

問題 No.346 チワワ数え上げ問題
ユーザー jp_stejp_ste
提出日時 2016-02-27 00:05:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 997 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 74,456 KB
実行使用メモリ 62,656 KB
最終ジャッジ日時 2023-10-24 17:59:47
合計ジャッジ時間 12,293 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
61,784 KB
testcase_01 AC 116 ms
57,212 KB
testcase_02 WA -
testcase_03 AC 117 ms
57,344 KB
testcase_04 AC 107 ms
56,108 KB
testcase_05 WA -
testcase_06 AC 118 ms
57,384 KB
testcase_07 AC 118 ms
57,392 KB
testcase_08 AC 107 ms
56,152 KB
testcase_09 AC 107 ms
56,176 KB
testcase_10 WA -
testcase_11 AC 437 ms
58,220 KB
testcase_12 WA -
testcase_13 AC 391 ms
58,220 KB
testcase_14 AC 135 ms
56,720 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner scan = new Scanner(System.in)) {
            
            String S = scan.nextLine();
            int ans = 0;
            
            for(int i=0; i<S.length(); i++) {
                if(S.charAt(i) == 'c') {
                    int count = 0;
                    for(int j=i+1; j<S.length(); j++) {
                        if(S.charAt(j) == 'w') {
                            count++;
                        }
                    }
                    if(count >= 2) {
                        int tmp = 0;
                        for(int j=count-1; j>=1; j--) {
                            tmp += j;
                        }
                        ans += tmp;   
                    }
                }
            }
            if(ans == 0) {
                System.out.println(-1);
            } else {
                System.out.println(ans);
            }
        }
    }
}
0