답안 #442290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442290 2021-07-07T11:48:01 Z iANikzad Asceticism (JOI18_asceticism) C++14
49 / 100
600 ms 4228 KB
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define F first
#define S second
#define debug(x) cerr<<#x<<" :"<<x<<"\n"
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
#define int long long

typedef long long ll;
typedef long double ld;

const int maxn = 5e5 + 7;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const int mlog = 20;
const int SQ = 400;

int fact[maxn];

int pw(int a,int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1) res = res * a % mod;
        a = a*a % mod;
        b/= 2;
    }

    return res;
}

int C(int n,int r) { return fact[n] * (pw(fact[r] * fact[n - r] % mod, mod-2)) % mod;  }

int32_t main()
{
    FAST;

    fact[0] = 1;
    for(int i = 1; i < maxn; i++) fact[i] = fact[i - 1] * i % mod;

    int n, k;
  	cin >> n >> k;

    int ans = 0;
    for(int i = 0; i <= k - 1; i++)
        for(int j = 0; j <= k - i - 1; j++)
        {
            int res = (pw(k - i - j, n) * C(n - k + j, j) % mod * C(k - j, i) % mod);
            if((i + j) % 2 == 1) res *= -1;

            ans = (ans + res)  %mod;
        }
	
    ans = (ans + mod) % mod;
    cout << ans << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4172 KB Output is correct
2 Correct 6 ms 4108 KB Output is correct
3 Correct 6 ms 4204 KB Output is correct
4 Correct 6 ms 4172 KB Output is correct
5 Correct 6 ms 4172 KB Output is correct
6 Correct 6 ms 4112 KB Output is correct
7 Correct 7 ms 4200 KB Output is correct
8 Correct 6 ms 4172 KB Output is correct
9 Correct 6 ms 4172 KB Output is correct
10 Correct 6 ms 4172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4172 KB Output is correct
2 Correct 6 ms 4108 KB Output is correct
3 Correct 6 ms 4204 KB Output is correct
4 Correct 6 ms 4172 KB Output is correct
5 Correct 6 ms 4172 KB Output is correct
6 Correct 6 ms 4112 KB Output is correct
7 Correct 7 ms 4200 KB Output is correct
8 Correct 6 ms 4172 KB Output is correct
9 Correct 6 ms 4172 KB Output is correct
10 Correct 6 ms 4172 KB Output is correct
11 Correct 6 ms 4144 KB Output is correct
12 Correct 6 ms 4204 KB Output is correct
13 Correct 6 ms 4172 KB Output is correct
14 Correct 9 ms 4224 KB Output is correct
15 Correct 22 ms 4104 KB Output is correct
16 Correct 23 ms 4228 KB Output is correct
17 Correct 6 ms 4172 KB Output is correct
18 Correct 10 ms 4224 KB Output is correct
19 Correct 9 ms 4172 KB Output is correct
20 Correct 6 ms 4224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4172 KB Output is correct
2 Correct 6 ms 4108 KB Output is correct
3 Correct 6 ms 4204 KB Output is correct
4 Correct 6 ms 4172 KB Output is correct
5 Correct 6 ms 4172 KB Output is correct
6 Correct 6 ms 4112 KB Output is correct
7 Correct 7 ms 4200 KB Output is correct
8 Correct 6 ms 4172 KB Output is correct
9 Correct 6 ms 4172 KB Output is correct
10 Correct 6 ms 4172 KB Output is correct
11 Correct 6 ms 4144 KB Output is correct
12 Correct 6 ms 4204 KB Output is correct
13 Correct 6 ms 4172 KB Output is correct
14 Correct 9 ms 4224 KB Output is correct
15 Correct 22 ms 4104 KB Output is correct
16 Correct 23 ms 4228 KB Output is correct
17 Correct 6 ms 4172 KB Output is correct
18 Correct 10 ms 4224 KB Output is correct
19 Correct 9 ms 4172 KB Output is correct
20 Correct 6 ms 4224 KB Output is correct
21 Correct 6 ms 4172 KB Output is correct
22 Correct 6 ms 4224 KB Output is correct
23 Correct 43 ms 4172 KB Output is correct
24 Correct 52 ms 4212 KB Output is correct
25 Correct 173 ms 4212 KB Output is correct
26 Correct 194 ms 4208 KB Output is correct
27 Correct 187 ms 4204 KB Output is correct
28 Correct 60 ms 4152 KB Output is correct
29 Correct 9 ms 4172 KB Output is correct
30 Correct 174 ms 4172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4172 KB Output is correct
2 Correct 6 ms 4108 KB Output is correct
3 Correct 6 ms 4204 KB Output is correct
4 Correct 6 ms 4172 KB Output is correct
5 Correct 6 ms 4172 KB Output is correct
6 Correct 6 ms 4112 KB Output is correct
7 Correct 7 ms 4200 KB Output is correct
8 Correct 6 ms 4172 KB Output is correct
9 Correct 6 ms 4172 KB Output is correct
10 Correct 6 ms 4172 KB Output is correct
11 Correct 6 ms 4144 KB Output is correct
12 Correct 6 ms 4204 KB Output is correct
13 Correct 6 ms 4172 KB Output is correct
14 Correct 9 ms 4224 KB Output is correct
15 Correct 22 ms 4104 KB Output is correct
16 Correct 23 ms 4228 KB Output is correct
17 Correct 6 ms 4172 KB Output is correct
18 Correct 10 ms 4224 KB Output is correct
19 Correct 9 ms 4172 KB Output is correct
20 Correct 6 ms 4224 KB Output is correct
21 Correct 6 ms 4172 KB Output is correct
22 Correct 6 ms 4224 KB Output is correct
23 Correct 43 ms 4172 KB Output is correct
24 Correct 52 ms 4212 KB Output is correct
25 Correct 173 ms 4212 KB Output is correct
26 Correct 194 ms 4208 KB Output is correct
27 Correct 187 ms 4204 KB Output is correct
28 Correct 60 ms 4152 KB Output is correct
29 Correct 9 ms 4172 KB Output is correct
30 Correct 174 ms 4172 KB Output is correct
31 Correct 6 ms 4172 KB Output is correct
32 Correct 6 ms 4192 KB Output is correct
33 Execution timed out 1088 ms 4120 KB Time limit exceeded
34 Halted 0 ms 0 KB -