結果
| 問題 |
No.655 E869120 and Good Triangles
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-02-25 21:37:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,114 ms / 2,500 ms |
| コード長 | 1,825 bytes |
| コンパイル時間 | 1,132 ms |
| コンパイル使用メモリ | 100,316 KB |
| 実行使用メモリ | 318,388 KB |
| 最終ジャッジ日時 | 2024-10-10 03:05:35 |
| 合計ジャッジ時間 | 20,397 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
const int DX[6] = {-1, -1, 0, 1, 1, 0};
const int DY[6] = {0, -1, -1, 0, 1, 1};
int N, M;
long long K;
int A[4000][4000];
long long TX[4001][4001], TY[4001][4001];
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> M >> K;
rep(i, N) rep(j, N) A[i][j] = INF;
queue<P> q;
rep(i, M) {
int x, y;
cin >> y >> x;
x--, y--;
A[x][y] = 0;
q.push(P(x, y));
}
while (!q.empty()) {
P x = q.front(); q.pop();
rep(k, 6) {
P nx = P(x._1+DX[k], x._2+DY[k]);
if (0 <= nx._1 && nx._1 < N && 0 <= nx._2 && nx._2 < N && nx._1 <= nx._2 && A[nx._1][nx._2] == INF) {
A[nx._1][nx._2] = A[x._1][x._2]+1;
q.push(nx);
}
}
}
rep(x, N) rep(y, N) TX[x][y] = TY[x][y] = A[x][y];
rep(x, N-1) rep(y, N) TX[x+1][y] += TX[x][y];
rep(x, N) rep(y, N-1) TY[x][y+1] += TY[x][y];
long long ans = 0;
rep(sx, N) {
int x = sx, y = N-1, h = N-1;
long long cur = 0;
while (x>=0&&y>=0) {
cur += TY[x][h]-(y>0?TY[x][y-1]:0);
while (y <= h-1) {
long long s = TX[x+h-y][h]-(x>0?TX[x-1][h]:0);
if (cur-s < K) break;
h--, cur -= s;
}
if (cur >= K) ans += N-h;
x--, y--;
}
}
cout << ans << "\n";
return 0;
}