Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int NDIRS = 4;
- const int dirI[NDIRS] = {0, 0, -1, 1};
- const int dirJ[NDIRS] = {1, -1, 0, 0};
- void lee(vector<vector<int>> &mat, int si, int sj) {
- auto isIn = [=](size_t i, size_t j)->bool {
- return i >= 0 && i < mat.size() && j >= 0 && j < mat[0].size();
- };
- queue<pair<int, int>> q;
- q.push(make_pair(si, sj));
- while (!q.empty()) {
- int i = q.front().first, j = q.front().second;
- q.pop();
- for (int dir = 0; dir < NDIRS; dir++) {
- int newI = i + dirI[dir];
- int newJ = j + dirJ[dir];
- if (!isIn(newI, newJ)) {
- continue;
- }
- if (mat[newI][newJ] > mat[i][j] + 1) {
- mat[newI][newJ] = mat[i][j] + 1;
- q.push(make_pair(newI, newJ));
- }
- }
- }
- }
- int solve(vector<vector<int>> mat, int k) {
- const int n = mat.size(), m = mat[0].size();
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- if (mat[i][j] == 1) {
- mat[i][j] = 0;
- } else {
- mat[i][j] = 1e9;
- }
- }
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- if (mat[i][j] == 0) {
- lee(mat, i, j);
- }
- }
- }
- //for (auto it : mat) { for (int it2 : it) cerr << it2 << ' '; cerr << endl; }
- int ans = 0;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- if (mat[i][j] > k) {
- ans++;
- }
- }
- }
- return ans;
- }
- int main() {
- vector<vector<int>> a(8, vector<int>(8));
- a[6][6] = a[2][2] = 1;
- cerr << solve(a, 2) << endl;
- return 0;
- }
Advertisement
Advertisement