Submission #20304990


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




void main() {
  try {
    for (; ; ) {
      const X = readToken();
      const M = readLong();
      
      if (X.length == 1) {
        writeln((X[0] - '0' <= M) ? 1 : 0);
        continue;
      }
      
      long d = 0;
      foreach (x; X) {
        chmax(d, x - '0');
      }
      
      long lo = d, hi = M + 1;
      for (; lo + 1 < hi; ) {
        const mid = (lo + hi) / 2;
        BigInt val;
        foreach (x; X) {
          val = val * mid + (x - '0');
        }
        ((val <= M) ? lo : hi) = mid;
      }
      writeln(lo - d);
    }
  } catch (EOFException e) {
  }
}

Submission Info

Submission Time
Task D - Base n
User hos_lyric
Language D (LDC 1.20.1)
Score 400
Code Size 1815 Byte
Status AC
Exec Time 9 ms
Memory 3860 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 47
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, one_digit_01.txt, one_digit_02.txt, one_digit_03.txt, one_digit_04.txt, one_digit_05.txt, one_digit_06.txt, one_digit_07.txt, one_digit_08.txt, one_digit_09.txt, one_digit_10.txt, one_digit_11.txt, one_digit_12.txt, one_digit_13.txt, one_digit_14.txt, one_digit_15.txt, one_digit_16.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, random_21.txt, random_22.txt, random_23.txt, random_24.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 7 ms 3388 KB
hand_02.txt AC 3 ms 3196 KB
hand_03.txt AC 4 ms 3364 KB
hand_04.txt AC 3 ms 3168 KB
one_digit_01.txt AC 4 ms 3176 KB
one_digit_02.txt AC 3 ms 3284 KB
one_digit_03.txt AC 4 ms 3372 KB
one_digit_04.txt AC 3 ms 3288 KB
one_digit_05.txt AC 6 ms 3224 KB
one_digit_06.txt AC 3 ms 3324 KB
one_digit_07.txt AC 4 ms 3336 KB
one_digit_08.txt AC 4 ms 3328 KB
one_digit_09.txt AC 3 ms 3192 KB
one_digit_10.txt AC 3 ms 3300 KB
one_digit_11.txt AC 3 ms 3400 KB
one_digit_12.txt AC 4 ms 3192 KB
one_digit_13.txt AC 4 ms 3304 KB
one_digit_14.txt AC 3 ms 3328 KB
one_digit_15.txt AC 4 ms 3228 KB
one_digit_16.txt AC 5 ms 3368 KB
random_01.txt AC 5 ms 3224 KB
random_02.txt AC 4 ms 3228 KB
random_03.txt AC 3 ms 3172 KB
random_04.txt AC 3 ms 3400 KB
random_05.txt AC 3 ms 3288 KB
random_06.txt AC 3 ms 3048 KB
random_07.txt AC 5 ms 3232 KB
random_08.txt AC 4 ms 3288 KB
random_09.txt AC 4 ms 3328 KB
random_10.txt AC 4 ms 3308 KB
random_11.txt AC 4 ms 3476 KB
random_12.txt AC 6 ms 3428 KB
random_13.txt AC 3 ms 3116 KB
random_14.txt AC 9 ms 3300 KB
random_15.txt AC 3 ms 3112 KB
random_16.txt AC 4 ms 3324 KB
random_17.txt AC 4 ms 3116 KB
random_18.txt AC 6 ms 3300 KB
random_19.txt AC 4 ms 3296 KB
random_20.txt AC 5 ms 3368 KB
random_21.txt AC 4 ms 3284 KB
random_22.txt AC 6 ms 3848 KB
random_23.txt AC 9 ms 3824 KB
random_24.txt AC 7 ms 3840 KB
sample_01.txt AC 3 ms 3340 KB
sample_02.txt AC 4 ms 3172 KB
sample_03.txt AC 9 ms 3860 KB