結果
| 問題 |
No.194 フィボナッチ数列の理解(1)
|
| コンテスト | |
| ユーザー |
h_noson
|
| 提出日時 | 2016-05-25 15:38:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 WA * 9 |
コンパイルメッセージ
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;
}
h_noson