結果
| 問題 | 
                            No.805 UMG
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Arc
                         | 
                    
| 提出日時 | 2019-03-22 22:22:22 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 5 ms / 2,000 ms | 
| コード長 | 874 bytes | 
| コンパイル時間 | 776 ms | 
| コンパイル使用メモリ | 77,664 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-18 13:26:53 | 
| 合計ジャッジ時間 | 1,600 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}
int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n;
  std::string s;
  cin >> n >> s;
  int result = 0;
  for (int center = 1; center < n - 1; center++) {
    if (s[center] == 'M') {
      int width = 1;
      while (center - width >= 0 && center + width < n) {
        int left = center - width, right = center + width;
        if (s[left] == 'U' && s[right] == 'G') {
          result++;
        }
        width++;
      }
    }
  }
  cout << result << endl;
  return 0;
}
            
            
            
        
            
Arc