結果

問題 No.1898 Battle and Exchange
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-04-08 22:11:50
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 311 ms / 5,000 ms
コード長 3,321 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 145,000 KB
実行使用メモリ 16,648 KB
最終ジャッジ日時 2024-06-22 14:51:59
合計ジャッジ時間 15,513 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 21 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 14 ms
6,940 KB
testcase_18 AC 60 ms
9,444 KB
testcase_19 AC 99 ms
12,340 KB
testcase_20 AC 107 ms
12,980 KB
testcase_21 AC 267 ms
14,776 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 9 ms
6,940 KB
testcase_28 AC 13 ms
6,940 KB
testcase_29 AC 33 ms
6,940 KB
testcase_30 AC 4 ms
6,944 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 74 ms
12,608 KB
testcase_33 AC 129 ms
14,184 KB
testcase_34 AC 63 ms
12,124 KB
testcase_35 AC 99 ms
13,328 KB
testcase_36 AC 80 ms
12,512 KB
testcase_37 AC 28 ms
6,940 KB
testcase_38 AC 263 ms
16,648 KB
testcase_39 AC 203 ms
15,352 KB
testcase_40 AC 247 ms
15,960 KB
testcase_41 AC 207 ms
14,972 KB
testcase_42 AC 11 ms
6,940 KB
testcase_43 AC 178 ms
13,852 KB
testcase_44 AC 1 ms
6,940 KB
testcase_45 AC 21 ms
6,944 KB
testcase_46 AC 83 ms
12,468 KB
testcase_47 AC 14 ms
6,940 KB
testcase_48 AC 32 ms
6,940 KB
testcase_49 AC 9 ms
6,944 KB
testcase_50 AC 8 ms
6,944 KB
testcase_51 AC 8 ms
6,944 KB
testcase_52 AC 15 ms
6,940 KB
testcase_53 AC 63 ms
6,944 KB
testcase_54 AC 82 ms
7,396 KB
testcase_55 AC 72 ms
6,940 KB
testcase_56 AC 89 ms
7,688 KB
testcase_57 AC 286 ms
15,332 KB
testcase_58 AC 296 ms
15,280 KB
testcase_59 AC 311 ms
15,340 KB
testcase_60 AC 296 ms
15,472 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;
enum BIG = 10L^^9;

int N, M;
int[] A, B;
long[][] X;

int[][] G;

long need0, need1;
int[] us;

bool check(long[] start) {
  long[] xs;
  void upd(long val) {
    foreach (k; 0 .. 3) {
      if (xs[k] < val) {
        swap(xs[k], val);
      }
    }
  }
  
  xs = start.dup;
  if (!(xs.sum > need0)) {
    return false;
  }
  upd(X[0][0]);
  if (!(xs.sum > need1)) {
    return false;
  }
  
  xs = start.dup;
  foreach (u; us) {
    if (!(xs.sum > X[u].sum)) {
      return false;
    }
    foreach (k; 0 .. 3) {
      upd(X[u][k]);
    }
  }
  return true;
}

void main() {
  try {
    for (; ; ) {
      N = readInt;
      M = readInt;
      A = new int[M];
      B = new int[M];
      foreach (i; 0 .. M) {
        A[i] = readInt - 1;
        B[i] = readInt - 1;
      }
      X = new long[][](N, 3);
      foreach (u; 0 .. N) {
        foreach (k; 0 .. 3) {
          X[u][k] = readLong;
        }
        X[u].sort;
        X[u].reverse;
      }
      
      G = new int[][N];
      foreach (i; 0 .. M) {
        G[A[i]] ~= i;
        G[B[i]] ~= i;
      }
      
      need0 = X[0].sum;
      need1 = INF;
      foreach (i; G[0]) {
        const v = A[i] ^ B[i] ^ 0;
        chmin(need1, X[v].sum);
      }
      
      alias Entry = Tuple!(long, "c", int, "u");
      BinaryHeap!(Array!Entry, "a.c > b.c") que;
      auto vis = new bool[N];
      vis[0] = true;
      que.insert(Entry(X[0].sum, 0));
      us = [];
      for (; !que.empty; ) {
        const u = que.front.u;
        que.removeFront;
        us ~= u;
        foreach (i; G[u]) {
          const v = A[i] ^ B[i] ^ u;
          if (!vis[v]) {
            vis[v] = true;
            que.insert(Entry(X[v].sum, v));
          }
        }
      }
      debug {
        writeln("need0 = ", need0);
        writeln("need1 = ", need1);
        writeln("us = ", us);
      }
      
      long lo = 0, hi = BIG;
      long[] start = [1, 1, 1];
      for (; lo + 1 < hi; ) {
        const mid = (lo + hi) / 2;
        start[0] = mid;
        (check(start) ? hi : lo) = mid;
      }
      
      writeln(hi, " ", 1, " ", 1);
    }
  } catch (EOFException e) {
  }
}
0