Source Code
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define f first
#define s second
using namespace std;

pair <char, int>a[100002];
void solve() {
	int n;
	cin >> n;
	cin >> a[0].f >> a[0].s;
	for (int i = 1; i < n; i++) {
		cin >> a[i].f >> a[i].s;
	}
	if (a[0].f == '*' || a[n - 1].f == '*') {
		cout << "NO";
		return;
	}
	int k = 0;
	for (int i = 0; i < n - 1; i++) {
		if (a[i].f == '#') {
			bool check = false;
			for (int j = i + 1; j < i + 3; j++) {
				if (a[j].s - a[i].s > 2) {
					cout << "NO";
					return;
				}
				if (a[j].f == '#') {
					if (!check) {
						k = j;
						check = true;
					}
					else {
						if (a[k].s - a[i].s <= a[j].s - a[i].s) {
							k = j;
						}
					}
				}
			}
			if (!check) {
				cout << "NO";
				return;
			}
			
		}
		i = k - 1;
	}
	cout << "YES";
}

int main() {
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
}
Copy
Path of Pain lafi-Odeh
GNU G++17
14 ms
1.3 MB
Wrong Answer