답안 #127890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127890 2019-07-10T08:10:20 Z BThero Asceticism (JOI18_asceticism) C++17
100 / 100
55 ms 2040 KB
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;   
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MAXN = (int)2e5 + 5;
const int MOD = (int)1e9 + 7;

int fact[MAXN], rev[MAXN];

int n, k;

int addMod(int a, int b, int m = MOD) {
    a += b;

    if (m <= a) {
        a -= m;
    }

    return a;
}

int mulMod(int a, int b, int m = MOD) {
    return a * 1ll * b % m;
}

int binPow(int a, int b, int m = MOD) {
    int ret = 1;

    while (b > 0) {
        if (b & 1) {
            ret = mulMod(ret, a, m);
        }

        a = mulMod(a, a, m);
        b >>= 1;        
    }

    return ret;
}

void pre() {
    fact[0] = rev[0] = 1;

    for (int i = 1; i < MAXN; ++i) {
        fact[i] = mulMod(fact[i - 1], i);
        rev[i] = binPow(fact[i], MOD - 2);
    }
}

int C(int n, int k) {
    return fact[n] * 1ll * rev[k] % MOD * rev[n - k] % MOD;
}

void solve() {
    scanf("%d %d", &n, &k);
    int ans = 0;

    for (int i = 0; i <= k; ++i) {
        int cur = mulMod(binPow(k - i, n), C(n + 1, i));

        if (i & 1) {
            cur = MOD - cur;
        }

        ans = addMod(ans, cur);
    }

    printf("%d\n", ans);
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int tt = 1;

    pre();

    while (tt--) {
        solve();
    }

    return 0;
}

Compilation message

asceticism.cpp: In function 'void solve()':
asceticism.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 2040 KB Output is correct
2 Correct 45 ms 1912 KB Output is correct
3 Correct 45 ms 2040 KB Output is correct
4 Correct 45 ms 1912 KB Output is correct
5 Correct 45 ms 1912 KB Output is correct
6 Correct 45 ms 1912 KB Output is correct
7 Correct 45 ms 1912 KB Output is correct
8 Correct 45 ms 1912 KB Output is correct
9 Correct 45 ms 1912 KB Output is correct
10 Correct 45 ms 1912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 2040 KB Output is correct
2 Correct 45 ms 1912 KB Output is correct
3 Correct 45 ms 2040 KB Output is correct
4 Correct 45 ms 1912 KB Output is correct
5 Correct 45 ms 1912 KB Output is correct
6 Correct 45 ms 1912 KB Output is correct
7 Correct 45 ms 1912 KB Output is correct
8 Correct 45 ms 1912 KB Output is correct
9 Correct 45 ms 1912 KB Output is correct
10 Correct 45 ms 1912 KB Output is correct
11 Correct 45 ms 1912 KB Output is correct
12 Correct 45 ms 1912 KB Output is correct
13 Correct 45 ms 1912 KB Output is correct
14 Correct 45 ms 1912 KB Output is correct
15 Correct 45 ms 1900 KB Output is correct
16 Correct 45 ms 1912 KB Output is correct
17 Correct 45 ms 1912 KB Output is correct
18 Correct 45 ms 1912 KB Output is correct
19 Correct 44 ms 1912 KB Output is correct
20 Correct 45 ms 1912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 2040 KB Output is correct
2 Correct 45 ms 1912 KB Output is correct
3 Correct 45 ms 2040 KB Output is correct
4 Correct 45 ms 1912 KB Output is correct
5 Correct 45 ms 1912 KB Output is correct
6 Correct 45 ms 1912 KB Output is correct
7 Correct 45 ms 1912 KB Output is correct
8 Correct 45 ms 1912 KB Output is correct
9 Correct 45 ms 1912 KB Output is correct
10 Correct 45 ms 1912 KB Output is correct
11 Correct 45 ms 1912 KB Output is correct
12 Correct 45 ms 1912 KB Output is correct
13 Correct 45 ms 1912 KB Output is correct
14 Correct 45 ms 1912 KB Output is correct
15 Correct 45 ms 1900 KB Output is correct
16 Correct 45 ms 1912 KB Output is correct
17 Correct 45 ms 1912 KB Output is correct
18 Correct 45 ms 1912 KB Output is correct
19 Correct 44 ms 1912 KB Output is correct
20 Correct 45 ms 1912 KB Output is correct
21 Correct 50 ms 1832 KB Output is correct
22 Correct 45 ms 1880 KB Output is correct
23 Correct 45 ms 1912 KB Output is correct
24 Correct 45 ms 1884 KB Output is correct
25 Correct 45 ms 1876 KB Output is correct
26 Correct 45 ms 2040 KB Output is correct
27 Correct 45 ms 1996 KB Output is correct
28 Correct 45 ms 1912 KB Output is correct
29 Correct 46 ms 1912 KB Output is correct
30 Correct 45 ms 1888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 2040 KB Output is correct
2 Correct 45 ms 1912 KB Output is correct
3 Correct 45 ms 2040 KB Output is correct
4 Correct 45 ms 1912 KB Output is correct
5 Correct 45 ms 1912 KB Output is correct
6 Correct 45 ms 1912 KB Output is correct
7 Correct 45 ms 1912 KB Output is correct
8 Correct 45 ms 1912 KB Output is correct
9 Correct 45 ms 1912 KB Output is correct
10 Correct 45 ms 1912 KB Output is correct
11 Correct 45 ms 1912 KB Output is correct
12 Correct 45 ms 1912 KB Output is correct
13 Correct 45 ms 1912 KB Output is correct
14 Correct 45 ms 1912 KB Output is correct
15 Correct 45 ms 1900 KB Output is correct
16 Correct 45 ms 1912 KB Output is correct
17 Correct 45 ms 1912 KB Output is correct
18 Correct 45 ms 1912 KB Output is correct
19 Correct 44 ms 1912 KB Output is correct
20 Correct 45 ms 1912 KB Output is correct
21 Correct 50 ms 1832 KB Output is correct
22 Correct 45 ms 1880 KB Output is correct
23 Correct 45 ms 1912 KB Output is correct
24 Correct 45 ms 1884 KB Output is correct
25 Correct 45 ms 1876 KB Output is correct
26 Correct 45 ms 2040 KB Output is correct
27 Correct 45 ms 1996 KB Output is correct
28 Correct 45 ms 1912 KB Output is correct
29 Correct 46 ms 1912 KB Output is correct
30 Correct 45 ms 1888 KB Output is correct
31 Correct 46 ms 1932 KB Output is correct
32 Correct 45 ms 1920 KB Output is correct
33 Correct 45 ms 1912 KB Output is correct
34 Correct 46 ms 1912 KB Output is correct
35 Correct 53 ms 1912 KB Output is correct
36 Correct 54 ms 1912 KB Output is correct
37 Correct 55 ms 1884 KB Output is correct
38 Correct 46 ms 1912 KB Output is correct
39 Correct 48 ms 1912 KB Output is correct
40 Correct 49 ms 1912 KB Output is correct