跳到正文

题解

题解:AT_abc355_c [ABC355C] Bingo 2

kevinZ99约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 3 分钟

版本

  1. v1当前

思路

很明显暴力超时,如何优化呢?

先考虑行,每一行有什么特点,所有行数都一样,那么直接开一个桶记录,记录这一行出现了几个数字。

列同理。

接下来考虑两个对角线。

左上到右下,很明显行数等于列数,那么开桶记录。

另一条对角线与左上到右下相似,请读者自行完成。

另一条对角线就是把列数倒过来就行了。

代码

C++
//Author:Kevin Z K Y
#include <bits/stdc++.h>
#define putendl putchar('\n')
#define putspace putchar(' ')
#define up(a,b,c) for(int (a)=(b);(a)<=(c);(a)++)
#define dn(a,b,c) for(int (a)=(b);(a)>=(c);(a)--)
#define fst first
#define sed second
using namespace std;
using ll = long long ;
using hint = __int128 ;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;
using vi = vector<int> ;
using vl = vector<ll> ;
using vpi = vector<pair<int,int>> ;
using vpl = vector<pair<ll,ll>>;
using db = double ;
const double eps=1e-6;
namespace __STL{
	ll max(ll x,ll y){return x>=y?x:y;}
    ll min(ll x,ll y){return x<=y?x:y;}
    ll abs(ll x){return x<=0?-x:x;}
}
using namespace __STL;
namespace my{
	const int N=2005;
	string ot;
	int n,q;
	int col[N],row[N],s[2];
	void solve(){
		cin>>n>>q;
		up(d,1,q){
			int x;cin>>x;
			int i=x/n+1,j=x-(i-1)*n;
			if(x%n==0)i=x/n,j=n;
//			cout<<i<<' '<<j<<'\n';
			col[j]++;
			row[i]++;
			if(i==j)s[0]++;
			if(i==n-j+1)s[1]++;
			if(col[j]==n||row[i]==n||s[0]==n||s[1]==n){
				cout<<d<<'\n';
				return ;
			}
		}
		cout<<"-1\n";
	}
}
int main(){
//  freopen("","r",stdin);
//  freopen("","w",stdout);
	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
	int _=1;
	while(_--)my::solve();return 0;
}
原文