結果

問題 No.805 UMG
ユーザー CELICA
提出日時 2020-09-29 08:27:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 1,717 ms
コンパイル使用メモリ 174,352 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-18 14:06:46
合計ジャッジ時間 2,456 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ll n;
	string s;
	cin >> n >> s;

	vector<int> u, m;
	set<int> g;
	for (int i = 0; i < n; ++i)
	{
		if (s[i] == 'U')
			u.push_back(i);
		else if (s[i] == 'M')
			m.push_back(i);
		else if (s[i] == 'G')
			g.insert(i);
	}

	ll res{ 0 };
	for (const auto& itu : u)
	{
		for (auto itm =m.crbegin();itm!=m.crend();++itm)
		{
			if (itu > *itm)
				break;
			int k = *itm * 2 - itu;
			if (g.count(k))
				++res;
		}
	}

	cout << res << "\n";

	return 0;
}
0