結果

問題 No.1136 Four Points Tour
ユーザー りあんりあん
提出日時 2021-08-11 12:48:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 5,497 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 89,156 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-24 23:16:44
合計ジャッジ時間 1,906 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
01_Sample03_evil.txt AC 2 ms
6,944 KB
04_Rnd_large_evil1.txt AC 2 ms
6,944 KB
04_Rnd_large_evil2.txt AC 2 ms
6,944 KB
04_Rnd_large_evil3.txt AC 2 ms
6,940 KB
04_Rnd_large_evil4.txt AC 2 ms
6,940 KB
04_Rnd_large_evil5.txt AC 2 ms
6,944 KB
04_Rnd_large_evil6.txt AC 2 ms
6,944 KB
04_Rnd_large_evil7.txt AC 2 ms
6,944 KB
04_Rnd_large_evil8.txt AC 2 ms
6,944 KB
04_Rnd_large_evil9.txt AC 2 ms
6,940 KB
04_Rnd_large_evil10.txt AC 2 ms
6,940 KB
05_Rnd_huge_evil1.txt AC 2 ms
6,940 KB
05_Rnd_huge_evil2.txt AC 2 ms
6,944 KB
05_Rnd_huge_evil3.txt AC 2 ms
6,940 KB
05_Rnd_huge_evil4.txt AC 2 ms
6,940 KB
05_Rnd_huge_evil5.txt AC 2 ms
6,940 KB
05_Rnd_huge_evil6.txt AC 1 ms
6,940 KB
05_Rnd_huge_evil7.txt AC 2 ms
6,940 KB
99_evil_01.txt AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// This C++ code is transpiled using Jikka transpiler v5.2.0.0 https://github.com/kmyk/Jikka
// The original Python code:
//     from typing import *
//     
//     
//     def solve(n: int) -> int:
//         a = 1
//         bcd = 0
//         for _ in range(n):
//             tmp = bcd
//             bcd = a * 3 + bcd * 2
//             a = tmp
//         return a % 1000000007
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdint>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <vector>
#line 3 "jikka/modulo_matrix.hpp"
/**
 * @file jikka/modulo_matrix.hpp
 * @author Kimiyuki Onaka
 * @copyright Apache License 2.0
 */
#line 3 "jikka/divmod.hpp"
/**
 * @file jikka/divmod.hpp
 * @author Kimiyuki Onaka
 * @copyright Apache License 2.0
 */
#include <cassert>
#include <cstdint>

namespace jikka {

inline int64_t floordiv(int64_t n, int64_t d) {
  assert(d != 0);
  return n / d - ((n ^ d) < 0 && n % d);
}

inline int64_t floormod(int64_t n, int64_t d) {
  assert(d != 0);
  n %= d;
  return (n < 0 ? n + d : n);
}

inline int64_t ceildiv(int64_t n, int64_t d) {
  assert(d != 0);
  return n / d + ((n ^ d) >= 0 && n % d);
}

inline int64_t ceilmod(int64_t n, int64_t d) {
  assert(d != 0);
  return n - ceildiv(n, d) * d;
}

} // namespace jikka

#line 3 "jikka/matrix.hpp"
/**
 * @file jikka/matrix.hpp
 * @author Kimiyuki Onaka
 * @copyright Apache License 2.0
 */
#include <array>

namespace jikka {

template <typename T, size_t H, size_t W>
using matrix = std::array<std::array<T, W>, H>;

namespace mat {

template <size_t H, size_t W>
std::array<int64_t, H> ap(const matrix<int64_t, H, W> &a,
                          const std::array<int64_t, W> &b) {
  std::array<int64_t, H> c = {};
  for (size_t y = 0; y < H; ++y) {
    for (size_t x = 0; x < W; ++x) {
      c[y] += a[y][x] * b[x];
    }
  }
  return c;
}

template <size_t N> matrix<int64_t, N, N> zero() { return {}; }

template <size_t N> matrix<int64_t, N, N> one() {
  matrix<int64_t, N, N> a = {};
  for (size_t i = 0; i < N; ++i) {
    a[i][i] = 1;
  }
  return a;
}

template <size_t H, size_t W>
matrix<int64_t, H, W> add(const matrix<int64_t, H, W> &a,
                          const matrix<int64_t, H, W> &b) {
  matrix<int64_t, H, W> c;
  for (size_t y = 0; y < H; ++y) {
    for (size_t x = 0; x < W; ++x) {
      c[y][x] = a[y][x] + b[y][x];
    }
  }
  return c;
}

template <size_t H, size_t N, size_t W>
matrix<int64_t, H, W> mul(const matrix<int64_t, H, N> &a,
                          const matrix<int64_t, N, W> &b) {
  matrix<int64_t, H, W> c = {};
  for (size_t y = 0; y < H; ++y) {
    for (size_t z = 0; z < N; ++z) {
      for (size_t x = 0; x < W; ++x) {
        c[y][x] += a[y][z] * b[z][x];
      }
    }
  }
  return c;
}

template <size_t N>
matrix<int64_t, N, N> pow(matrix<int64_t, N, N> x, int64_t k) {
  matrix<int64_t, N, N> y = one<N>();
  for (; k; k >>= 1) {
    if (k & 1) {
      y = mul(y, x);
    }
    x = mul(x, x);
  }
  return y;
}

} // namespace mat

} // namespace jikka

