1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #include <bits/stdc++.h> #define ll long long #define INF 1e9 using namespace std; int n, m; int dx[9] = {1, 1, 1, -1, -1, -1, 0, 0, 0}; int dy[9] = {0, -1, 1, 0, -1, 1, 0, -1, 1}; bool vis[1005][1005]; bool check(int x, int y) { for (int i = 0; i < 9; i++) { if (!vis[x + dx[i]][y + dy[i]]) return 0; } return 1; } signed main() { ios :: sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; vis[x][y] = 1; for (int j = 0; j < 9; j++) { if (check(x + dx[j], y + dy[j])) { cout << i; return 0; } } } cout << -1; return 0; }
|