結果

問題 No.1898 Battle and Exchange
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-04-08 22:11:50
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 385 ms / 5,000 ms
コード長 3,321 bytes
コンパイル時間 1,151 ms
コンパイル使用メモリ 133,092 KB
実行使用メモリ 17,092 KB
最終ジャッジ日時 2023-09-04 16:42:29
合計ジャッジ時間 21,153 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 26 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 17 ms
4,380 KB
testcase_18 AC 70 ms
9,960 KB
testcase_19 AC 111 ms
12,416 KB
testcase_20 AC 126 ms
14,156 KB
testcase_21 AC 329 ms
15,132 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 10 ms
4,380 KB
testcase_28 AC 14 ms
4,380 KB
testcase_29 AC 35 ms
4,384 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 87 ms
12,408 KB
testcase_33 AC 153 ms
13,932 KB
testcase_34 AC 73 ms
11,756 KB
testcase_35 AC 116 ms
14,468 KB
testcase_36 AC 97 ms
12,872 KB
testcase_37 AC 32 ms
4,404 KB
testcase_38 AC 328 ms
17,092 KB
testcase_39 AC 241 ms
15,844 KB
testcase_40 AC 299 ms
16,404 KB
testcase_41 AC 234 ms
15,460 KB
testcase_42 AC 13 ms
4,384 KB
testcase_43 AC 217 ms
14,372 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 24 ms
4,376 KB
testcase_46 AC 99 ms
12,484 KB
testcase_47 AC 18 ms
4,376 KB
testcase_48 AC 37 ms
4,408 KB
testcase_49 AC 10 ms
4,376 KB
testcase_50 AC 10 ms
4,380 KB
testcase_51 AC 10 ms
4,376 KB
testcase_52 AC 18 ms
4,376 KB
testcase_53 AC 73 ms
5,544 KB
testcase_54 AC 97 ms
6,224 KB
testcase_55 AC 87 ms
5,808 KB
testcase_56 AC 107 ms
7,732 KB
testcase_57 AC 363 ms
15,616 KB
testcase_58 AC 376 ms
15,740 KB
testcase_59 AC 385 ms
15,808 KB
testcase_60 AC 371 ms
15,568 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