Open utterances-bot opened 1 year ago
AC
```cpp
#include
Sao em dùng cấp phát động mà không đc vậy ạ
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
// const int N = 1e6+2;
int n, m, res(0), b(2);
int main()
{
fast();
cin >> n >> m;
vector<vector<int>> a;
a.resize(n);
for (int i = 0; i < n; i++)
{
a[i].resize(m);
for (int j = 0; j < m; j++)
cin >> a[i][j];
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
if (a[i][j] == 1)
{
res++;
int xi = i - 1, yj = j - 1;
for (int k = 0; k < 9; k++)
{
if ((xi >= 0 && xi < n) && (yj >= 0 && yj < m))
if (a[xi][yj] == 0)
res++, a[xi][yj] = b;
yj++;
if (yj == j + 2)
yj = j - 1, xi++;
}
}
}
cout << res;
return 0;
}
Sử dụng mảng tĩnh
```ruby
#include
Cấp phát động
```ruby
#include
mn tham khảo code bằng python 3:
dx = [-1, -1, -1, 0, 0, 1, 1, 1] dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n, m = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(n)]
cl = 2 res = 0 for i in range(n): for j in range(m): if a[i][j] == 1: res += 1 for k in range(8): x = i + dx[k] y = j + dy[k] if 0 <= x < n and 0 <= y < m and a[x][y] == 0: res += 1 a[x][y] = cl cl += 1
print(res)
Chi tiết bài tập - Luyện Code Online
https://oj.luyencode.net/problem/Baovebaibien