結果
問題 | No.194 フィボナッチ数列の理解(1) |
ユーザー | h_noson |
提出日時 | 2016-05-25 15:38:23 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,909 bytes |
コンパイル時間 | 677 ms |
コンパイル使用メモリ | 66,156 KB |
実行使用メモリ | 11,608 KB |
最終ジャッジ日時 | 2024-10-07 14:09:08 |
合計ジャッジ時間 | 2,494 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 16 ms
6,816 KB |
testcase_03 | AC | 15 ms
6,816 KB |
testcase_04 | AC | 16 ms
6,820 KB |
testcase_05 | AC | 15 ms
6,816 KB |
testcase_06 | AC | 14 ms
6,820 KB |
testcase_07 | AC | 14 ms
6,820 KB |
testcase_08 | AC | 15 ms
6,816 KB |
testcase_09 | AC | 14 ms
6,816 KB |
testcase_10 | AC | 16 ms
6,816 KB |
testcase_11 | AC | 14 ms
6,820 KB |
testcase_12 | AC | 15 ms
6,816 KB |
testcase_13 | AC | 16 ms
6,816 KB |
testcase_14 | AC | 14 ms
6,820 KB |
testcase_15 | AC | 13 ms
6,816 KB |
testcase_16 | AC | 14 ms
6,816 KB |
testcase_17 | AC | 15 ms
6,816 KB |
testcase_18 | AC | 14 ms
6,820 KB |
testcase_19 | AC | 15 ms
6,820 KB |
testcase_20 | AC | 6 ms
11,604 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 16 ms
6,816 KB |
testcase_31 | AC | 9 ms
6,816 KB |
testcase_32 | AC | 16 ms
6,820 KB |
testcase_33 | AC | 14 ms
6,820 KB |
testcase_34 | AC | 15 ms
6,820 KB |
testcase_35 | AC | 16 ms
6,816 KB |
testcase_36 | AC | 15 ms
6,820 KB |
testcase_37 | AC | 16 ms
6,816 KB |
testcase_38 | AC | 15 ms
6,820 KB |
testcase_39 | AC | 16 ms
6,820 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:75:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 75 | 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 += f[i]; REP (i,n,k-1) { f[i] = sum; sum += f[i] - f[i-n]; } rep (i,k) s[i] = f[i] + (i > 0 ? s[i-1] : 0); 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; }