結果
問題 | No.655 E869120 and Good Triangles |
ユーザー |
![]() |
提出日時 | 2018-02-23 23:30:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,209 ms / 2,500 ms |
コード長 | 1,260 bytes |
コンパイル時間 | 265 ms |
コンパイル使用メモリ | 33,792 KB |
実行使用メモリ | 201,472 KB |
最終ジャッジ日時 | 2024-10-10 02:26:37 |
合計ジャッジ時間 | 22,152 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <cstdio> int dx[] = { 0, 1, 0, -1, 1, -1 }; int dy[] = { 1, 0, -1, 0, -1, 1 }; int N, K, x, y, l, r, qx[8002009], qy[8002009], v[4009][4009], sx[4009][4009], sy[4009][4009]; long long X; int main() { scanf("%d %d %lld", &N, &K, &X); for (int i = 0; i < N; i++) { for (int j = 0; j < N - i; j++) { v[i][j] = -1; } } for (int i = 0; i < K; i++) { scanf("%d %d", &x, &y), x = x - y, y--; if (v[x][y] == -1) v[x][y] = 0, qx[r] = x, qy[r++] = y; } while (l != r) { x = qx[l], y = qy[l++]; for (int i = 0; i < 6; i++) { int tx = x + dx[i], ty = y + dy[i]; if (0 <= tx && tx < N && 0 <= ty && ty < N && 0 <= tx + ty && tx + ty < N && v[tx][ty] == -1) { v[tx][ty] = v[x][y] + 1; qx[r] = tx, qy[r++] = ty; } } } for (int i = 0; i < N; i++) { for (int j = 0; j < N - i; j++) { sx[i][j + 1] = sx[i][j] + v[i][j]; sy[i][j + 1] = sy[i][j] + v[j][i]; } } long long ret = 0; for (int i = 0; i < N; i++) { int cx = i + 1; long long cs = 0; for (int j = 0; j <= i; j++) { while (cx != 0) { int delta = sy[cx - 1][i - cx + 2] - sy[cx - 1][j]; if (cs + delta >= X) break; cs += delta; cx--; } ret += cx; cs -= sx[j][i - j + 1] - sx[j][cx]; } } printf("%lld\n", ret); return 0; }