結果

問題 No.805 UMG
ユーザー masaemonmasaemon
提出日時 2019-03-22 22:07:13
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 700 bytes
コンパイル時間 992 ms
コンパイル使用メモリ 87,336 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-18 13:25:56
合計ジャッジ時間 1,681 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 2 WA * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:17: warning: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   27 |         cout << ans << endl;
      |                 ^~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <limits>
#include <iomanip>

using namespace std;

int main() {
    int n;
    int ans;
    string s;
    cin >> n;
    cin >> s;
    vector<int>M;
    for(int i = 0; i < n; i++){
        if(s[i] == 'M') M.push_back(i);
    }

    if(M.size() == 0) {
        cout << ans << endl;
        return 0;
    }

    for(int i = 0; i < M.size(); i++) {
        int d = 1;
        while(M[i] - d > 0 || M[i] + d <= n) {
            if(s[M[i]-d] == 'U' && s[M[i]+d] =='G') ans += 1;
            d++;
        }
    }

    cout << ans << endl;
}
0