結果

問題 No.655 E869120 and Good Triangles
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-02-25 23:48:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,048 ms / 2,500 ms
コード長 3,490 bytes
コンパイル時間 1,753 ms
コンパイル使用メモリ 174,784 KB
実行使用メモリ 355,068 KB
最終ジャッジ日時 2023-07-31 09:31:45
合計ジャッジ時間 20,180 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,444 KB
testcase_01 AC 2 ms
7,468 KB
testcase_02 AC 2 ms
7,544 KB
testcase_03 AC 3 ms
7,552 KB
testcase_04 AC 2 ms
7,548 KB
testcase_05 AC 2 ms
7,484 KB
testcase_06 AC 2 ms
7,480 KB
testcase_07 AC 2 ms
7,504 KB
testcase_08 AC 2 ms
7,460 KB
testcase_09 AC 2 ms
7,536 KB
testcase_10 AC 1,048 ms
334,720 KB
testcase_11 AC 939 ms
334,648 KB
testcase_12 AC 878 ms
351,384 KB
testcase_13 AC 891 ms
354,784 KB
testcase_14 AC 886 ms
355,024 KB
testcase_15 AC 912 ms
354,752 KB
testcase_16 AC 960 ms
354,740 KB
testcase_17 AC 963 ms
354,748 KB
testcase_18 AC 939 ms
355,068 KB
testcase_19 AC 919 ms
354,956 KB
testcase_20 AC 966 ms
354,568 KB
testcase_21 AC 961 ms
354,816 KB
testcase_22 AC 859 ms
354,696 KB
testcase_23 AC 880 ms
354,816 KB
testcase_24 AC 650 ms
352,628 KB
testcase_25 AC 632 ms
352,584 KB
testcase_26 AC 630 ms
352,644 KB
testcase_27 AC 728 ms
352,720 KB
testcase_28 AC 610 ms
352,904 KB
testcase_29 AC 707 ms
352,708 KB
testcase_30 AC 2 ms
7,436 KB
testcase_31 AC 3 ms
7,476 KB
testcase_32 AC 2 ms
7,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/





int N, K; ll P;
ll A[4040][4040];
//---------------------------------------------------------------------------------------------------
int dx[6] = { -1, -1, 0, 1, 1, 0 }, dy[6] = { 0, -1, -1, 0, 1, 1 };
void bfs() {
    rep(y, 0, N) rep(x, 0, y + 1) A[y][x] = inf;
    queue<pair<int, int>> que;
    rep(i, 0, K) {
        int x, y; cin >> y >> x;
        x--; y--;
        A[y][x] = 0;
        que.push({ x, y });
    }

    while (!que.empty()) {
        auto q = que.front(); que.pop();
        int x, y;
        tie(x, y) = q;

        rep(d, 0, 6) {
            int xx = x + dx[d];
            int yy = y + dy[d];
            if (0 <= yy and yy < N and 0 <= xx and xx <= yy) {
                if (A[yy][xx] == inf) {
                    A[yy][xx] = A[y][x] + 1;
                    que.push({ xx, yy });
                }
            }
        }
    }
}
//---------------------------------------------------------------------------------------------------
ll B[4040][4040], C[4040][4040];
void pre() {
    rep(y, 0, N) rep(x, 0, y + 1) B[y][x] = A[y][x];
    rrep(y, N - 1, 0) rep(x, 0, y + 1) {
        if (x) B[y][x] += B[y][x - 1];
        if (y < N - 1) B[y][x] += B[y + 1][x];
        if (x and y < N - 1) B[y][x] -= B[y + 1][x - 1];
    }

    rep(y, 0, N) rep(x, 0, y + 1) C[y][x] = A[y][x];
    rrep(y, N - 2, 0) rep(x, 0, y + 1) {
        C[y][x] += C[y + 1][x + 1];
        C[y][x] += B[y + 1][x];
        if (x) C[y][x] -= B[y + 1][x - 1];
    }
}
ll get(int x, int y, int k) {
    ll res = C[y][x];
    
    int yy = y + k;
    if (N <= yy) return res;

    res -= C[y + k][x + k];
    res -= B[y + k][x + k - 1];
    if (x) res += B[y + k][x - 1];

    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K >> P;

    bfs();
    pre();

    ll ans = 0;
    rep(y, 0, N) rep(x, 0, y + 1) {
        int KK = (N - y);
        if (P <= get(x, y, 1)) ans += KK;
        else {
            int ng = 1, ok = KK + 1;
            while (ng + 1 != ok) {
                int md = (ng + ok) / 2;
                if (P <= get(x, y, md)) ok = md;
                else ng = md;
            }
            ans += KK - ok + 1;
        }
    }
    cout << ans << endl;
}
0