結果

問題 No.655 E869120 and Good Triangles
ユーザー 193s193s
提出日時 2018-02-25 21:37:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,009 ms / 2,500 ms
コード長 1,825 bytes
コンパイル時間 1,048 ms
コンパイル使用メモリ 102,404 KB
実行使用メモリ 318,336 KB
最終ジャッジ日時 2024-04-18 09:52:59
合計ジャッジ時間 18,377 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 961 ms
318,040 KB
testcase_11 AC 903 ms
318,080 KB
testcase_12 AC 932 ms
318,184 KB
testcase_13 AC 850 ms
318,336 KB
testcase_14 AC 810 ms
318,336 KB
testcase_15 AC 872 ms
318,284 KB
testcase_16 AC 929 ms
318,080 KB
testcase_17 AC 1,001 ms
318,336 KB
testcase_18 AC 914 ms
318,208 KB
testcase_19 AC 980 ms
318,208 KB
testcase_20 AC 910 ms
318,204 KB
testcase_21 AC 1,009 ms
318,228 KB
testcase_22 AC 881 ms
318,208 KB
testcase_23 AC 934 ms
318,336 KB
testcase_24 AC 542 ms
316,160 KB
testcase_25 AC 586 ms
316,216 KB
testcase_26 AC 582 ms
316,160 KB
testcase_27 AC 626 ms
315,904 KB
testcase_28 AC 573 ms
316,160 KB
testcase_29 AC 588 ms
316,160 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0