結果

問題 No.528 10^9と10^9+7と回文
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-05-20 21:19:37
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 2,716 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 106,748 KB
実行使用メモリ 9,836 KB
最終ジャッジ日時 2023-09-04 01:07:57
合計ジャッジ時間 2,658 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,004 KB
testcase_01 AC 5 ms
8,740 KB
testcase_02 AC 5 ms
8,696 KB
testcase_03 AC 5 ms
8,176 KB
testcase_04 AC 5 ms
7,908 KB
testcase_05 AC 5 ms
9,364 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
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 AC 10 ms
9,132 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) {
            cnt = (N[L - 1 - k] < N[k]) ? 1 : 0;
          } else {
            cnt = (k == 0) ? (N[k] - '0' - 1) : (N[k] - '0');
          }
          tmp *= MInt(cnt);
          tmp *= ten[(L - k + 1) / 2 - 1];
        }
        debug {
          writeln("k = ", k, ": ", tmp);
        }
        ans += tmp;
      }
      
      writeln(ans.v0);
      writeln(ans.v1);
    }
  } catch (EOFException e) {
  }
}
0