結果

問題 No.493 とても長い数列と文字列(Long Long Sequence and a String)
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-05-02 17:41:03
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 2,681 bytes
コンパイル時間 791 ms
コンパイル使用メモリ 117,352 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-04 01:01:01
合計ジャッジ時間 5,879 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 TLE -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
testcase_94 -- -
testcase_95 -- -
testcase_96 -- -
testcase_97 -- -
testcase_98 -- -
testcase_99 -- -
testcase_100 -- -
testcase_101 -- -
testcase_102 -- -
testcase_103 -- -
testcase_104 -- -
testcase_105 -- -
testcase_106 -- -
testcase_107 -- -
testcase_108 -- -
testcase_109 -- -
testcase_110 -- -
testcase_111 -- -
testcase_112 -- -
testcase_113 -- -
testcase_114 -- -
testcase_115 -- -
testcase_116 -- -
testcase_117 -- -
testcase_118 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, 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 MO = 10UL^^9 + 7;

struct P {
  long len;
  ulong sum, prod;
  P opBinary(string op)(in P o) const if (op == "*") {
    return P(len + o.len, sum + o.sum, (prod * o.prod) % MO);
  }
}
enum IDENTITY = P(0, 0, 1);

enum LIM = 60;

void main() {
  auto ss = new int[][LIM + 1];
  auto ps = new P[LIM + 1];
  ps[0] = IDENTITY;
  foreach (n; 1 .. LIM + 1) {
    ss[n] = (n^^2).to!string.map!(c => ((c == '0') ? 10 : cast(int)(c - '0'))).array;
    ps[n] = ps[n - 1] * P(ss[n].length, ss[n].sum, ss[n].fold!((a, b) => (a * b) % MO)) * ps[n - 1];
  }
  debug {
    writeln("ss = ", ss);
    writeln("ps = ", ps);
    assert(ps[LIM].len >= 10L^^18);
  }
  
  P calc(int n, long l, long r) {
    debug {
      writeln("calc ", n, " [", l, ", ", r, ")");
    }
    chmax(l, 0);
    chmin(r, ps[n].len);
    if (l >= r) {
      return IDENTITY;
    }
    P ret = IDENTITY;
    ret = ret * calc(n - 1, l, r);
    foreach (i; 0 .. ss[n].length) {
      if (l - ps[n - 1].len <= i && i < r - ps[n - 1].len) {
        ret = ret * P(1, ss[n][i], ss[n][i]);
      }
    }
    ret = ret * calc(n - 1, l - ps[n - 1].len - ss[n].length, r - ps[n - 1].len - ss[n].length);
    return ret;
  }
  
  try {
    for (; ; ) {
      int K = readInt();
      const L = readLong() - 1;
      const R = readLong();
      
      chmin(K, LIM);
      if (R > ps[K].len) {
        writeln(-1);
      } else {
        const ans = calc(K, L, R);
        assert(ans.len == R - L);
        writeln(ans.sum, " ", ans.prod);
      }
    }
  } catch (EOFException e) {
  }
}
0