結果

問題 No.1359 [Zelkova 3rd Tune] 四人セゾン
ユーザー 👑 hos.lyrichos.lyric
提出日時 2021-01-22 23:01:04
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 3,354 bytes
コンパイル時間 1,963 ms
コンパイル使用メモリ 157,072 KB
実行使用メモリ 36,156 KB
最終ジャッジ日時 2024-06-22 10:46:00
合計ジャッジ時間 27,631 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 209 ms
17,468 KB
testcase_04 AC 193 ms
16,304 KB
testcase_05 AC 175 ms
17,024 KB
testcase_06 AC 175 ms
18,244 KB
testcase_07 AC 265 ms
28,008 KB
testcase_08 AC 262 ms
28,636 KB
testcase_09 AC 72 ms
7,416 KB
testcase_10 AC 72 ms
9,024 KB
testcase_11 AC 352 ms
34,580 KB
testcase_12 AC 334 ms
33,800 KB
testcase_13 AC 213 ms
16,984 KB
testcase_14 AC 215 ms
16,888 KB
testcase_15 AC 186 ms
14,916 KB
testcase_16 AC 189 ms
15,172 KB
testcase_17 AC 349 ms
34,532 KB
testcase_18 AC 356 ms
35,292 KB
testcase_19 AC 331 ms
27,372 KB
testcase_20 AC 306 ms
27,284 KB
testcase_21 AC 368 ms
34,776 KB
testcase_22 AC 374 ms
35,900 KB
testcase_23 AC 220 ms
17,892 KB
testcase_24 AC 250 ms
18,032 KB
testcase_25 AC 40 ms
6,940 KB
testcase_26 AC 37 ms
6,940 KB
testcase_27 AC 118 ms
13,948 KB
testcase_28 AC 135 ms
13,164 KB
testcase_29 AC 143 ms
14,124 KB
testcase_30 AC 162 ms
14,512 KB
testcase_31 AC 209 ms
16,496 KB
testcase_32 AC 191 ms
15,984 KB
testcase_33 AC 144 ms
14,492 KB
testcase_34 AC 138 ms
14,152 KB
testcase_35 AC 183 ms
16,640 KB
testcase_36 AC 184 ms
17,100 KB
testcase_37 AC 37 ms
6,940 KB
testcase_38 AC 36 ms
6,944 KB
testcase_39 AC 30 ms
6,944 KB
testcase_40 AC 29 ms
6,940 KB
testcase_41 AC 64 ms
7,440 KB
testcase_42 AC 66 ms
7,532 KB
testcase_43 AC 50 ms
6,940 KB
testcase_44 AC 347 ms
33,932 KB
testcase_45 AC 147 ms
14,200 KB
testcase_46 AC 48 ms
6,940 KB
testcase_47 AC 246 ms
24,280 KB
testcase_48 AC 235 ms
18,276 KB
testcase_49 AC 234 ms
24,468 KB
testcase_50 AC 182 ms
16,884 KB
testcase_51 AC 10 ms
6,940 KB
testcase_52 AC 313 ms
29,140 KB
testcase_53 AC 404 ms
35,176 KB
testcase_54 AC 372 ms
35,124 KB
testcase_55 AC 417 ms
35,044 KB
testcase_56 AC 391 ms
34,956 KB
testcase_57 AC 377 ms
34,476 KB
testcase_58 AC 408 ms
34,880 KB
testcase_59 AC 367 ms
36,156 KB
testcase_60 AC 359 ms
34,964 KB
testcase_61 AC 352 ms
35,364 KB
testcase_62 AC 413 ms
34,960 KB
testcase_63 AC 414 ms
35,708 KB
testcase_64 AC 417 ms
35,788 KB
testcase_65 AC 414 ms
35,260 KB
testcase_66 AC 412 ms
35,756 KB
testcase_67 AC 422 ms
34,812 KB
testcase_68 AC 408 ms
35,720 KB
testcase_69 AC 351 ms
34,924 KB
testcase_70 AC 378 ms
34,796 KB
testcase_71 AC 346 ms
35,128 KB
testcase_72 AC 375 ms
35,740 KB
testcase_73 AC 368 ms
35,368 KB
testcase_74 AC 375 ms
34,836 KB
testcase_75 AC 370 ms
35,768 KB
testcase_76 AC 360 ms
34,756 KB
testcase_77 AC 359 ms
34,356 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)); }


struct ModInt {
  static int M;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      if (a < 0) return (this = inv()^^(-a));
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op)() const if (op == "-") { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const { return mixin("ModInt(this) " ~ op ~ "= a"); }
  ModInt opBinaryRight(string op)(long a) const { return mixin("ModInt(a) " ~ op ~ "= this"); }
  string toString() const { return x.to!string; }
}


void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const K = readLong();
      ModInt.M = readInt();
      auto A = new long[][](4, N);
      foreach (h; 0 .. 4) {
        foreach (i; 0 .. N) {
          A[h][i] = readLong();
        }
        A[h].sort;
      }
      
      ModInt ans;
      foreach (i; 0 .. N) {
        long mn = long.max;
        long mx = long.min;
        foreach (h; 0 .. 4) {
          chmin(mn, A[h][i]);
          chmax(mx, A[h][i]);
        }
        ans += ModInt(mx - mn)^^K;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0