結果
| 問題 | No.573 a^2[i] = a[i] |
| コンテスト | |
| ユーザー |
ats5515
|
| 提出日時 | 2017-10-06 23:27:17 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,464 bytes |
| 記録 | |
| コンパイル時間 | 385 ms |
| コンパイル使用メモリ | 92,552 KB |
| 最終ジャッジ日時 | 2026-05-12 04:47:21 |
| 合計ジャッジ時間 | 960 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / tmp-judge_1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In instantiation of 'struct comb_util<long long int, 1000000007, 100005>':
main.cpp:64:7: required from here
64 | comb cb;
| ^~
main.cpp:17:32: error: 'comb_util<Int, MOD, N>::fc' has incomplete type
17 | std::array<Int, N + 1> fc, ifc;
| ^~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:64,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/string:53,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/locale_classes.h:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ios_base.h:43,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ios:46,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:43,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<long long int, 100006>'
99 | struct array;
| ^~~~~
main.cpp:17:36: error: 'comb_util<Int, MOD, N>::ifc' has incomplete type
17 | std::array<Int, N + 1> fc, ifc;
| ^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<long long int, 100006>'
99 | struct array;
| ^~~~~
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int t;
template <typename Int, Int MOD, int N>
struct comb_util {
std::array<Int, N + 1> fc, ifc;
comb_util() {
fc[0] = 1;
for (int i = 1; i <= N; i++) fc[i] = fc[i - 1] * i % MOD;
ifc[N] = inv(fc[N]);
for (int i = N - 1; i >= 0; i--) ifc[i] = ifc[i + 1] * (i + 1) % MOD;
}
Int fact(Int n) { return fc[n]; }
Int inv_fact(Int n) { return ifc[n]; }
Int inv(Int n) { return pow(n, MOD - 2); }
Int pow(Int n, Int a) {
Int res = 1, exp = n;
for (; a; a /= 2) {
if (a & 1) res = res * exp % MOD;
exp = exp * exp % MOD;
}
return res;
}
Int perm(Int n, Int r) {
if (r < 0 || n < r)
return 0;
else
return fc[n] * ifc[n - r] % MOD;
}
Int binom(Int n, Int r) {
if (n < 0 || r < 0 || n < r) return 0;
return fc[n] * ifc[r] % MOD * ifc[n - r] % MOD;
}
Int homo(Int n, Int r) {
if (n < 0 || r < 0) return 0;
return r == 0 ? 1 : binom(n + r - 1, r);
}
};
using comb = comb_util<long long, 1000000007, 100005>;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
comb cb;
int N;
cin >> N;
int k;
int res = 0;
for (int i = 1; i <= N; i++) {
k = cb.binom(N, i);
k = (k*cb.pow(N - i, i)) % MOD;
res = (res + k) % MOD;
}
cout << (res+1) % MOD << endl;
}
ats5515