結果
| 問題 |
No.793 うし数列 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-06 04:42:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,803 bytes |
| コンパイル時間 | 583 ms |
| コンパイル使用メモリ | 75,704 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-18 13:51:14 |
| 合計ジャッジ時間 | 1,353 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
#include <iostream>
#include <vector>
#include <utility>
#include <set>
#include <list>
#include <functional>
using namespace std;
using ll = long long int;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL_INCLUDED_ENVIRONMENT
template <class T> std::ostream& operator<<(std::ostream& o, const std::vector<T>& v) {
o << "{";
for (int i = 0; i < (int) v.size(); i++)
o << (i > 0 ? ", " : "" ) << v[i];
o << "}";
return o;
}
template <class T> std::ostream& operator<<(std::ostream& o, const std::list<T>& lst) {
o << "{";
for (auto itr = lst.begin(); itr != lst.end(); itr++)
o << (itr == lst.begin() ? "" : ", " ) << *itr;
o << "}";
return o;
}
template <class X, class Y> std::ostream& operator<<(std::ostream& o, const std::pair<X, Y>& p) {
o << "(" << p.first << ", " << p.second << ")";
return o;
}
template <class T, class Monoid> struct Power {
static T power(T base, ll exp) {
if (exp == 0) {
return Monoid::id;
} else if (exp & 1) {
return Monoid::op(base, power(base, exp - 1));
} else {
return power(Monoid::op(base, base), exp >> 1);
}
}
};
const ll MOD = 1000000007;
template <class T> struct ModularProduct {
const static T id = 1;
static ll op(T a, T b) {
return (a * b) % MOD;
}
};
ll calc (ll len) {
if (len == 0)
return 0;
else if (len & 1) {
return (3 + (calc(len - 1) * 10) % MOD) % MOD;
} else {
ll res = calc(len >> 1);
ll shift = Power<ll, ModularProduct<ll> >::power(10, len >> 1);
return (res + (res * shift) % MOD) % MOD;
}
}
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
ll n;
cin >> n;
ll highest = Power<ll, ModularProduct<ll> >::power(10, n);
ll res = (calc(n) + highest) % MOD;
cout << res << "\n";
return 0;
}