結果

問題 No.805 UMG
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-03-22 21:34:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 74,648 KB
実行使用メモリ 41,856 KB
最終ジャッジ日時 2024-04-29 10:30:52
合計ジャッジ時間 7,191 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
41,196 KB
testcase_01 AC 133 ms
40,968 KB
testcase_02 AC 132 ms
41,220 KB
testcase_03 AC 133 ms
41,344 KB
testcase_04 AC 134 ms
41,436 KB
testcase_05 AC 135 ms
41,296 KB
testcase_06 AC 131 ms
41,376 KB
testcase_07 AC 132 ms
41,348 KB
testcase_08 AC 131 ms
41,616 KB
testcase_09 AC 134 ms
41,476 KB
testcase_10 AC 118 ms
40,016 KB
testcase_11 AC 131 ms
41,180 KB
testcase_12 AC 132 ms
41,220 KB
testcase_13 AC 129 ms
40,996 KB
testcase_14 AC 130 ms
41,220 KB
testcase_15 AC 150 ms
41,308 KB
testcase_16 AC 148 ms
41,600 KB
testcase_17 AC 150 ms
41,248 KB
testcase_18 AC 157 ms
41,844 KB
testcase_19 AC 146 ms
41,064 KB
testcase_20 AC 153 ms
41,224 KB
testcase_21 AC 144 ms
41,656 KB
testcase_22 AC 152 ms
41,824 KB
testcase_23 AC 193 ms
41,740 KB
testcase_24 AC 197 ms
41,336 KB
testcase_25 AC 190 ms
41,856 KB
testcase_26 AC 188 ms
41,540 KB
testcase_27 AC 197 ms
41,288 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