結果

問題 No.655 E869120 and Good Triangles
ユーザー parukiparuki
提出日時 2018-02-24 12:57:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,202 ms / 2,500 ms
コード長 2,654 bytes
コンパイル時間 1,744 ms
コンパイル使用メモリ 172,188 KB
実行使用メモリ 165,936 KB
最終ジャッジ日時 2024-04-18 09:45:42
合計ジャッジ時間 20,650 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
65,920 KB
testcase_01 AC 25 ms
66,048 KB
testcase_02 AC 19 ms
66,048 KB
testcase_03 AC 19 ms
66,048 KB
testcase_04 AC 19 ms
66,048 KB
testcase_05 AC 17 ms
66,048 KB
testcase_06 AC 21 ms
66,176 KB
testcase_07 AC 19 ms
66,176 KB
testcase_08 AC 18 ms
66,048 KB
testcase_09 AC 20 ms
66,176 KB
testcase_10 AC 1,043 ms
165,696 KB
testcase_11 AC 937 ms
165,936 KB
testcase_12 AC 975 ms
165,740 KB
testcase_13 AC 934 ms
164,624 KB
testcase_14 AC 1,202 ms
164,732 KB
testcase_15 AC 970 ms
165,788 KB
testcase_16 AC 1,023 ms
165,460 KB
testcase_17 AC 1,121 ms
164,152 KB
testcase_18 AC 1,024 ms
164,968 KB
testcase_19 AC 1,091 ms
165,904 KB
testcase_20 AC 994 ms
164,540 KB
testcase_21 AC 1,023 ms
164,076 KB
testcase_22 AC 1,143 ms
162,516 KB
testcase_23 AC 1,006 ms
165,232 KB
testcase_24 AC 528 ms
156,416 KB
testcase_25 AC 467 ms
156,672 KB
testcase_26 AC 516 ms
156,672 KB
testcase_27 AC 571 ms
156,544 KB
testcase_28 AC 454 ms
156,544 KB
testcase_29 AC 497 ms
156,672 KB
testcase_30 AC 24 ms
66,048 KB
testcase_31 AC 22 ms
66,048 KB
testcase_32 AC 18 ms
65,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int N, K;
ll P;
int X[4001], Y[4001];
int A[4001][4001];
queue<tuple<int,int,int> > Q;
int D = 6;
int DX[6] = { -1,0,1,1,0,-1 };
int DY[6] = { -1,-1,0,1,1,0 };

int horizon[4001][4001], diagonal[4001][4001];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    cin >> N >> K >> P;
    rep(i, K) {
        cin >> X[i] >> Y[i];
        --X[i]; --Y[i];
        Q.push(MT(X[i], Y[i], 0));
    }

    MEM(A, -1);
    while (sz(Q)) {
        int x, y, d;
        tie(x, y, d) = Q.front();
        Q.pop();
        if (A[x][y] != -1)continue;
        A[x][y] = d;
        rep(i, D) {
            int nx = x + DX[i];
            int ny = y + DY[i];
            if (nx >= 0 && nx < N && ny >= 0 && ny <= nx && A[nx][ny] == -1) {
                Q.push(MT(nx, ny, d + 1));
            }
        }
    }

    //部分和の初期化
    rep(x, N)rep(y, x + 1) {
        horizon[x][y + 1] = horizon[x][y] + A[x][y];
        diagonal[x + 1][y + 1] = diagonal[x][y] + A[x][y];
    }


    ll ans = 0;
    // (x, y)を上端とするような和を考える
    for (int y = 0; y < N; ++y) { // 列yを見る
        // (0, y)を上端とする和について
        // P以上になるまで下端を伸ばす
        // その後は、x->x+1としながら下端を尺取
        // x->x+1のとき斜めの部分を削る
        
        int bottom = y; // 下端
        int len = 0;
        ll sum = 0;
        for (int x = y; x < N; ++x) {
            while (bottom == x || (bottom < N&&sum < P)) {
                len++;
                sum += horizon[bottom][y + len];
                sum -= horizon[bottom][y];
                bottom++;
            }
            if (sum < P)break;
            ans += N - bottom + 1;

            // 斜め上の部分を削る
            sum -= diagonal[x + len][y + len];
            sum += diagonal[x][y];
            len--;
        }
    }

    cout << ans << endl;
}
0