这题需要二分吗???
查看原帖
这题需要二分吗???
1371852
jasonyjm楼主2024/7/4 19:55

RT 附代码

#include<bits/stdc++.h>
#define int long long
#define fast register int 

using namespace std;

const int N=5e3+100;

int n,m,ans=0,cnt=0,x[N],y[N],d1=0,d2=0,k;

struct qwq{
	int xx,yy;
}a[N*N];

signed main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin>>n>>m;
	for (fast i=1;i<=n;i++){
		for (fast j=1;j<=n;j++){
			cnt++;
			a[cnt].xx=i,a[cnt].yy=j;
		}
	}
	for (fast i=1;i<=m;i++){
		cin>>k;
		x[a[k].xx]++;
		y[a[k].yy]++;
		if (a[k].xx-a[k].yy==0){
			d1++;
		}
		if (a[k].xx+a[k].yy==n+1){
			d2++;
		}
		if (d1==n||d2==n||x[a[k].xx]==n||y[a[k].yy]==n){
			cout<<i;
			return 0;
		}
	}
	cout<<-1;
	return 0;
} 
2024/7/4 19:55
加载中...