Official

B - Go to Jail Editorial by evima


It is sufficient to check the conditions described in the problem statement for all \(i\). Once such \(i\) is found, you can output Yes on the spot and terminate the program. Be careful of the range of the loop.

Sample Code (C++)

#include <iostream>
using namespace std;

int main(){
	int n;
	cin >> n;
	int a[100][2];
	for (int i=0; i<n; i++){
		cin >> a[i][0] >> a[i][1];
	}
	// Be careful when the loop ends
	for (int i=0; i<n-2; i++){
		if(a[i][0]==a[i][1] && a[i+1][0]==a[i+1][1] && a[i+2][0]==a[i+2][1]){
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}

posted:
last update: