結果

問題 No.974 最後の日までに
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-01-17 22:20:43
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 267 ms / 2,000 ms
コード長 2,586 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 117,148 KB
実行使用メモリ 17,240 KB
最終ジャッジ日時 2023-09-04 04:44:38
合計ジャッジ時間 12,699 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 246 ms
16,716 KB
testcase_01 AC 243 ms
16,448 KB
testcase_02 AC 243 ms
16,972 KB
testcase_03 AC 245 ms
16,304 KB
testcase_04 AC 245 ms
16,500 KB
testcase_05 AC 242 ms
16,836 KB
testcase_06 AC 243 ms
15,972 KB
testcase_07 AC 243 ms
16,252 KB
testcase_08 AC 243 ms
16,252 KB
testcase_09 AC 246 ms
16,452 KB
testcase_10 AC 247 ms
16,756 KB
testcase_11 AC 246 ms
17,240 KB
testcase_12 AC 247 ms
16,260 KB
testcase_13 AC 247 ms
15,924 KB
testcase_14 AC 248 ms
17,172 KB
testcase_15 AC 248 ms
17,172 KB
testcase_16 AC 248 ms
16,188 KB
testcase_17 AC 261 ms
17,016 KB
testcase_18 AC 261 ms
17,228 KB
testcase_19 AC 260 ms
16,496 KB
testcase_20 AC 260 ms
16,716 KB
testcase_21 AC 260 ms
16,568 KB
testcase_22 AC 261 ms
16,256 KB
testcase_23 AC 261 ms
16,280 KB
testcase_24 AC 261 ms
16,980 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 189 ms
13,200 KB
testcase_28 AC 248 ms
17,216 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 261 ms
15,972 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 152 ms
13,184 KB
testcase_34 AC 250 ms
17,172 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 267 ms
17,220 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 142 ms
13,440 KB
testcase_41 AC 184 ms
15,988 KB
testcase_42 AC 267 ms
16,228 KB
testcase_43 AC 267 ms
17,168 KB
testcase_44 AC 203 ms
13,196 KB
testcase_45 AC 162 ms
13,952 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum INF = 10L^^18;

void main() {
  try {
    for (; ; ) {
      const W = readInt();
      auto A = new long[W];
      auto B = new long[W];
      auto C = new long[W];
      foreach (i; 0 .. W) {
        A[i] = readLong();
        B[i] = readLong();
        C[i] = readLong();
      }
      
      long ans;
      foreach (m; W / 2 .. W / 2 + 2) {
        alias Entry = Tuple!(long, "x", long, "y");
        auto ess = new Entry[][2];
        void dfs(int s, int r, int i, long x, long y) {
          if (i == r) {
            ess[s] ~= Entry(x, y);
            return;
          }
          if (i + 1 <= r) {
            dfs(s, r, i + 1, x + A[i], y);
          }
          if (i + 2 <= r) {
            dfs(s, r, i + 2, x - C[i + 1], y + B[i + 1]);
          }
        }
        dfs(0, m, 0, 0, 0);
        dfs(1, W, m, 0, 0);
        ess[0].sort;
        ess[1].sort;
        debug {
          writeln("m = ", m);
          writeln("ess[0] = ", ess[0]);
          writeln("ess[1] = ", ess[1]);
        }
        const len0 = cast(int)(ess[0].length);
        const len1 = cast(int)(ess[1].length);
        long mx = -INF;
        for (int j = 0, k = len1; j < len0; ++j) {
          for (; k > 0 && ess[0][j].x + ess[1][k - 1].x >= 0; ) {
            chmax(mx, ess[1][--k].y);
          }
          chmax(ans, ess[0][j].y + mx);
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0