結果

問題 No.655 E869120 and Good Triangles
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-02-25 23:39:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,568 bytes
コンパイル時間 1,990 ms
コンパイル使用メモリ 172,552 KB
実行使用メモリ 152,848 KB
最終ジャッジ日時 2024-04-18 09:52:27
合計ジャッジ時間 6,158 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
10,624 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 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
int 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 });
                }
            }
        }
    }
}
//---------------------------------------------------------------------------------------------------
int 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];
    }
}
int get(int x, int y, int k) {
    int 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();

    /*rep(y, 0, N) { rep(x, 0, y + 1) printf("%d ", A[y][x]); printf("\n"); }
    rep(y, 0, N) { rep(x, 0, y + 1) printf("%d ", B[y][x]); printf("\n"); }
    rep(y, 0, N) { rep(x, 0, y + 1) printf("%d ", C[y][x]); printf("\n"); }*/

    int ans = 0;
    rep(y, 0, N) rep(x, 0, y + 1) rep(k, 1, (N - y) + 1) {
        int cn = get(x, y, k);
        //printf("<%d %d %d> %d\n", x, y, k, cn);
        if (P <= cn) ans++;
    }
    cout << ans << endl;

    //cout << get(0, 2, 2) << endl;
}
0