結果

問題 No.493 とても長い数列と文字列(Long Long Sequence and a String)
ユーザー tnakao0123tnakao0123
提出日時 2017-03-14 12:49:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,445 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 83,124 KB
実行使用メモリ 7,816 KB
最終ジャッジ日時 2023-09-12 12:20:28
合計ジャッジ時間 6,846 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 493.cc: No.493 とても長い数列と文字列(Long Long Sequence and a String) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

typedef long long ll;
const ll MAX_R = 1000000000000000000LL;
const ll MOD = 1000000007;

/* typedef */

/* global variables */

ll lfs[MAX_N], sums[MAX_N], muls[MAX_N];
int lds[MAX_N], ds[MAX_N][5];;

/* subroutines */

ll sum_range(int k, ll l, ll r) {
  ll &lfk = lfs[k];
  int &ldk = lds[k];
  if (k <= 0 || r <= 0 || lfk <= l) return 0;
  if (l <= 0 && lfk <= r) return sums[k];

  int off = lfs[k - 1] + ldk;
  ll sum =
    sum_range(k - 1, l, r) + sum_range(k - 1, l - off, r - off);

  ll i0 = max(l - lfs[k - 1], 0LL), i1 = min(r - lfs[k - 1], (ll)ldk);
  if (i0 < ldk && 0 < i1)
    for (int i = i0; i < i1; i++) sum += ds[k][i];

  return sum;
}

ll mul_range(int k, ll l, ll r) {
  ll &lfk = lfs[k];
  int &ldk = lds[k];
  if (k <= 0 || r <= 0 || lfk <= l) return 1;
  if (l <= 0 && lfk <= r) return muls[k];

  int off = lfs[k - 1] + ldk;
  ll mul =
    (mul_range(k - 1, l, r) * mul_range(k - 1, l - off, r - off)) % MOD;

  ll i0 = max(l - lfs[k - 1], 0LL), i1 = min(r - lfs[k - 1], (ll)ldk);
  if (i0 < ldk && 0 < i1)
    for (int i = i0; i < i1; i++) mul = (mul * ds[k][i]) % MOD;

  return mul;
}

/* main */

int main() {
  lfs[0] = 0;
  lds[0] = 0;
  sums[0] = 0;
  muls[0] = 1;
  int n;
  for (n = 1;; n++) {
    sums[n] = sums[n - 1] * 2;
    muls[n] = (muls[n - 1] * muls[n - 1]) % MOD;
    int n2 = n * n, l = 0;
    for (; n2 > 0; l++, n2 /= 10) {
      int d = n2 % 10;
      if (d == 0) d = 10;
      sums[n] += d;
      muls[n] = (muls[n] * d) % MOD;
      ds[n][l] = d;
    }
    lfs[n] = lfs[n - 1] * 2 + l;
    lds[n] = l;
    //printf("lfs[%d]=%lld (%d^2=%d(%d))", n, lfs[n], n, n * n, l);
    //printf(" sum=%lld, mul=%lld\n", sums[n], muls[n]);
    if (lfs[n] > MAX_R) break;
  }

  int k;
  ll l, r;
  cin >> k >> l >> r;
  l--;

  if (k > n) k = n;
  if (lfs[k] < r) {
    puts("-1");
    return 0;
  }

  ll s = sum_range(k, l, r);
  ll m = mul_range(k, l, r);
  printf("%lld %lld\n", s, m);
  return 0;
}
0