結果
問題 | No.805 UMG |
ユーザー |
![]() |
提出日時 | 2019-03-22 21:26:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 3,974 bytes |
コンパイル時間 | 827 ms |
コンパイル使用メモリ | 103,512 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 13:13:03 |
合計ジャッジ時間 | 1,785 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
// IO library#include <cstdio>#include <iomanip>#include <ios>#include <iostream>// algorithm library#include <algorithm>#include <cmath>#include <numeric>#include <random>// contancer library#include <bitset>#include <deque>#include <map>#include <queue>#include <set>#include <string>#include <tuple>#include <vector>#include <functional>#include <limits>using ll = long long;using ld = long double;/* ----- Output Functions for Debugging ----- */template <class T>std::ostream& operator<<(std::ostream& os, std::vector<T> v);template <class T>std::ostream& operator<<(std::ostream& os, std::set<T> v);template <class L, class R>std::ostream& operator<<(std::ostream& os, std::pair<L, R> p);template <class K, class T>std::ostream& operator<<(std::ostream& os, std::map<K, T> v);template <class T>std::ostream& operator<<(std::ostream& os, std::queue<T> q);template <class T>std::ostream& operator<<(std::ostream& os, std::priority_queue<T> q);template <class T>std::ostream& operator<<(std::ostream& os, std::vector<T> v) {os << "[";for (auto vv : v) os << vv << ",";return os << "]";}template <class T>std::ostream& operator<<(std::ostream& os, std::set<T> v) {os << "{";for (auto vv : v) os << vv << ",";return os << "}";}template <class L, class R>std::ostream& operator<<(std::ostream& os, std::pair<L, R> p) {return os << "(" << p.first << "," << p.second << ")";}template <class K, class T>std::ostream& operator<<(std::ostream& os, std::map<K, T> v) {os << "{";for (auto vv : v) os << vv << ",";return os << "}";}template <class T>std::ostream& operator<<(std::ostream& os, std::queue<T> q) {os << "[";while (!q.empty()) {os << q.front() << ",";q.pop();}return os << "]";}template <class T>std::ostream& operator<<(std::ostream& os, std::priority_queue<T> q) {os << "{";while (!q.empty()) {os << q.top() << ",";q.pop();}return os << "}";}/* ----- Short Functions ----- */template <class T>T Vec(T v) { return v; }template <class T, class... Ts>auto Vec(size_t l, Ts... ts) {return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));}template <class T>inline T sq(T a) { return a * a; }template <class T>inline T iceil(T n, T d) { return (n + d - 1) / d; }template <class T>T gcd(T a, T b) {while (b > 0) {a %= b;swap(a, b);}return a;}template <class T, class U>T ipow(T b, U n) {T ret = 1;while (n > 0) {if (n & 1) ret *= b;n >>= 1;b *= b;}return ret;}// 0-indexedtemplate <class T, class U>inline T kthbit(T a, U k) { return (a >> k) & 1; }template <class T, class U>inline T mask(T a, U k) { return a & ((1 << k) - 1); }/* ----- class ----- */template <class T>struct Edge {int from, to;T cost;Edge(int from = -1, int to = -1, T cost = 1) : from(from), to(to), cost(cost){};bool operator<(const Edge<T>& e) const { return this->cost < e.cost; }bool operator>(const Edge<T>& e) const { return this->cost > e.cost; }};template <class T = int>class Graph {public:explicit Graph(int N = 0) : size(N) { path.resize(size); }void span(int u, int v, T cost = 1) { path[u].push_back(Edge<T>(u, v, cost)); }std::vector<Edge<T>> operator[](int v) const { return path[v]; }int size;std::vector<std::vector<Edge<T>>> path;};/* ----- Constants ----- */// const int INF = 1 << 25;// const ll INF = 1LL << 50;// const ld PI = acos(-1);// const ld EPS = 1e-10;// mt19937 mt(ll(time(0)));int main() {int N;std::string S;std::cin >> N >> S;int ans = 0;for (int k = 1; k <= N; ++k) {for (int i = 0; i + k * 2 < N; ++i) {if (S[i] == 'U' && S[i + k] == 'M' && S[i + k * 2] == 'G') ++ans;}}std::cout << ans << std::endl;return 0;}