結果

問題 No.165 四角で囲え!
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-12-13 18:36:28
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 4,259 ms / 5,000 ms
コード長 1,579 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 151,336 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 23:28:46
合計ジャッジ時間 41,266 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,328 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1,684 ms
4,380 KB
testcase_06 AC 287 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2,053 ms
4,376 KB
testcase_12 AC 4,179 ms
4,376 KB
testcase_13 AC 4,259 ms
4,380 KB
testcase_14 AC 2,690 ms
4,376 KB
testcase_15 AC 2,651 ms
4,376 KB
testcase_16 AC 2,600 ms
4,376 KB
testcase_17 AC 2,606 ms
4,376 KB
testcase_18 AC 2,528 ms
4,380 KB
testcase_19 AC 2,548 ms
4,376 KB
testcase_20 AC 2,526 ms
4,380 KB
testcase_21 AC 2,593 ms
4,376 KB
testcase_22 AC 2,500 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

void main() {
    int N, B; readf("%d %d\n", &N, &B);
    auto X = new int[N];
    auto Y = new int[N];
    auto P = new int[N];
    foreach (i; 0 .. N) {
        readf("%d %d %d\n", &X[i], &Y[i], &P[i]);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            int sy = min(Y[i], Y[j]);
            int ty = max(Y[i], Y[j]);
            auto r = iota(0, N, 1).filter!(k => sy <= Y[k] && Y[k] <= ty);
            auto sa = sort!((a, b) => (X[a] < X[b]))(r.array).array;
            int n = sa.size;
            int sk = 0, tk = 0;
            int sum = 0;
            //log("i, j: ", [i, j]);
            while (sk < n || tk < n) {
                //log("sk, tk: ", [sk, tk]);
                ans = max(ans, tk - sk);
                int nsum = sum;
                int nk = tk;
                while (nk < n && X[sa[nk]] == X[sa[tk]]) { nsum += P[sa[nk++]]; }
                if (tk == n || nsum > B) {
                    int sx = X[sa[sk]];
                    while (sk < n && X[sa[sk]] == sx) {
                        sum -= P[sa[sk++]];
                    }
                } else {
                    tk = nk;
                    sum = nsum;
                }
            }
        }
    }
    writeln(ans);
}
0