結果
問題 |
No.493 とても長い数列と文字列(Long Long Sequence and a String)
|
ユーザー |
![]() |
提出日時 | 2025-06-12 13:57:28 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,086 bytes |
コンパイル時間 | 205 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 379,688 KB |
最終ジャッジ日時 | 2025-06-12 13:58:06 |
合計ジャッジ時間 | 12,378 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 55 MLE * 1 -- * 59 |
ソースコード
MOD = 10**9 + 7 def compute_s(k): return len(str(k*k)) def compute_len(n): len_n = 1 << (n-1) sum_part = 0 current = 1 for k in range(2, n+1): s = compute_s(k) sum_part += s * (1 << (n - k)) return len_n + sum_part def get_chars(n, L, R): result = [] stack = [(n, L, R)] while stack: current_n, l, r = stack.pop() if current_n == 1: s = '1' start = max(0, l-1) end = min(len(s), r) result.append(s[start:end]) continue left_len = compute_len(current_n - 1) mid = str(current_n * current_n) mid_len = len(mid) total_len = 2 * left_len + mid_len if l > total_len or r > total_len: return None left_start = 1 left_end = left_len mid_start = left_end + 1 mid_end = left_end + mid_len right_start = mid_end + 1 right_end = total_len if r < left_start: continue if l <= left_end: new_l = l new_r = min(r, left_end) stack.append((current_n - 1, new_l, new_r)) if r >= mid_start and l <= mid_end: start = max(l, mid_start) - mid_start + 1 end = min(r, mid_end) - mid_start + 1 result.append(mid[start-1:end]) if r >= right_start and l <= right_end: new_l = l - (mid_end) new_r = r - (mid_end) stack.append((current_n - 1, new_l, new_r)) return ''.join(result) def solve(): K, L, R = map(int, input().split()) total_len = compute_len(K) if R > total_len: print(-1) return s = get_chars(K, L, R) if s is None: print(-1) return sum_total = 0 product_total = 1 for c in s: num = int(c) if num == 0: sum_total += 10 product_total = product_total * 10 % MOD else: sum_total += num product_total = product_total * num % MOD print(sum_total, product_total) solve()