結果
| 問題 |
No.573 a^2[i] = a[i]
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-13 05:50:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 2,000 ms |
| コード長 | 2,309 bytes |
| コンパイル時間 | 2,309 ms |
| コンパイル使用メモリ | 198,148 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-05-13 05:50:13 |
| 合計ジャッジ時間 | 4,330 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 47 |
コンパイルメッセージ
main.cpp: In function ‘void Thaer()’:
main.cpp:96:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
96 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:97:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
97 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
//#define int int64_t
#define el '\n'
namespace combinatorics {
int64_t MOD = 1e9 + 7;
int size = 0;
vector<int> _fact = {1};
vector<int> _invfact = {1};
vector<int> _inv = {1};
int64_t pw(int64_t n, int64_t e) {
int64_t ans = 1;
for (; e; n = n * n % MOD, e /= 2)
if (e & 1)
ans = ans * n % MOD;
return ans;
}
void init(int N) {
_fact.resize(N + 1);
_invfact.resize(N + 1);
_inv.resize(N + 1);
for (int64_t i = size + 1; i <= N; i++) {
_fact[i] = _fact[i - 1] * i % MOD;
}
_invfact[N] = pw(_fact[N], MOD - 2);
for (int i = N; i >= size + 1; i--) {
_invfact[i - 1] = 1LL * _invfact[i] * i % MOD;
_inv[i] = 1LL * _invfact[i] * _fact[i - 1] % MOD;
}
size = N;
}
int64_t fact(int n) {
if (n > size) init(2 * n);
return _fact[n];
}
int64_t invfact(int n) {
if (n > size)init(2 * n);
return _invfact[n];
}
int64_t inv(int n) {
if (n > size)init(2 * n);
return _inv[n];
}
int64_t npr(int n, int r) {
if (n < r)return 0;
return fact(n) * invfact(n - r) % MOD;
}
int64_t ncr(int n, int r) {
return npr(n, r) * invfact(r) % MOD;
}
int64_t catalan(int n) {
return ncr(2 * n, n) * inv(n + 1) % MOD;
}
int64_t stars_and_bars(int star, int bar) {
return ncr(star + bar - 1, star);
}
}
using namespace combinatorics;
int64_t pw(int64_t n , int64_t e,int64_t mod) {
int64_t ans = 1;
for (; e; n = n * n % mod, e /= 2)
if (e & 1) ans = ans * n % mod;
return ans;
}
void Main() {
int n;
cin >> n;
int64_t ans = 0;
for (int i = 1; i <= n; ++i) {
ans += (ncr(n, i) * pw(i, n - i, MOD)) % MOD;
ans %= MOD;
}
cout << ans;
}
void Thaer();
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
// Thaer();
int T = 1;
// cin >> T;
for (int i = 1; i <= T; ++i) {
Main();
// if (i != T)cout << el;
}
}
void Thaer() {
if (fopen("input.txt", "r")) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
}