やるだけ。面倒。
- vector<int> S;
- bool f(int i)
- {
- int x = S[i - 1];
- int y = S[i];
- int z = S[i + 1];
- if (x < y && y > z) return true;
- return false;
- }
- bool g(int begin, int end)
- {
- if (begin == end) return true;
- int diff = S[begin + 1] - S[begin];
- for (int i = begin; i < end; ++i) {
- if (diff != S[i + 1] - S[i]) return false;
- }
- return true;
- }
- class FoxSequence {
- public:
- string isValid(vector <int> S_)
- {
- S = S_;
- for (int a = 1; a < (int)S.size(); ++a) {
- for (int b = a + 1; b < (int)S.size(); ++b) {
- for (int c = b; c < (int)S.size(); ++c) {
- for (int d = c + 1; d + 1 < (int)S.size(); ++d) {
- if (!f(a) || !f(d)) continue;
- if (b < c) {
- if (S[b] == S[b + 1]) ; else continue;
- if (S[c - 1] == S[c]) ; else continue;
- }
- if (g(0, a) && g(a, b) && g(b, c) && g(c, d) && g(d, S.size() - 1)) {
- return "YES";
- }
- }
- }
- }
- }
- return "NO";
- }
- };