結果

問題 No.805 UMG
ユーザー kohaku_kohaku
提出日時 2019-03-22 21:34:23
言語 Java
(openjdk 23)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 2,042 ms
コンパイル使用メモリ 74,228 KB
実行使用メモリ 54,480 KB
最終ジャッジ日時 2024-11-18 13:15:46
合計ジャッジ時間 7,141 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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