Submission #1437023


Source Code Expand

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

immutable long MOD = 1777777777;

void main() {
    auto s = readln.split.map!(to!long);
    auto N = s[0];
    auto K = s[1];

    int MAX = 10^^6;
    auto modinv = new long[](MAX);
    modinv[0] = modinv[1] = 1;
    foreach(i; 2..MAX) {
        modinv[i] = modinv[MOD % i] * (MOD - MOD / i) % MOD;
    }

    auto f_mod = new long[](MAX);
    auto f_modinv = new long[](MAX);
    f_mod[0] = f_mod[1] = 1;
    f_modinv[0] = f_modinv[1] = 1;

    foreach(i; 2..MAX) {
        f_mod[i] = (i * f_mod[i-1]) % MOD;
        f_modinv[i] = (modinv[i] * f_modinv[i-1]) % MOD;
    }

    long ncr(long n, long r) {
        return f_mod[n.to!int] * f_modinv[(n-r).to!int] % MOD * f_modinv[r.to!int] % MOD;
    }

    long ans = 0;
    foreach (i; iota(K, -1, -1)) {
        ans = (K - i) % 2 == 0 ? ans + ncr(K, i) * f_mod[i] % MOD : ans - ncr(K, i) * f_mod[i] % MOD;
        ans = (ans % MOD + MOD) % MOD;
    }

    long nck = 1;
    foreach (i; 0..K) nck = nck * (N - i) % MOD;
    nck = nck * f_modinv[K.to!int] % MOD;

    writeln(ans * nck % MOD);
}

Submission Info

Submission Time
Task C - 高橋君、24歳
User nebukuro09
Language D (LDC 0.17.0)
Score 40
Code Size 1288 Byte
Status WA
Exec Time 45 ms
Memory 28028 KB

Judge Result

Set Name small large
Score / Max Score 40 / 40 0 / 60
Status
AC × 15
AC × 16
WA × 11
Set Name Test Cases
small 00_small/small_00_sample1.txt, 00_small/small_00_sample2.txt, 00_small/small_00_sample3.txt, 00_small/small_00_sample4.txt, 00_small/small_01_rand_01.txt, 00_small/small_01_rand_02.txt, 00_small/small_01_rand_03.txt, 00_small/small_01_rand_05.txt, 00_small/small_01_rand_07.txt, 00_small/small_01_rand_08.txt, 00_small/small_01_rand_09.txt, 00_small/small_01_rand_10.txt, 00_small/small_01_rand_13.txt, 00_small/small_01_rand_14.txt, 00_small/small_01_rand_18.txt
large 00_small/small_00_sample1.txt, 00_small/small_00_sample2.txt, 00_small/small_00_sample3.txt, 00_small/small_00_sample4.txt, 00_small/small_01_rand_01.txt, 00_small/small_01_rand_02.txt, 00_small/small_01_rand_03.txt, 00_small/small_01_rand_05.txt, 00_small/small_01_rand_07.txt, 00_small/small_01_rand_08.txt, 00_small/small_01_rand_09.txt, 00_small/small_01_rand_10.txt, 00_small/small_01_rand_13.txt, 00_small/small_01_rand_14.txt, 00_small/small_01_rand_18.txt, 01_large/large_00_sample5.txt, 01_large/large_01_rand_01.txt, 01_large/large_01_rand_02.txt, 01_large/large_01_rand_03.txt, 01_large/large_01_rand_05.txt, 01_large/large_01_rand_07.txt, 01_large/large_01_rand_08.txt, 01_large/large_01_rand_09.txt, 01_large/large_01_rand_10.txt, 01_large/large_01_rand_13.txt, 01_large/large_01_rand_14.txt, 01_large/large_01_rand_18.txt
Case Name Status Exec Time Memory
00_small/small_00_sample1.txt AC 35 ms 26236 KB
00_small/small_00_sample2.txt AC 35 ms 27644 KB
00_small/small_00_sample3.txt AC 35 ms 26748 KB
00_small/small_00_sample4.txt AC 35 ms 27388 KB
00_small/small_01_rand_01.txt AC 37 ms 27644 KB
00_small/small_01_rand_02.txt AC 35 ms 27388 KB
00_small/small_01_rand_03.txt AC 35 ms 27004 KB
00_small/small_01_rand_05.txt AC 35 ms 26492 KB
00_small/small_01_rand_07.txt AC 36 ms 27260 KB
00_small/small_01_rand_08.txt AC 36 ms 26108 KB
00_small/small_01_rand_09.txt AC 35 ms 25980 KB
00_small/small_01_rand_10.txt AC 36 ms 26492 KB
00_small/small_01_rand_13.txt AC 36 ms 26748 KB
00_small/small_01_rand_14.txt AC 36 ms 27516 KB
00_small/small_01_rand_18.txt AC 36 ms 26492 KB
01_large/large_00_sample5.txt AC 35 ms 26620 KB
01_large/large_01_rand_01.txt WA 40 ms 27260 KB
01_large/large_01_rand_02.txt WA 42 ms 26108 KB
01_large/large_01_rand_03.txt WA 38 ms 27004 KB
01_large/large_01_rand_05.txt WA 44 ms 25724 KB
01_large/large_01_rand_07.txt WA 36 ms 28028 KB
01_large/large_01_rand_08.txt WA 36 ms 27516 KB
01_large/large_01_rand_09.txt WA 41 ms 27132 KB
01_large/large_01_rand_10.txt WA 37 ms 26620 KB
01_large/large_01_rand_13.txt WA 45 ms 27516 KB
01_large/large_01_rand_14.txt WA 40 ms 27388 KB
01_large/large_01_rand_18.txt WA 44 ms 27388 KB