結果

問題 No.805 UMG
ユーザー ameame
提出日時 2019-03-22 21:46:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 844 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 75,260 KB
実行使用メモリ 41,552 KB
最終ジャッジ日時 2024-04-29 10:32:37
合計ジャッジ時間 7,136 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
41,424 KB
testcase_01 AC 131 ms
41,224 KB
testcase_02 AC 131 ms
41,196 KB
testcase_03 AC 129 ms
41,216 KB
testcase_04 AC 117 ms
40,312 KB
testcase_05 AC 122 ms
40,400 KB
testcase_06 AC 117 ms
40,072 KB
testcase_07 AC 129 ms
41,404 KB
testcase_08 AC 130 ms
41,200 KB
testcase_09 AC 115 ms
40,096 KB
testcase_10 AC 139 ms
41,448 KB
testcase_11 AC 141 ms
41,320 KB
testcase_12 AC 133 ms
40,908 KB
testcase_13 AC 136 ms
41,528 KB
testcase_14 AC 132 ms
41,500 KB
testcase_15 AC 144 ms
41,264 KB
testcase_16 AC 139 ms
41,144 KB
testcase_17 AC 141 ms
41,324 KB
testcase_18 AC 146 ms
41,108 KB
testcase_19 AC 121 ms
40,108 KB
testcase_20 AC 144 ms
41,404 KB
testcase_21 AC 139 ms
41,092 KB
testcase_22 AC 148 ms
41,336 KB
testcase_23 AC 197 ms
41,056 KB
testcase_24 AC 196 ms
41,236 KB
testcase_25 AC 199 ms
41,348 KB
testcase_26 AC 196 ms
41,432 KB
testcase_27 AC 189 ms
41,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main {
    // U M G
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            if (c != 'M') {
                continue;
            }
            for (int j = 0; j < i; j++) {
                char u = s.charAt(j);
                if (u != 'U') {
                    continue;
                }
                int sa = i - j;
                if (sa + i >= n) {
                    continue;
                }
                char g = s.charAt(sa + i);
                if (g == 'G') {
                    ans++;
                }

            }
        }
        System.out.println(ans);
        sc.close();
    }
}
0