結果

問題 No.295 hel__world
ユーザー te-shte-sh
提出日時 2018-02-01 15:18:55
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,704 bytes
コンパイル時間 11,575 ms
コンパイル使用メモリ 524,708 KB
実行使用メモリ 4,996 KB
最終ジャッジ日時 2023-09-03 18:33:07
合計ジャッジ時間 25,360 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 8 ms
4,924 KB
testcase_25 AC 7 ms
4,992 KB
testcase_26 AC 10 ms
4,988 KB
testcase_27 AC 1,383 ms
4,984 KB
testcase_28 AC 2,377 ms
4,996 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.container; // SList, DList, BinaryHeap
import std.bigint;    // BigInt
import std.regex;     // Regex

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
T[] readArray(T)(size_t n){auto a=new T[](n),r=readln.splitter;foreach(ref v;a){v=r.front.to!T;r.popFront;}return a;}
T[] readArrayM(T)(size_t n){auto a=new T[](n);foreach(ref v;a)v=readln.chomp.to!T;return a;}

const inf = BigInt(1L<<62);

void main()
{
  auto s = readArray!long(26);
  string t; readV(t);

  auto d = BigInt(1);
  foreach (i, si; s) {
    d *= calc(BigInt(si), t, cast(char)('a'+i));
    if (d >= inf) d = inf;
  }

  if (d >= inf) writeln("hel");
  else          writeln(d);
}

auto calc(BigInt s, string t, char c)
{
  auto y = t.matchAll(regex(c.to!string ~ '+')).map!((m) => m[0].length.to!int).array;
  auto ny = y.length.to!int;
  if (y.empty) return BigInt(1);
  if (s < y.sum) return BigInt(0);

  if (s > 10^^7) {
    if (ny == 1) {
      if (y[0] == 1) return s;
      if (y[0] == 2) return s*(s-1)/2;
    } else if (ny == 2) {
      if (y[0] == 1 && y[1] == 1) return s/2*(s-s/2);
    }
    return inf;
  }

  auto r = new Rat[](ny);
  foreach (i, yi; y)
    r[i] = Rat(yi+1, yi);

  auto h = heapify(r), d = BigInt(1);
  foreach (i; 0..(s-y.sum).to!int) {
    auto ri = h.front;
    d = d * ri.n / (ri.n-ri.r);
    if (d >= inf) return inf;
    h.replaceFront(Rat(ri.n+1, ri.r));
  }

  return d;
}

struct Rat
{
  long n, r;

  auto opCmp(Rat b)
  {
    auto num = n, den = n-r, bnum = b.n, bden = b.n-b.r;
    auto c = num*bden - den*bnum;
    return c == 0 ? 0 : c < 0 ? -1 : 1;
  }
}
0