結果
問題 | No.493 とても長い数列と文字列(Long Long Sequence and a String) |
ユーザー |
👑 |
提出日時 | 2019-05-02 17:41:03 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,681 bytes |
コンパイル時間 | 732 ms |
コンパイル使用メモリ | 126,396 KB |
実行使用メモリ | 13,880 KB |
最終ジャッジ日時 | 2024-06-22 01:09:08 |
合計ジャッジ時間 | 5,075 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 3 |
other | AC * 1 WA * 54 TLE * 1 -- * 59 |
ソースコード
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) {}}