結果
| 問題 | No.793 うし数列 2 |
| コンテスト | |
| ユーザー |
ei1333333
|
| 提出日時 | 2018-10-27 23:52:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 690 bytes |
| 記録 | |
| コンパイル時間 | 1,583 ms |
| コンパイル使用メモリ | 192,516 KB |
| 最終ジャッジ日時 | 2025-01-06 14:54:59 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 8 TLE * 13 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using int64 = long long;
const int64 mod = 1e9 + 7;
using pi = pair< int, int >;
int64 power(int64 x, int64 n) {
int64 ret = 1;
while(n > 0) {
if(n & 1) (ret *= x) %= mod;
(x *= x) %= mod;
n >>= 1;
}
return ret;
}
int64 rec(int64 length, int64 weight, bool l) {
if(length == 1) return l ? weight : 3 * weight % mod;
int64 mid = length >> 1;
int64 ret = 0;
(ret += rec(mid, weight, false)) %= mod;
(ret += rec(length - mid, weight * power(10, mid) % mod, l)) %= mod;
return ret;
}
int main() {
int64 N;
cin >> N;
assert(1LL <= N && N <= 1000000000000000000LL);
cout << rec(N + 1, 1, true) << endl;
}
ei1333333