結果

問題 No.805 UMG
コンテスト
ユーザー Grenache
提出日時 2019-04-26 17:07:52
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 747 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,703 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 43,380 KB
最終ジャッジ日時 2026-05-13 01:39:46
合計ジャッジ時間 5,368 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.*;
import java.util.Scanner;


public class Main_yukicoder805 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();

		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 1; i + j + j < n; j++) {
				if (s[i] == 'U' && s[i + j] == 'M' && s[i + j + j] == 'G') {
					ans++;
				}
			}
		}
		
		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
0