結果

問題 No.335 門松宝くじ
ユーザー nebukuro09nebukuro09
提出日時 2017-04-05 13:52:23
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 593 ms / 2,000 ms
コード長 2,136 bytes
コンパイル時間 2,122 ms
コンパイル使用メモリ 159,632 KB
実行使用メモリ 11,280 KB
最終ジャッジ日時 2023-09-03 12:41:58
合計ジャッジ時間 6,296 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 146 ms
11,180 KB
testcase_06 AC 217 ms
11,240 KB
testcase_07 AC 393 ms
11,240 KB
testcase_08 AC 256 ms
11,280 KB
testcase_09 AC 592 ms
11,216 KB
testcase_10 AC 585 ms
11,168 KB
testcase_11 AC 574 ms
11,228 KB
testcase_12 AC 593 ms
11,232 KB
testcase_13 AC 582 ms
11,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto E = new int[][](M);
    foreach (i; 0..M) E[i] = readln.split.map!(to!int).array;

    
    long ans_v = 0;
    int  ans_i = 0;
    
    foreach (i; 0..M) {
        long e = 0;
        auto rbt_l = new RedBlackTree!(int)();

        foreach (j; 0..N) {
            auto rbt_m = new RedBlackTree!(int)();
            auto rbt_r = new RedBlackTree!(int)();
            foreach (k; j+2..N) rbt_r.insert(E[i][k]);
            
            foreach (k; j+1..N) {
                long et = 0;
                if (E[i][j] < E[i][k]) {
                    auto l  = rbt_l.upperBound(E[i][j]);
                    if (!l.empty) et = max(et, max(l.back, E[i][k]));
                    auto ml = rbt_m.lowerBound(E[i][j]);
                    if (!ml.empty) et = max(et, E[i][k]);
                    auto mu = rbt_m.upperBound(E[i][k]);
                    if (!mu.empty) et = max(et, mu.back);
                    auto r  = rbt_r.lowerBound(E[i][k]);
                    if (!r.empty) et = max(et, E[i][k]);
                }
                else {
                    auto l  = rbt_l.lowerBound(E[i][j]);
                    if (!l.empty) et = max(et, E[i][j]);
                    auto mu = rbt_m.upperBound(E[i][j]);
                    if (!mu.empty) et = max(et, mu.back);
                    auto ml = rbt_m.lowerBound(E[i][k]);
                    if (!ml.empty) et = max(et, E[i][j]);
                    auto r  = rbt_r.upperBound(E[i][k]);
                    if (!r.empty) et = max(et, max(r.back, E[i][j]));
                }

                if (k+1 < N) rbt_r.removeKey(E[i][k+1]);
                rbt_m.insert(E[i][k]);
                e += et;
            }

            rbt_l.insert(E[i][j]);
            
        }


        if (e > ans_v) {
            ans_v = e;
            ans_i = i;
        }
    }

    //ans_v.writeln;
    ans_i.writeln;
}
0