結果
問題 | No.493 とても長い数列と文字列(Long Long Sequence and a String) |
ユーザー | tnakao0123 |
提出日時 | 2017-03-14 12:54:09 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 800 ms |
コード長 | 2,474 bytes |
コンパイル時間 | 633 ms |
コンパイル使用メモリ | 86,180 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-30 00:44:19 |
合計ジャッジ時間 | 3,019 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 1 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 1 ms
6,944 KB |
testcase_18 | AC | 1 ms
6,940 KB |
testcase_19 | AC | 1 ms
6,940 KB |
testcase_20 | AC | 1 ms
6,940 KB |
testcase_21 | AC | 1 ms
6,940 KB |
testcase_22 | AC | 1 ms
6,940 KB |
testcase_23 | AC | 1 ms
6,944 KB |
testcase_24 | AC | 1 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 1 ms
6,944 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 1 ms
6,944 KB |
testcase_29 | AC | 1 ms
6,940 KB |
testcase_30 | AC | 1 ms
6,944 KB |
testcase_31 | AC | 1 ms
6,944 KB |
testcase_32 | AC | 1 ms
6,940 KB |
testcase_33 | AC | 1 ms
6,944 KB |
testcase_34 | AC | 1 ms
6,940 KB |
testcase_35 | AC | 1 ms
6,940 KB |
testcase_36 | AC | 1 ms
6,940 KB |
testcase_37 | AC | 1 ms
6,940 KB |
testcase_38 | AC | 2 ms
6,940 KB |
testcase_39 | AC | 1 ms
6,944 KB |
testcase_40 | AC | 1 ms
6,940 KB |
testcase_41 | AC | 2 ms
6,944 KB |
testcase_42 | AC | 1 ms
6,940 KB |
testcase_43 | AC | 1 ms
6,944 KB |
testcase_44 | AC | 1 ms
6,940 KB |
testcase_45 | AC | 1 ms
6,944 KB |
testcase_46 | AC | 1 ms
6,940 KB |
testcase_47 | AC | 1 ms
6,940 KB |
testcase_48 | AC | 1 ms
6,940 KB |
testcase_49 | AC | 1 ms
6,940 KB |
testcase_50 | AC | 1 ms
6,944 KB |
testcase_51 | AC | 1 ms
6,940 KB |
testcase_52 | AC | 1 ms
6,940 KB |
testcase_53 | AC | 1 ms
6,940 KB |
testcase_54 | AC | 1 ms
6,940 KB |
testcase_55 | AC | 1 ms
6,944 KB |
testcase_56 | AC | 1 ms
6,940 KB |
testcase_57 | AC | 1 ms
6,940 KB |
testcase_58 | AC | 1 ms
6,940 KB |
testcase_59 | AC | 2 ms
6,940 KB |
testcase_60 | AC | 1 ms
6,940 KB |
testcase_61 | AC | 1 ms
6,940 KB |
testcase_62 | AC | 1 ms
6,940 KB |
testcase_63 | AC | 2 ms
6,944 KB |
testcase_64 | AC | 1 ms
6,940 KB |
testcase_65 | AC | 1 ms
6,944 KB |
testcase_66 | AC | 1 ms
6,940 KB |
testcase_67 | AC | 1 ms
6,944 KB |
testcase_68 | AC | 1 ms
6,940 KB |
testcase_69 | AC | 1 ms
6,944 KB |
testcase_70 | AC | 1 ms
6,940 KB |
testcase_71 | AC | 2 ms
6,944 KB |
testcase_72 | AC | 2 ms
6,944 KB |
testcase_73 | AC | 1 ms
6,944 KB |
testcase_74 | AC | 1 ms
6,944 KB |
testcase_75 | AC | 1 ms
6,944 KB |
testcase_76 | AC | 1 ms
6,940 KB |
testcase_77 | AC | 2 ms
6,944 KB |
testcase_78 | AC | 1 ms
6,940 KB |
testcase_79 | AC | 1 ms
6,940 KB |
testcase_80 | AC | 2 ms
6,944 KB |
testcase_81 | AC | 1 ms
6,940 KB |
testcase_82 | AC | 2 ms
6,944 KB |
testcase_83 | AC | 2 ms
6,944 KB |
testcase_84 | AC | 2 ms
6,944 KB |
testcase_85 | AC | 1 ms
6,940 KB |
testcase_86 | AC | 1 ms
6,944 KB |
testcase_87 | AC | 1 ms
6,944 KB |
testcase_88 | AC | 1 ms
6,940 KB |
testcase_89 | AC | 1 ms
6,944 KB |
testcase_90 | AC | 1 ms
6,940 KB |
testcase_91 | AC | 2 ms
6,940 KB |
testcase_92 | AC | 1 ms
6,944 KB |
testcase_93 | AC | 1 ms
6,944 KB |
testcase_94 | AC | 1 ms
6,944 KB |
testcase_95 | AC | 1 ms
6,940 KB |
testcase_96 | AC | 1 ms
6,940 KB |
testcase_97 | AC | 1 ms
6,944 KB |
testcase_98 | AC | 2 ms
6,940 KB |
testcase_99 | AC | 2 ms
6,940 KB |
testcase_100 | AC | 1 ms
6,940 KB |
testcase_101 | AC | 2 ms
6,944 KB |
testcase_102 | AC | 1 ms
6,944 KB |
testcase_103 | AC | 1 ms
6,944 KB |
testcase_104 | AC | 2 ms
6,940 KB |
testcase_105 | AC | 2 ms
6,940 KB |
testcase_106 | AC | 2 ms
6,940 KB |
testcase_107 | AC | 2 ms
6,944 KB |
testcase_108 | AC | 1 ms
6,940 KB |
testcase_109 | AC | 1 ms
6,940 KB |
testcase_110 | AC | 1 ms
6,944 KB |
testcase_111 | AC | 2 ms
6,944 KB |
testcase_112 | AC | 1 ms
6,944 KB |
testcase_113 | AC | 1 ms
6,940 KB |
testcase_114 | AC | 1 ms
6,940 KB |
testcase_115 | AC | 2 ms
6,940 KB |
testcase_116 | AC | 1 ms
6,944 KB |
testcase_117 | AC | 1 ms
6,940 KB |
testcase_118 | AC | 1 ms
6,940 KB |
ソースコード
/* -*- 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]; ll 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]; ll 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; reverse(ds[n], ds[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; }