公式

A - Glutton Takahashi 解説 by en_translator


For beginners

If there exists an integer \(i\) between \(1\) and \((N-2)\) such that the \(i\)-th and \((i+1)\)-th dishes to eat are both sweet, he cannot eat the \((i+2)\)-th dish and cannot eat all of the dishes.

Otherwise, he does not get sick until eating the last dish, so he can eat all the dishes.

Note that indices start from \(0\) in the following sample code.

Sample code

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) cin >> s[i];
	string ans = "Yes";
	for (int i = 0; i < n - 2; i++) if (s[i] == "sweet" && s[i + 1] == "sweet") ans = "No";
	cout << ans << '\n';
}

投稿日時:
最終更新: