結果
| 問題 |
No.741 AscNumber(Easy)
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2018-10-10 08:48:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,657 bytes |
| コンパイル時間 | 1,512 ms |
| コンパイル使用メモリ | 85,836 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-12 17:11:27 |
| 合計ジャッジ時間 | 2,059 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 55 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:132:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
132 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 741.cc: No.741 AscNumber(Easy) - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 1000000;
const int D = 10;
const int MOD = 1000000007;
/* typedef */
typedef long long ll;
typedef int vec[D];
typedef vec mat[D];
/* global variables */
const mat MM =
{{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
};
const vec VV = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
mat ma, mb, mc;
vec va, vb, vc;
/* subroutines */
inline void initvec(vec a) { fill(a, a + D, 0.0); }
inline void initmat(mat a) {
for (int i = 0; i < D; i++) initvec(a[i]);
}
inline void unitmat(mat a) {
initmat(a);
for (int i = 0; i < D; i++) a[i][i] = 1;
}
inline void copymat(const mat a, mat b) {
memcpy(b, a, sizeof(mat));
}
inline void addmat(const mat a, const mat b, mat c) {
for (int i = 0; i < D; i++)
for (int j = 0; j < D; j++)
c[i][j] = (a[i][j] + b[i][j]) % MOD;
}
inline void mulmat(const mat a, const mat b, mat c) {
for (int i = 0; i < D; i++)
for (int j = 0; j < D; j++) {
c[i][j] = 0;
for (int k = 0; k < D; k++)
c[i][j] = (c[i][j] + (ll)a[i][k] * b[k][j] % MOD) % MOD;
}
}
inline void powmat(const mat a, int b, mat c) {
mat s, t;
copymat(a, s);
unitmat(c);
while (b > 0) {
if (b & 1) {
mulmat(c, s, t);
copymat(t, c);
}
mulmat(s, s, t);
copymat(t, s);
b >>= 1;
}
}
inline void mulmatvec(const mat a, const vec b, vec c) {
for (int i = 0; i < D; i++) {
c[i] = 0;
for (int j = 0; j < D; j++)
c[i] = (c[i] + (ll)a[i][j] * b[j] % MOD) % MOD;
}
}
void printvec(const vec a) {
for (int j = 0; j < D; j++) {
if (j) putchar(' ');
printf("%d", a[j]);
}
putchar('\n');
}
void printmat(const mat a) {
for (int i = 0; i < D; i++) printvec(a[i]);
}
/* main */
int main() {
int n;
scanf("%d", &n);
powmat(MM, n, ma);
mulmatvec(ma, VV, va);
int sum = 0;
for (int i = 0; i < D; i++)
sum = (sum + va[i]) % MOD;
printf("%d\n", sum);
return 0;
}
tnakao0123