結果

問題 No.805 UMG
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-03-22 21:34:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 2,216 ms
コンパイル使用メモリ 72,616 KB
実行使用メモリ 56,068 KB
最終ジャッジ日時 2023-08-11 19:10:40
合計ジャッジ時間 7,466 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,840 KB
testcase_01 AC 127 ms
55,680 KB
testcase_02 AC 126 ms
55,784 KB
testcase_03 AC 129 ms
55,496 KB
testcase_04 AC 125 ms
55,672 KB
testcase_05 AC 130 ms
55,532 KB
testcase_06 AC 130 ms
55,768 KB
testcase_07 AC 132 ms
55,864 KB
testcase_08 AC 128 ms
55,740 KB
testcase_09 AC 127 ms
56,040 KB
testcase_10 AC 126 ms
55,500 KB
testcase_11 AC 126 ms
55,708 KB
testcase_12 AC 125 ms
55,716 KB
testcase_13 AC 128 ms
55,496 KB
testcase_14 AC 124 ms
55,688 KB
testcase_15 AC 144 ms
55,908 KB
testcase_16 AC 141 ms
56,064 KB
testcase_17 AC 138 ms
55,548 KB
testcase_18 AC 146 ms
55,688 KB
testcase_19 AC 137 ms
55,676 KB
testcase_20 AC 144 ms
55,468 KB
testcase_21 AC 145 ms
55,492 KB
testcase_22 AC 145 ms
56,068 KB
testcase_23 AC 184 ms
55,692 KB
testcase_24 AC 185 ms
55,868 KB
testcase_25 AC 184 ms
55,504 KB
testcase_26 AC 184 ms
55,764 KB
testcase_27 AC 184 ms
56,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ans = 0;
        int n = sc.nextInt();
        String s = sc.next();
        for(int j = 1; j < n; j++) {
            if(s.charAt(j) == 'M') {
                for(int dist = 1; dist < n; dist++) {
                    int i = j - dist;
                    int k = j + dist;
                    if(0 <= i && k < n) {
                        if(s.charAt(i) == 'U' && s.charAt(k) == 'G') {
                            ans++;
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }
}
0