Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "CAU4"
- #include <iostream>
- #include <cstdio>
- using namespace std;
- constexpr int N = 1e2 + 5;
- int m, n, t;
- int a[N][N];
- bool keep[N][N]; // Có giữ lại cây này hay không
- void Read()
- {
- cin >> m >> n >> t;
- for (int i = 1; i <= m; ++i)
- for (int j = 1; j <= n; ++j)
- cin >> a[i][j];
- }
- void Solve()
- {
- for (int i = 1; i <= m; ++i)
- for (int j = 1; j <= n; ++j)
- if (a[i][j] != 0) // Có chậu cây ở đây mới xét
- {
- int h = j;
- while (h <= n && a[i][h] == a[i][j])
- ++h;
- if (h - j >= t) // Hàng cây đẹp
- while (j < h)
- {
- keep[i][j] = 1;
- ++j;
- }
- j = h - 1; // Một phép nhảy
- }
- // Làm tương tự với các cột
- for (int i = 1; i <= n; ++i)
- for (int j = 1; j <= m; ++j)
- if (a[j][i] != 0) // Có chậu cây ở đây mới xét
- {
- int h = j;
- while (h <= m && a[h][i] == a[j][i])
- ++h;
- if (h - j >= t) // Hàng cây đẹp
- while (j < h)
- {
- keep[j][i] = 1;
- ++j;
- }
- j = h - 1; // Một phép nhảy
- }
- int ans(0);
- for (int i = 1; i <= m; ++i)
- for (int j = 1; j <= n; ++j)
- if (a[i][j] != 0 && !keep[i][j]) // Có chậu cây ở ô này và nó không thuộc hàng cây tốt nào cả
- ++ans;
- cout << ans;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment