提出 #68064248


ソースコード 拡げる

#include <bits/stdc++.h>

using std::cin;
using std::cout;

constexpr int N = 4005;
constexpr int MOD = 924844033;
int n, k, dp[N][N], cnt = 0;
bool marked[N];
long long fact[N], ans = 0;

void Mark(const int val) {
    cnt += val;
    marked[cnt] = false;
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> k;

    fact[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = fact[i - 1] * i % MOD;
    }

    memset(marked, true, sizeof(marked));
    marked[0] = false;
    for (int i = 1; i <= (n - k) % k; i++) {
        Mark(ceil(static_cast<double>(n - k) / k));
        Mark(ceil(static_cast<double>(n - k) / k));
    }

    for (int i = 1; i <= k - (n - k) % k; i++) {
        Mark((n - k) / k);
        Mark((n - k) / k);
    }

    dp[0][0] = 1;
    for (int i = 1; i <= cnt; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = dp[i - 1][j] % MOD;
            if (j > 0) {
                dp[i][j] = (dp[i][j] + dp[i - 1 - marked[i - 1]][j - 1]) % MOD;
            }
        }
    }

    for (int i = 0; i <= n; i++) {
        if (i & 1) {
            ans = ((ans - dp[cnt][i] * fact[n - i] % MOD) % MOD + MOD) % MOD;
        } else {
            ans = (ans + dp[cnt][i] * fact[n - i] % MOD) % MOD;
        }
    }

    cout << ans << "\n";

    return 0;
}

提出情報

提出日時
問題 D - ~K Perm Counting
ユーザ Peter_0327
言語 C++ 20 (gcc 12.2)
得点 900
コード長 1415 Byte
結果 AC
実行時間 36 ms
メモリ 50680 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 900 / 900
結果
AC × 5
AC × 28
セット名 テストケース
Sample example0, example1, example2, example3, example4
All example0, example1, example2, example3, example4, handmade0, handmade1, handmade2, handmade3, handmade4, handmade5, handmade6, maxrand0, maxrand1, maxrand2, maxrand3, maxrand4, rand0, rand1, rand2, rand3, rand4, small0, small1, small2, supersmall0, supersmall1, supersmall2
ケース名 結果 実行時間 メモリ
example0 AC 1 ms 3528 KiB
example1 AC 1 ms 3600 KiB
example2 AC 1 ms 3416 KiB
example3 AC 1 ms 3476 KiB
example4 AC 3 ms 7776 KiB
handmade0 AC 1 ms 3528 KiB
handmade1 AC 36 ms 50680 KiB
handmade2 AC 1 ms 3408 KiB
handmade3 AC 32 ms 46192 KiB
handmade4 AC 1 ms 3372 KiB
handmade5 AC 35 ms 49440 KiB
handmade6 AC 35 ms 49556 KiB
maxrand0 AC 8 ms 12384 KiB
maxrand1 AC 19 ms 28180 KiB
maxrand2 AC 21 ms 30756 KiB
maxrand3 AC 33 ms 46476 KiB
maxrand4 AC 2 ms 4776 KiB
rand0 AC 28 ms 38924 KiB
rand1 AC 3 ms 6680 KiB
rand2 AC 1 ms 4040 KiB
rand3 AC 1 ms 3784 KiB
rand4 AC 7 ms 11916 KiB
small0 AC 2 ms 5524 KiB
small1 AC 1 ms 4388 KiB
small2 AC 1 ms 3784 KiB
supersmall0 AC 1 ms 3464 KiB
supersmall1 AC 1 ms 3340 KiB
supersmall2 AC 1 ms 3348 KiB