結果
問題 | No.194 フィボナッチ数列の理解(1) |
ユーザー | h_noson |
提出日時 | 2016-05-25 15:50:33 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 18 ms / 5,000 ms |
コード長 | 1,980 bytes |
コンパイル時間 | 738 ms |
コンパイル使用メモリ | 66,024 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-10-07 14:09:52 |
合計ジャッジ時間 | 2,525 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 16 ms
5,248 KB |
testcase_03 | AC | 15 ms
5,248 KB |
testcase_04 | AC | 17 ms
5,248 KB |
testcase_05 | AC | 15 ms
5,248 KB |
testcase_06 | AC | 14 ms
5,248 KB |
testcase_07 | AC | 16 ms
5,248 KB |
testcase_08 | AC | 16 ms
5,248 KB |
testcase_09 | AC | 14 ms
5,248 KB |
testcase_10 | AC | 16 ms
5,248 KB |
testcase_11 | AC | 15 ms
5,248 KB |
testcase_12 | AC | 15 ms
5,248 KB |
testcase_13 | AC | 16 ms
5,248 KB |
testcase_14 | AC | 15 ms
5,248 KB |
testcase_15 | AC | 14 ms
5,248 KB |
testcase_16 | AC | 14 ms
5,248 KB |
testcase_17 | AC | 16 ms
5,248 KB |
testcase_18 | AC | 15 ms
5,248 KB |
testcase_19 | AC | 15 ms
5,248 KB |
testcase_20 | AC | 18 ms
11,352 KB |
testcase_21 | AC | 18 ms
11,520 KB |
testcase_22 | AC | 18 ms
11,392 KB |
testcase_23 | AC | 4 ms
5,248 KB |
testcase_24 | AC | 11 ms
7,424 KB |
testcase_25 | AC | 11 ms
7,040 KB |
testcase_26 | AC | 11 ms
6,784 KB |
testcase_27 | AC | 10 ms
7,936 KB |
testcase_28 | AC | 5 ms
5,248 KB |
testcase_29 | AC | 16 ms
10,752 KB |
testcase_30 | AC | 15 ms
5,248 KB |
testcase_31 | AC | 9 ms
5,248 KB |
testcase_32 | AC | 16 ms
5,248 KB |
testcase_33 | AC | 14 ms
5,248 KB |
testcase_34 | AC | 15 ms
5,248 KB |
testcase_35 | AC | 16 ms
5,248 KB |
testcase_36 | AC | 16 ms
5,248 KB |
testcase_37 | AC | 16 ms
5,248 KB |
testcase_38 | AC | 15 ms
5,248 KB |
testcase_39 | AC | 16 ms
5,248 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:60:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 60 | scanf("%d%lld",&n,&k); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:62:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 62 | rep (i,n) scanf("%d",f+i); | ~~~~~^~~~~~~~~~ main.cpp:76:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 76 | rep (i,n) scanf("%d",a+i+1); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <iostream> #include <vector> #include <map> #include <algorithm> using namespace std; #define REP(i,s,e) for (i = s; i <= e; i++) #define rep(i,n) REP (i,0,(int)(n)-1) #define RREP(i,s,e) for (i = s; i >= e; i--) #define rrep(i,n) RREP (i,(int)(n)-1,0) #define INF (int)1e8 #define MOD (int)(1e9+7) #define MAX 31 typedef long long ll; typedef ll M[MAX][MAX]; int f[1001001], s[1001001]; void multMM(M a, M b) { int i, j, k; M c; rep (i,MAX) rep (j,MAX) c[i][j] = 0; rep (i,MAX) rep (j,MAX) rep (k,MAX) { c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD; c[i][j] = (c[i][j] + MOD) % MOD; } rep (i,MAX) rep (j,MAX) a[i][j] = c[i][j]; } void powMM(M a, ll n) { int i, j; M tmp; rep (i,MAX) rep (j,MAX) tmp[i][j] = i == j; while (n > 0) { if (n % 2) { multMM(tmp,a); } multMM(a,a); n /= 2; } rep (i,MAX) rep (j,MAX) a[i][j] = tmp[i][j]; } void multMV(M a, int b[MAX]) { int i, j; int tmp[MAX]; rep (i,MAX) tmp[i] = 0; rep (i,MAX) rep (j,MAX) { tmp[i] = (tmp[i] + a[i][j] * b[j]) % MOD; tmp[i] = (tmp[i] + MOD) % MOD; } rep (i,MAX) b[i] = tmp[i]; } int main(void) { int i, n; ll k; scanf("%d%lld",&n,&k); if (k <= (int)1e6) { rep (i,n) scanf("%d",f+i); int sum = 0; rep (i,n) sum = (sum + f[i]) % MOD; REP (i,n,k-1) { f[i] = sum; sum = (sum + f[i] - f[i-n]) % MOD; sum = (sum + MOD) % MOD; } rep (i,k) s[i] = (f[i] + (i > 0 ? s[i-1] : 0)) % MOD; printf("%d %d\n", f[k-1], s[k-1]); } else { int a[MAX] {}; M mat {}; rep (i,n) scanf("%d",a+i+1); rep (i,n) a[i+1] += a[i]; rep (i,n) mat[i][i+1] = 1; mat[n][0] = -1; mat[n][n] = 2; powMM(mat,k-n); multMV(mat,a); printf("%d %d\n",(a[n]-a[n-1]+MOD)%MOD,a[n]); } return 0; }