跳到正文

题解

AT_abc355_c 题解

Vitamin_B约 1 分钟
原文
文章信息与版本

文章信息

发布
2024年5月26日
收录
2025年12月12日
更新
2026年11月9日
篇幅
约 1 分钟
获赞
2

版本

  1. v1当前

思路

首先 aia_i 是第 ⌊ai−1n⌋\lfloor\frac{a_i-1}{n}\rfloor 行第 (ai−1) mod n(a_i-1)\bmod n 列的(此处均为 00 开始),然后每次添加点肯定不用整个都判断,只需要判断更改的部分即可。

代码

C++
# include <bits/stdc++.h>
# define done {cout << i; return 0;}
using namespace std;
int n, t, x, y, sh[3005], sl[3005], s1, s2;
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> n >> t;
	for (int i = 1; i <= t; ++ i) {
		cin >> x;
		-- x, y = x % n, x /= n;
		if (++ sh[x] >= n)
			done;
		if (++ sl[y] >= n)
			done;
		if (x == y && ++ s1 >= n)
			done;
		if (x == n - y - 1 && ++ s2 >= n)
			done;
	}
	cout << "-1";
	return 0;
}
原文