求助
查看原帖
求助
1200191
封禁用户楼主2024/12/22 10:23
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n, s;
int main() {
	cin >> n >> s;
	vector<pair<int, int> > board(n + 1);
	for (int i = 1; i <= n; ++i) {
		int qi, vi;
		cin >> qi >> vi;
		board[i] = {qi, vi};
	}
	int cnt = 1;
	ll pos = s;
	bool d = true;
	set<int> v;
	set<int> bt;
	while (pos >= 1 && pos <= n) {
		if (v.find(pos) != v.end()) {
			break;
		}
		v.insert(pos);

		if (board[pos].first == 0) {
			cnt += board[pos].second;
			d = !d;
		} else if (board[pos].first == 1 && cnt >= board[pos].second) {
			bt.insert(pos);
		}

		if (d) {
			pos += cnt;
		} else {
			pos -= cnt;
		}

		if (pos < 1 || pos > n) {
			break;
		}
	}
	cout << bt.size() << "\n";
	return 0;
}





2024/12/22 10:23
加载中...