結果

問題 No.528 10^9と10^9+7と回文
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-05-20 21:34:16
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 10 ms / 1,000 ms
コード長 2,703 bytes
コンパイル時間 789 ms
コンパイル使用メモリ 106,636 KB
実行使用メモリ 9,884 KB
最終ジャッジ日時 2023-09-04 01:08:26
合計ジャッジ時間 2,185 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,108 KB
testcase_01 AC 5 ms
8,020 KB
testcase_02 AC 6 ms
8,928 KB
testcase_03 AC 5 ms
7,736 KB
testcase_04 AC 5 ms
8,624 KB
testcase_05 AC 5 ms
7,924 KB
testcase_06 AC 5 ms
8,388 KB
testcase_07 AC 6 ms
8,976 KB
testcase_08 AC 5 ms
7,824 KB
testcase_09 AC 5 ms
9,884 KB
testcase_10 AC 9 ms
8,184 KB
testcase_11 AC 8 ms
7,876 KB
testcase_12 AC 9 ms
8,192 KB
testcase_13 AC 8 ms
9,648 KB
testcase_14 AC 7 ms
8,468 KB
testcase_15 AC 7 ms
8,028 KB
testcase_16 AC 7 ms
9,532 KB
testcase_17 AC 6 ms
7,892 KB
testcase_18 AC 8 ms
8,012 KB
testcase_19 AC 6 ms
8,620 KB
testcase_20 AC 8 ms
9,244 KB
testcase_21 AC 6 ms
8,224 KB
testcase_22 AC 5 ms
8,304 KB
testcase_23 AC 6 ms
8,476 KB
testcase_24 AC 5 ms
8,324 KB
testcase_25 AC 6 ms
8,208 KB
testcase_26 AC 9 ms
8,604 KB
testcase_27 AC 10 ms
9,152 KB
権限があれば一括ダウンロードができます

ソースコード

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


struct MInt {
  enum MO0 = 10L^^9;
  enum MO1 = 10L^^9 + 7;
  long v0, v1;
  this(long v) {
    v0 = v % MO0;
    v1 = v % MO1;
  }
  this(long v0, long v1) {
    this.v0 = v0 % MO0;
    this.v1 = v1 % MO1;
  }
  MInt opBinary(string op)(MInt o) if (op == "+" || op == "*") {
    return MInt(mixin("v0 " ~ op ~ " o.v0"), mixin("v1 " ~ op ~ " o.v1"));
  }
  MInt opOpAssign(string op)(MInt o) if (op == "+" || op == "*") {
    return (this = mixin("this " ~ op ~ "o"));
  }
}

enum LIM = 3 * 10^^5;

int L;
string N;

void main() {
  auto ten = new MInt[LIM];
  ten[0] = MInt(1);
  foreach (i; 1 .. LIM) {
    ten[i] = ten[i - 1] * MInt(10);
  }
  
  try {
    for (; ; ) {
      N = readToken();
      L = cast(int)(N.length);
      
      MInt ans;
      
      // of length l (< L)
      foreach (l; 1 .. L) {
        ans += MInt(9) * ten[(l + 1) / 2 - 1];
      }
      
      // share first k digits
      foreach (k; 0 .. L + 1) {
        auto tmp = MInt(1);
        if (L - 1 - (k - 1) < k - 1) {
          if (N[L - 1 - (k - 1)] != N[k - 1]) {
            break;
          }
        }
        if (k < L) {
          int cnt;
          if (L - 1 - k < k) {
            tmp = MInt((N[L - 1 - k] < N[k]) ? 1 : 0);
          } else {
            tmp *= MInt((k == 0) ? (N[k] - '0' - 1) : (N[k] - '0'));
            tmp *= ten[(L + 1) / 2 - k - 1];
          }
        }
        debug {
          writeln("k = ", k, ": ", tmp);
        }
        ans += tmp;
      }
      
      writeln(ans.v0);
      writeln(ans.v1);
    }
  } catch (EOFException e) {
  }
}
0