結果

問題 No.2500 Products in a Range
ユーザー 👑 hos.lyrichos.lyric
提出日時 2023-10-13 23:35:39
言語 D
(dmd 2.106.1)
結果
RE  
実行時間 -
コード長 2,492 bytes
コンパイル時間 3,246 ms
コンパイル使用メモリ 109,372 KB
実行使用メモリ 4,844 KB
最終ジャッジ日時 2023-10-13 23:35:52
合計ジャッジ時間 7,645 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 RE -
testcase_02 AC 3 ms
4,352 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 17 ms
4,376 KB
testcase_08 RE -
testcase_09 WA -
testcase_10 AC 69 ms
4,356 KB
testcase_11 AC 82 ms
4,348 KB
testcase_12 AC 30 ms
4,372 KB
testcase_13 AC 2 ms
4,476 KB
testcase_14 AC 66 ms
4,352 KB
testcase_15 AC 4 ms
4,352 KB
testcase_16 RE -
testcase_17 AC 12 ms
4,352 KB
testcase_18 RE -
testcase_19 AC 18 ms
4,352 KB
testcase_20 AC 19 ms
4,352 KB
testcase_21 AC 3 ms
4,352 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 129 ms
4,352 KB
testcase_26 AC 124 ms
4,352 KB
testcase_27 AC 127 ms
4,356 KB
testcase_28 AC 16 ms
4,352 KB
testcase_29 AC 5 ms
4,352 KB
testcase_30 AC 4 ms
4,352 KB
testcase_31 RE -
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 28 ms
4,348 KB
testcase_34 AC 74 ms
4,352 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 AC 1 ms
4,352 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 1 ms
4,352 KB
testcase_43 RE -
testcase_44 AC 10 ms
4,352 KB
testcase_45 AC 1 ms
4,348 KB
testcase_46 RE -
testcase_47 AC 127 ms
4,352 KB
testcase_48 AC 1 ms
4,348 KB
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(49): Warning: statement is not reachable
Main.d(49): Warning: statement is not reachable

ソースコード

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; }

string COLOR(string s = "") { return "\x1b[" ~ s ~ "m"; }

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)); }




void main() {
  try {
    for (; ; ) {
      const N = readInt;
      const L = readLong;
      const R = readLong;
      auto A = new long[N];
      foreach (i; 0 .. N) {
        A[i] = readLong;
      }
      A.sort;
      
      bool check(int i, int j) {
        const prod = A[i] * A[j];
        return (L <= prod && prod <= R);
      }
      
      int ans = 1;
      if (R < 0) {
        foreach (i; 0 .. N) foreach (j; i + 1 .. N) {
          if (check(i, j)) {
            chmax(ans, 2);
          }
        }
      } else if (0 < L) {
        assert(false);
        foreach (i; 0 .. N) foreach (j; i + 1 .. N) {
          if (check(i, i + 1) && check(i, j) && check(j - 1, j)) {
            chmax(ans, j - i + 1);
          }
        }
      } else {
        foreach (i; 0 .. N) foreach (j; i + 1 .. N) {
          if (check(i, i + 1) && check(i, j) && check(j - 1, j)) {
            chmax(ans, j - i + 1);
          }
        }
        const zL = A.lowerBound(0);
        const zR = A.upperBound(0);
        foreach (i; 0 .. zL) foreach (j; zR .. N) {
          if (check(i, j)) {
            if (check(i, i + 1)) chmax(ans, 1 + (j - zL + 1));
            if (check(j - 1, j)) chmax(ans, (zR - i) + 1);
          }
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0