結果

問題 No.805 UMG
ユーザー tentententen
提出日時 2020-12-07 14:29:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 337 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 2,541 ms
コンパイル使用メモリ 75,980 KB
実行使用メモリ 46,548 KB
最終ジャッジ日時 2024-04-29 11:13:24
合計ジャッジ時間 7,805 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
41,588 KB
testcase_01 AC 114 ms
41,424 KB
testcase_02 AC 126 ms
41,012 KB
testcase_03 AC 126 ms
41,072 KB
testcase_04 AC 127 ms
41,260 KB
testcase_05 AC 125 ms
41,116 KB
testcase_06 AC 116 ms
40,204 KB
testcase_07 AC 126 ms
41,312 KB
testcase_08 AC 116 ms
41,448 KB
testcase_09 AC 122 ms
41,164 KB
testcase_10 AC 107 ms
41,676 KB
testcase_11 AC 129 ms
41,408 KB
testcase_12 AC 121 ms
41,128 KB
testcase_13 AC 130 ms
41,356 KB
testcase_14 AC 107 ms
41,156 KB
testcase_15 AC 155 ms
42,460 KB
testcase_16 AC 151 ms
41,700 KB
testcase_17 AC 143 ms
41,396 KB
testcase_18 AC 160 ms
42,128 KB
testcase_19 AC 143 ms
41,932 KB
testcase_20 AC 143 ms
42,128 KB
testcase_21 AC 147 ms
41,884 KB
testcase_22 AC 157 ms
42,180 KB
testcase_23 AC 329 ms
46,108 KB
testcase_24 AC 318 ms
46,380 KB
testcase_25 AC 337 ms
46,548 KB
testcase_26 AC 315 ms
46,344 KB
testcase_27 AC 319 ms
46,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        TreeSet<Integer> uSet = new TreeSet<>();
        TreeSet<Integer> mSet = new TreeSet<>();
        TreeSet<Integer> gSet = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            if (arr[i] == 'U') {
                uSet.add(i);
            } else if (arr[i] == 'M') {
                mSet.add(i);
            } else {
                gSet.add(i);
            }
        }
        long ans = 0;
        for (int m : mSet) {
            for (int u : uSet) {
                if (m < u) {
                    break;
                }
                if (gSet.contains(m * 2 - u)) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}
0