#include #include #include #include using namespace std; int main() { int n, K; long long p; cin >> n >> K >> p; vector> dist(n, vector(n, -1)); queue> q; for (int i = 0; i < K; i++) { int y, x; cin >> y >> x; y--; x--; dist[y][x] = 0; q.emplace(y, x); } while (!q.empty()) { int y = q.front().first; int x = q.front().second; q.pop(); int dy[] = {1, 1, 0, -1, -1, 0}; int dx[] = {0, 1, 1, 0, -1, -1}; for (int k = 0; k < 6; k++) { int ny = y + dy[k]; int nx = x + dx[k]; if (ny < 0 || nx < 0 || nx > ny || ny >= n) continue; if (dist[ny][nx] == -1) { dist[ny][nx] = dist[y][x] + 1; q.emplace(ny, nx); } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (dist[i][j] == -1) dist[i][j] = 0; } } #ifdef FOO for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << dist[i][j]; cout << ' '; } cout << endl; } cout << endl; #endif vector> sum(n + 1, vector(n + 1)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { sum[i + 1][j + 1] = dist[i][j] + sum[i + 1][j] + sum[i][j + 1] - sum[i][j]; } } #ifdef FOO for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { cout << sum[i][j]; cout << ' '; } cout << endl; } cout << endl; #endif vector> tri(n, vector(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { tri[i][j] = dist[i][j]; if (i - 1 >= 0 && j - 1 >= 0) { tri[i][j] += tri[i - 1][j - 1]; } if (j - 1 >= 0) { tri[i][j] += tri[i][j - 1]; } if (i - 1 >= 0 && j - 2 >= 0) { tri[i][j] -= tri[i - 1][j - 2]; } } } #ifdef FOO for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << tri[i][j]; cout << ' '; } cout << endl; } cout << endl; #endif vector> shaku(n + 1, vector(n + 1)); long long ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { int ng = i - 1; int ok = n; shaku[i][j] = max(shaku[i][j], i); auto f = [&](int k) { int d = k - i; long long hoge = tri[k][j + d]; hoge -= sum[k + 1][j] - sum[i + 1][j]; hoge -= tri[i][j]; hoge += dist[i][j]; return hoge; }; int &k = shaku[i][j]; while (k < n && f(k) < p) { k++; } shaku[i + 1][j] = max(shaku[i + 1][j], shaku[i][j]); shaku[i + 1][j + 1] = max(shaku[i + 1][j + 1], shaku[i][j]); #ifdef FOO for (int k = ok; k < n; k++) { printf("%d %d %d %lld\n", i, j, k, f(k)); } #endif ans += n - shaku[i][j]; } } cout << ans << endl; }