Submission #19699

# Submission time Handle Problem Language Result Execution time Memory
19699 2016-02-25T04:41:40 Z csehydrogen 괄호 (kriii4_R) C++
100 / 100
402 ms 1084 KB
#include <cstdio>
typedef long long ll;
int const MOD = 1000000007;
int pow(int x, int y) {
    if (y == 1) return x;
    int ret = pow(x, y / 2);
    ret = (ll)ret * ret % MOD;
    if (y & 1)
        ret = (ll)ret * x % MOD;
    return ret;
}
int inv(int x) {
    return pow(x, MOD - 2);
}
int mul(int x, int y) {
    return (ll)x * y % MOD;
}
int add(int x, int y) {
    return (x + y) % MOD;
}
int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    int m = (n + 1) / 2;
    int z = 1, ans = 0, pk = 1;
    for (int i = n; i > n - m; --i) {
        z = mul(z, i);
    }
    for (int i = 1; i <= m; ++i) {
        z = mul(z, inv(i));
        pk = mul(pk, k);
    }
    for (int i = m + 1; i <= n; ++i) {
        int znext = z;
        znext = mul(znext, inv(i));
        znext = mul(znext, n - i + 1);
        ans = add(ans, mul((z - znext + MOD) % MOD, pk));
        z = znext;
        pk = mul(pk, k);
    }
    ans = add(ans, mul(z, pk));
    printf("%d", ans);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 122 ms 1084 KB Output is correct
2 Correct 25 ms 1084 KB Output is correct
3 Correct 296 ms 1084 KB Output is correct
4 Correct 330 ms 1084 KB Output is correct
5 Correct 337 ms 1084 KB Output is correct
6 Correct 187 ms 1084 KB Output is correct
7 Correct 210 ms 1084 KB Output is correct
8 Correct 141 ms 1084 KB Output is correct
9 Correct 58 ms 1084 KB Output is correct
10 Correct 14 ms 1084 KB Output is correct
11 Correct 15 ms 1084 KB Output is correct
12 Correct 298 ms 1084 KB Output is correct
13 Correct 286 ms 1084 KB Output is correct
14 Correct 124 ms 1084 KB Output is correct
15 Correct 133 ms 1084 KB Output is correct
16 Correct 121 ms 1084 KB Output is correct
17 Correct 368 ms 1084 KB Output is correct
18 Correct 380 ms 1084 KB Output is correct
19 Correct 402 ms 1084 KB Output is correct
20 Correct 401 ms 1084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 1084 KB Output is correct
2 Correct 35 ms 1084 KB Output is correct
3 Correct 72 ms 1084 KB Output is correct
4 Correct 363 ms 1084 KB Output is correct
5 Correct 227 ms 1084 KB Output is correct
6 Correct 281 ms 1084 KB Output is correct
7 Correct 194 ms 1084 KB Output is correct
8 Correct 110 ms 1084 KB Output is correct
9 Correct 191 ms 1084 KB Output is correct
10 Correct 25 ms 1084 KB Output is correct
11 Correct 316 ms 1084 KB Output is correct
12 Correct 332 ms 1084 KB Output is correct
13 Correct 314 ms 1084 KB Output is correct
14 Correct 148 ms 1084 KB Output is correct
15 Correct 184 ms 1084 KB Output is correct
16 Correct 181 ms 1084 KB Output is correct
17 Correct 31 ms 1084 KB Output is correct
18 Correct 401 ms 1084 KB Output is correct
19 Correct 401 ms 1084 KB Output is correct
20 Correct 401 ms 1084 KB Output is correct