結果
問題 | No.805 UMG |
ユーザー |
|
提出日時 | 2019-03-22 22:13:03 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 856 bytes |
コンパイル時間 | 677 ms |
コンパイル使用メモリ | 87,328 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-18 13:26:25 |
合計ジャッジ時間 | 1,594 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; | ^~~
ソースコード
#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 a = 0; a < M.size(); a++) { int j = M[a]; int i = M[a] - 1; int k = M[a] + 1; while(i >= 0 && k < n) { //cout << "i, j, k = " << i << ", " << j << ", " << k << endl; if(s[i] == 'U' && s[k] == 'G') { ans += 1; } i--; k++; } } cout << ans << endl; }