結果

問題 No.793 うし数列 2
ユーザー sansaquasansaqua
提出日時 2019-08-06 04:42:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,803 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 75,652 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 17:37:05
合計ジャッジ時間 1,870 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0