結果

問題 No.805 UMG
ユーザー htensaihtensai
提出日時 2019-11-11 19:00:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 72,060 KB
実行使用メモリ 56,232 KB
最終ジャッジ日時 2023-08-11 19:43:10
合計ジャッジ時間 7,012 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,876 KB
testcase_01 AC 133 ms
55,860 KB
testcase_02 AC 125 ms
55,740 KB
testcase_03 AC 122 ms
55,748 KB
testcase_04 AC 127 ms
55,828 KB
testcase_05 AC 126 ms
56,136 KB
testcase_06 AC 120 ms
56,232 KB
testcase_07 AC 123 ms
55,348 KB
testcase_08 AC 124 ms
55,612 KB
testcase_09 AC 125 ms
55,760 KB
testcase_10 AC 126 ms
55,988 KB
testcase_11 AC 124 ms
55,804 KB
testcase_12 AC 126 ms
54,036 KB
testcase_13 AC 128 ms
55,684 KB
testcase_14 AC 127 ms
55,640 KB
testcase_15 AC 130 ms
55,812 KB
testcase_16 AC 128 ms
55,676 KB
testcase_17 AC 126 ms
55,836 KB
testcase_18 AC 132 ms
55,888 KB
testcase_19 AC 125 ms
55,640 KB
testcase_20 AC 129 ms
55,884 KB
testcase_21 AC 129 ms
53,816 KB
testcase_22 AC 124 ms
55,896 KB
testcase_23 AC 154 ms
56,116 KB
testcase_24 AC 162 ms
55,800 KB
testcase_25 AC 154 ms
55,668 KB
testcase_26 AC 156 ms
55,568 KB
testcase_27 AC 156 ms
55,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static TreeSet<Integer> primes;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int count = 0;
		for (int i = 0; i < n; i++) {
		    if (arr[i] != 'U') {
		        continue;
		    }
		    for (int j = 1; i + j * 2 < n; j++) {
		        if (arr[i + j] == 'M' && arr[i + j * 2] == 'G') {
		            count++;
		        }
		    }
		    
		}
		System.out.println(count);
	}
}
0