Submission #20303206


Source Code Expand

Copy
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 = 2 * 10L^^18;

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const X = readLong();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }
      
      long ans = INF;
      foreach (k; 1 .. N + 1) {
        auto dp = new long[][](k + 1, k);
        foreach (j; 0 .. k + 1) {
          dp[j][] = -INF;
        }
        dp[0][0] = 0;
        foreach (i; 0 .. N) {
          foreach_reverse (j; 0 .. k) {
            int rr = A[i] % k;
            foreach (r; 0 .. k) {
              if (dp[j][r] >= 0) {
                chmax(dp[j + 1][rr], dp[j][r] + A[i]);
              }
              if (++rr >= k) {
                rr = 0;
              }
            }
          }
          const r0 = cast(int)(X % k);
          if (dp[k][r0] >= 0) {
            chmin(ans, (X - dp[k][r0]) / k);
          }
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

Submission Info

Submission Time
Task F - Potion
User hos_lyric
Language D (LDC 1.20.1)
Score 600
Code Size 2181 Byte
Status AC
Exec Time 86 ms
Memory 3996 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 34
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand_01.txt, hand_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, special_01.txt, special_02.txt, special_03.txt, special_04.txt, special_05.txt, special_06.txt, special_07.txt, special_08.txt, special_09.txt, special_10.txt
Case Name Status Exec Time Memory
hand_01.txt AC 59 ms 3836 KB
hand_02.txt AC 57 ms 3792 KB
random_01.txt AC 82 ms 3984 KB
random_02.txt AC 4 ms 3216 KB
random_03.txt AC 84 ms 3996 KB
random_04.txt AC 17 ms 3564 KB
random_05.txt AC 84 ms 3836 KB
random_06.txt AC 69 ms 3804 KB
random_07.txt AC 81 ms 3764 KB
random_08.txt AC 5 ms 3400 KB
random_09.txt AC 80 ms 3872 KB
random_10.txt AC 4 ms 3292 KB
random_11.txt AC 82 ms 3864 KB
random_12.txt AC 5 ms 3372 KB
random_13.txt AC 86 ms 3840 KB
random_14.txt AC 16 ms 3532 KB
random_15.txt AC 81 ms 3836 KB
random_16.txt AC 8 ms 3232 KB
random_17.txt AC 82 ms 3852 KB
random_18.txt AC 4 ms 3384 KB
random_19.txt AC 80 ms 3928 KB
random_20.txt AC 5 ms 3296 KB
sample_01.txt AC 5 ms 3104 KB
sample_02.txt AC 5 ms 3300 KB
special_01.txt AC 57 ms 3828 KB
special_02.txt AC 58 ms 3736 KB
special_03.txt AC 57 ms 3820 KB
special_04.txt AC 58 ms 3880 KB
special_05.txt AC 57 ms 3844 KB
special_06.txt AC 57 ms 3820 KB
special_07.txt AC 60 ms 3756 KB
special_08.txt AC 58 ms 3780 KB
special_09.txt AC 55 ms 3756 KB
special_10.txt AC 60 ms 3860 KB