#line 10 "jikka/modulo_matrix.hpp"
#include <array>

namespace jikka {

namespace modmat {

using jikka::floormod;

template <size_t N>
std::array<int64_t, N> floormod(std::array<int64_t, N> x, int64_t MOD) {
  for (size_t i = 0; i < N; ++i) {
    x[i] = floormod(x[i], MOD);
  }
  return x;
}

template <size_t H, size_t W>
matrix<int64_t, H, W> floormod(matrix<int64_t, H, W> a, int64_t MOD) {
  for (size_t y = 0; y < H; ++y) {
    for (size_t x = 0; x < W; ++x) {
      a[y][x] = floormod(a[y][x], MOD);
    }
  }
  return a;
}

template <size_t H, size_t W>
std::array<int64_t, H> ap(const matrix<int64_t, H, W> &a,
                          const std::array<int64_t, W> &b, int64_t MOD) {
  std::array<int64_t, H> c = {};
  for (size_t y = 0; y < H; ++y) {
    for (size_t x = 0; x < W; ++x) {
      c[y] += a[y][x] * b[x] % MOD;
    }
    c[y] = floormod(c[y], MOD);
  }
  return c;
}

template <size_t H, size_t W>
matrix<int64_t, H, W> add(const matrix<int64_t, H, W> &a,
                          const matrix<int64_t, H, W> &b, int64_t MOD) {
  matrix<int64_t, H, W> c;
  for (size_t y = 0; y < H; ++y) {
    for (size_t x = 0; x < W; ++x) {
      c[y][x] = floormod(a[y][x] + b[y][x], MOD);
    }
  }
  return c;
}

template <size_t H, size_t N, size_t W>
matrix<int64_t, H, W> mul(const matrix<int64_t, H, N> &a,
                          const matrix<int64_t, N, W> &b, int64_t MOD) {
  matrix<int64_t, H, W> c = {};
  for (size_t y = 0; y < H; ++y) {
    for (size_t z = 0; z < N; ++z) {
      for (size_t x = 0; x < W; ++x) {
        c[y][x] += a[y][z] * b[z][x] % MOD;
      }
    }
  }
  for (size_t y = 0; y < H; ++y) {
    for (size_t x = 0; x < W; ++x) {
      c[y][x] = floormod(c[y][x], MOD);
    }
  }
  return c;
}

template <size_t N>
matrix<int64_t, N, N> pow(matrix<int64_t, N, N> x, int64_t k, int64_t MOD) {
  matrix<int64_t, N, N> y = mat::one<N>();
  for (; k; k >>= 1) {
    if (k & 1) {
      y = mul(y, x, MOD);
    }
    x = mul(x, x, MOD);
  }
  return y;
}

} // namespace modmat

} // namespace jikka

#line 12 "main.cpp"
int64_t solve(int64_t n_0) {
    return jikka::modmat::ap<2, 2>(jikka::modmat::pow<2>(std::array<std::array<int64_t, 2>, 2>{std::array<int64_t, 2>{0, 1}, std::array<int64_t, 2>{3, 2}}, n_0, 1000000007), std::array<int64_t, 2>{1, 0}, 1000000007)[0];
}
int main() {
    int64_t x1 = -1;
    std::cin >> x1;
    auto x2 = solve(x1);
    std::cout << x2 << ' ';
}
0