Submission #1003695

# Submission time Handle Problem Language Result Execution time Memory
1003695 2024-06-20T15:39:05 Z AdamGS Asceticism (JOI18_asceticism) C++17
49 / 100
97 ms 144012 KB
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll MOD=1e9+7;
const int LIM=3e3+7;
ll dp[LIM][LIM], sil[LIM], osil[LIM];
ll pot(ll a, ll b) {
  ll ans=1;
  while(b) {
    if(b&1) ans=(ans*a)%MOD;
    a=(a*a)%MOD;
    b/=2;
  }
  return ans;
}
ll C(ll n, ll k) {
  if(k>n || n<0) return 0;
  return (((sil[n]*osil[k])%MOD)*osil[n-k])%MOD;
}
int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  ll n, k;
  cin >> n >> k;
  sil[0]=1;
  for(ll i=1; i<=n; ++i) sil[i]=(sil[i-1]*i)%MOD;
  rep(i, n+1) osil[i]=pot(sil[i], MOD-2);
  dp[1][1]=1;
  for(int i=2; i<=n; ++i) for(ll j=1; j<=i; ++j) dp[i][j]=(dp[i-1][j]*j+dp[i-1][j-1])%MOD;
  ll ans=0;
  rep(i, k) {
    ll x=(dp[n][k-i]*sil[k-i])%MOD;
    x=(x*C(n-(k-i), i))%MOD;
    if(i%2==1) x=(MOD-x)%MOD;
    ans=(ans+x)%MOD;
  }
  cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 3 ms 24924 KB Output is correct
22 Correct 4 ms 24924 KB Output is correct
23 Correct 3 ms 24924 KB Output is correct
24 Correct 3 ms 25100 KB Output is correct
25 Correct 3 ms 24924 KB Output is correct
26 Correct 3 ms 25112 KB Output is correct
27 Correct 3 ms 24924 KB Output is correct
28 Correct 2 ms 14796 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 3 ms 24924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 1 ms 8540 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 3 ms 24924 KB Output is correct
22 Correct 4 ms 24924 KB Output is correct
23 Correct 3 ms 24924 KB Output is correct
24 Correct 3 ms 25100 KB Output is correct
25 Correct 3 ms 24924 KB Output is correct
26 Correct 3 ms 25112 KB Output is correct
27 Correct 3 ms 24924 KB Output is correct
28 Correct 2 ms 14796 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 3 ms 24924 KB Output is correct
31 Runtime error 97 ms 144012 KB Execution killed with signal 11
32 Halted 0 ms 0 KB -