75分TLE dalao求条!
查看原帖
75分TLE dalao求条!
1112707
liruwang楼主2025/8/4 20:06
#include<bits/stdc++.h>
using namespace std;
int n,m,b[100100],c[100100];
struct asd{
	int q,w;
}a[100100];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		if(x==0){
			a[i].q=y;
			a[i].w=1;
		}
		else{
			a[i].q=y;
			a[i].w=2;
		}
	}
	int j,k,ans=0;
	j=1;
	k=1;
	int l=m;
	while(l>=1&&l<=n){
		if(k==b[l]&&j==c[l]){
			break;
		}
		if(a[l].w==2&&a[l].q<=j){
			a[l].w=0;
			ans++;
		}
		else if(a[l].w==1){
			if(k==1)k=2;
			else if(k==2){
				k=1;
			}
			j+=a[l].q;
		}
		b[l]=k;
		c[l]=j;
		if(k==1){
			l+=j;
		}
		if(k==2){
			l-=j;
		}
	}
	cout<<ans;
	return 0;
}
2025/8/4 20:06
加载中...