提出 #14765903
ソースコード 拡げる
#include <bits/stdc++.h>
#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif
//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}
const int N = 5e5 + 10;
const int mod = 1e9 + 7;
int n, m;
LL dp[N];
LL func(int n, int m)
{
if (dp[n] != -1) return dp[n];
if (n == 0) return 1;
if (n == 1) return (m - 1) % mod;
LL v1 = (n - 1) * func(n - 2, m - 2);
LL v2 = (m - 1) * func(n - 1, m - 1);
return dp[n] = (v1 + v2) % mod;
}
LL f1[N];
LL f2[N];
int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif
f1[1] = 1;
for (int i = 2; i <= 5e5; i++) f1[i] = f1[i - 1] * i % mod;
f2[0] = 1;
f2[1] = 1;
for (int i = 2; i <= 5e5; i++) f2[i] = f2[mod % i] * (mod - mod / i) % mod;
for (int i = 2; i <= 5e5; i++) f2[i] = f2[i - 1] * f2[i] % mod;
while (cin >> n >> m)
{
LL ans = f1[m];
ans = (ans * f2[m - n]) % mod;
clr(dp, -1);
LL v = func(n, m);
// debug(v);
ans = (ans * v) % mod;
cout << ans << endl;
}
return 0;
}
提出情報
提出日時
2020-06-27 22:10:05+0900
問題
E - NEQ
ユーザ
mickeyandkaka
言語
C++ (GCC 9.2.1)
得点
500
コード長
1844 Byte
結果
AC
実行時間
39 ms
メモリ
26980 KiB
コンパイルエラー
./Main.cpp: In function ‘std::vector<std::__cxx11::basic_string<char> > split(const string&, char)’:
./Main.cpp:18:96: warning: this ‘while’ clause does not guard... [-Wmisleading-indentation]
18 | vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
| ^~~~~
./Main.cpp:19:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘while’
19 | (getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
| ^~~~~~
ジャッジ結果
セット名
Sample
All
得点 / 配点
0 / 0
500 / 500
結果
セット名
テストケース
Sample
sample00, sample01, sample02
All
handmade03, handmade04, handmade05, handmade06, handmade07, random08, random09, random10, random11, sample00, sample01, sample02
ケース名
結果
実行時間
メモリ
handmade03
AC
30 ms
15196 KiB
handmade04
AC
29 ms
15268 KiB
handmade05
AC
21 ms
15092 KiB
handmade06
AC
29 ms
15268 KiB
handmade07
AC
38 ms
26980 KiB
random08
AC
39 ms
25444 KiB
random09
AC
27 ms
18700 KiB
random10
AC
35 ms
19764 KiB
random11
AC
31 ms
16416 KiB
sample00
AC
23 ms
15168 KiB
sample01
AC
32 ms
15224 KiB
sample02
AC
29 ms
18616 KiB