結果
| 問題 |
No.793 うし数列 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-02-22 21:47:42 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 1,794 bytes |
| コンパイル時間 | 670 ms |
| コンパイル使用メモリ | 109,736 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-13 04:10:32 |
| 合計ジャッジ時間 | 1,412 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;
void main() {
long n;
scan(n);
auto a = [[10L, 3L], [0L, 1L]];
auto e = iota(2).map!(i => iota(2).map!(j => i == j ? 1L : 0L).array).array;
debug {
writeln(e);
writeln(a);
}
long[][] mul(long[][] a, long[][] b) {
auto c = new long[][](2, 2);
foreach (i ; 0 .. 2) {
foreach (j ; 0 .. 2) {
foreach (k ; 0 .. 2) {
c[i][j] += a[i][k] * b[k][j] % mod;
c[i][j] %= mod;
}
}
}
return c;
}
long[][] sqm(long[][] a) {
return mul(a, a);
}
long[][] powm(long k) {
return k > 0 ? mul(sqm(powm(k>>1)), k & 1 ? a : e) : e;
}
auto t = powm(n);
long ans;
foreach (j ; 0 .. 2) {
ans += t[0][j];
ans %= mod;
}
writeln(ans);
}
void yes(bool b) {writeln(b ? "Yes" : "No");}
void YES(bool b) {writeln(b ? "YES" : "NO");}
T[] readArr(T)() {return readln.split.to!(T[]);}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront();
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}