답안 #528832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528832 2022-02-21T14:30:42 Z NaimSS Asceticism (JOI18_asceticism) C++14
100 / 100
11 ms 1996 KB
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
//#define left oooooopss
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll b,ll e,ll m){
  b%=m;
  ll ans = 1;
  for (; e; b = b * b % m, e /= 2)
      if (e & 1) ans = ans * b % m;
  return ans;
}

// debug:
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ 
  cerr << ' ' << H; 
  dbg_out(T...); 
}
#ifdef LOCAL
#define dbg(...) cerr<<"(" << #__VA_ARGS__<<"):" , dbg_out(__VA_ARGS__) , cerr << endl
#else
#define dbg(...) 42
#endif
//

const int N = 100100;
const int M = 1e9 + 7;
// long long?

ll fat[N],inv[N];
ll C(int n,int k){
  if(k>n)return 0;
  return (fat[n]*inv[k]%M*inv[n-k]%M);
}

void init(){
  fat[0] = inv[0] = 1;
  for(int i=1;i<N;i++){
    fat[i] = (1LL*fat[i-1]*i)%M;
  }
  inv[N-1] = exp(fat[N-1],M-2,M);
  for(int i=N-2;i>=0;i--){
    inv[i] = (inv[i+1]*(i+1))%M;
  }
}


int32_t main(){
  fastio;
  init();
  int n,k;
  cin >> n >> k;
  ll res=0;
  rep(j,0,k+1){
    ll cur = C(n+1,j) * exp(k-j,n,M)%M;
    if(j&1)res = (res - cur + M)%M;
    else res = (res + cur)%M;
  }
  cout <<(res + M)%M << endl;
  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 2 ms 1868 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 2 ms 1868 KB Output is correct
6 Correct 2 ms 1884 KB Output is correct
7 Correct 2 ms 1888 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 2 ms 1884 KB Output is correct
10 Correct 2 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 2 ms 1868 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 2 ms 1868 KB Output is correct
6 Correct 2 ms 1884 KB Output is correct
7 Correct 2 ms 1888 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 2 ms 1884 KB Output is correct
10 Correct 2 ms 1880 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 2 ms 1880 KB Output is correct
14 Correct 2 ms 1868 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 2 ms 1868 KB Output is correct
17 Correct 2 ms 1868 KB Output is correct
18 Correct 2 ms 1868 KB Output is correct
19 Correct 3 ms 1996 KB Output is correct
20 Correct 2 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 2 ms 1868 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 2 ms 1868 KB Output is correct
6 Correct 2 ms 1884 KB Output is correct
7 Correct 2 ms 1888 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 2 ms 1884 KB Output is correct
10 Correct 2 ms 1880 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 2 ms 1880 KB Output is correct
14 Correct 2 ms 1868 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 2 ms 1868 KB Output is correct
17 Correct 2 ms 1868 KB Output is correct
18 Correct 2 ms 1868 KB Output is correct
19 Correct 3 ms 1996 KB Output is correct
20 Correct 2 ms 1868 KB Output is correct
21 Correct 2 ms 1868 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1880 KB Output is correct
24 Correct 2 ms 1872 KB Output is correct
25 Correct 2 ms 1868 KB Output is correct
26 Correct 3 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 2 ms 1884 KB Output is correct
29 Correct 3 ms 1884 KB Output is correct
30 Correct 3 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 2 ms 1868 KB Output is correct
4 Correct 2 ms 1884 KB Output is correct
5 Correct 2 ms 1868 KB Output is correct
6 Correct 2 ms 1884 KB Output is correct
7 Correct 2 ms 1888 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 2 ms 1884 KB Output is correct
10 Correct 2 ms 1880 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 2 ms 1880 KB Output is correct
14 Correct 2 ms 1868 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 2 ms 1868 KB Output is correct
17 Correct 2 ms 1868 KB Output is correct
18 Correct 2 ms 1868 KB Output is correct
19 Correct 3 ms 1996 KB Output is correct
20 Correct 2 ms 1868 KB Output is correct
21 Correct 2 ms 1868 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1880 KB Output is correct
24 Correct 2 ms 1872 KB Output is correct
25 Correct 2 ms 1868 KB Output is correct
26 Correct 3 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 2 ms 1884 KB Output is correct
29 Correct 3 ms 1884 KB Output is correct
30 Correct 3 ms 1868 KB Output is correct
31 Correct 2 ms 1996 KB Output is correct
32 Correct 2 ms 1880 KB Output is correct
33 Correct 3 ms 1884 KB Output is correct
34 Correct 4 ms 1872 KB Output is correct
35 Correct 9 ms 1872 KB Output is correct
36 Correct 10 ms 1884 KB Output is correct
37 Correct 11 ms 1884 KB Output is correct
38 Correct 3 ms 1888 KB Output is correct
39 Correct 5 ms 1888 KB Output is correct
40 Correct 5 ms 1872 KB Output is correct