結果

問題 No.805 UMG
ユーザー htensaihtensai
提出日時 2019-11-11 19:00:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 74,592 KB
実行使用メモリ 41,820 KB
最終ジャッジ日時 2024-04-29 11:01:17
合計ジャッジ時間 6,517 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
41,180 KB
testcase_01 AC 121 ms
41,092 KB
testcase_02 AC 121 ms
41,372 KB
testcase_03 AC 110 ms
41,248 KB
testcase_04 AC 111 ms
41,420 KB
testcase_05 AC 125 ms
41,348 KB
testcase_06 AC 121 ms
41,640 KB
testcase_07 AC 123 ms
41,080 KB
testcase_08 AC 125 ms
41,772 KB
testcase_09 AC 126 ms
41,360 KB
testcase_10 AC 121 ms
41,420 KB
testcase_11 AC 120 ms
41,636 KB
testcase_12 AC 119 ms
41,068 KB
testcase_13 AC 122 ms
41,128 KB
testcase_14 AC 122 ms
41,168 KB
testcase_15 AC 115 ms
41,428 KB
testcase_16 AC 123 ms
41,544 KB
testcase_17 AC 112 ms
41,280 KB
testcase_18 AC 117 ms
41,304 KB
testcase_19 AC 124 ms
40,232 KB
testcase_20 AC 131 ms
41,184 KB
testcase_21 AC 128 ms
41,064 KB
testcase_22 AC 129 ms
41,080 KB
testcase_23 AC 168 ms
41,332 KB
testcase_24 AC 169 ms
41,396 KB
testcase_25 AC 148 ms
41,424 KB
testcase_26 AC 152 ms
41,820 KB
testcase_27 AC 165 ms
41,312 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