Submission #20534906


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 L = 10;

long eval(string s, int a) {
  auto cs = new int[L];
  foreach (i; 0 .. 4) {
    ++cs[s[i] - '0'];
  }
  ++cs[a];
  long ret;
  foreach (i; 1 .. L) {
    ret += i * 10L^^cs[i];
  }
  return ret;
}

void main() {
  try {
    for (; ; ) {
      const K = readInt();
      const S = readToken();
      const T = readToken();
      
      auto lots = new int[L];
      lots[1 .. L] = K;
      foreach (i; 0 .. 4) --lots[S[i] - '0'];
      foreach (i; 0 .. 4) --lots[T[i] - '0'];
      
      auto scoresS = new long[L];
      auto scoresT = new long[L];
      foreach (a; 1 .. L) {
        scoresS[a] = eval(S, a);
        scoresT[a] = eval(T, a);
      }
      
      real ans = 0.0L;
      foreach (a; 1 .. L) {
        if (lots[a] > 0) {
          const probA = 1.0L * lots[a] / (9 * K - 8);
          --lots[a];
          foreach (b; 1 .. L) {
            const probB = 1.0L * lots[b] / (9 * K - 9);
            if (scoresS[a] > scoresT[b]) {
              ans += probA * probB;
            }
          }
          ++lots[a];
        }
      }
      writefln("%.12f", ans);
    }
  } catch (EOFException e) {
  }
}

Submission Info

Submission Time
Task D - Poker
User hos_lyric
Language D (LDC 1.20.1)
Score 400
Code Size 2373 Byte
Status AC
Exec Time 7 ms
Memory 3476 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 36
Set Name Test Cases
Sample 01_sample.txt, 02_sample.txt, 03_sample.txt, 04_sample.txt
All 01_sample.txt, 02_sample.txt, 03_sample.txt, 04_sample.txt, 05_hand.txt, 06_hand.txt, 07_random1.txt, 08_random1.txt, 09_random1.txt, 10_random1.txt, 11_random1.txt, 12_random1.txt, 13_random1.txt, 14_random2.txt, 15_random2.txt, 16_random2.txt, 17_random2.txt, 18_random2.txt, 19_random2.txt, 20_random2.txt, 21_random2.txt, 22_random2.txt, 23_random2.txt, 24_random3.txt, 25_random3.txt, 26_random3.txt, 27_random3.txt, 28_random3.txt, 29_random3.txt, 30_random3.txt, 31_random3.txt, 32_random3.txt, 33_random4.txt, 34_random4.txt, 35_random4.txt, 36_random4.txt
Case Name Status Exec Time Memory
01_sample.txt AC 7 ms 3460 KB
02_sample.txt AC 5 ms 3400 KB
03_sample.txt AC 3 ms 3252 KB
04_sample.txt AC 3 ms 3440 KB
05_hand.txt AC 4 ms 3420 KB
06_hand.txt AC 3 ms 3252 KB
07_random1.txt AC 5 ms 3452 KB
08_random1.txt AC 3 ms 3328 KB
09_random1.txt AC 5 ms 3328 KB
10_random1.txt AC 4 ms 3372 KB
11_random1.txt AC 6 ms 3368 KB
12_random1.txt AC 3 ms 3336 KB
13_random1.txt AC 3 ms 3420 KB
14_random2.txt AC 4 ms 3372 KB
15_random2.txt AC 3 ms 3404 KB
16_random2.txt AC 3 ms 3476 KB
17_random2.txt AC 4 ms 3420 KB
18_random2.txt AC 3 ms 3408 KB
19_random2.txt AC 3 ms 3404 KB
20_random2.txt AC 4 ms 3444 KB
21_random2.txt AC 3 ms 3304 KB
22_random2.txt AC 3 ms 3368 KB
23_random2.txt AC 3 ms 3440 KB
24_random3.txt AC 3 ms 3252 KB
25_random3.txt AC 3 ms 3476 KB
26_random3.txt AC 3 ms 3448 KB
27_random3.txt AC 3 ms 3476 KB
28_random3.txt AC 7 ms 3252 KB
29_random3.txt AC 3 ms 3372 KB
30_random3.txt AC 3 ms 3360 KB
31_random3.txt AC 4 ms 3404 KB
32_random3.txt AC 3 ms 3464 KB
33_random4.txt AC 3 ms 3476 KB
34_random4.txt AC 3 ms 3424 KB
35_random4.txt AC 3 ms 3372 KB
36_random4.txt AC 4 ms 3420 KB