| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 1102329 | MinhKien | Zapina (COCI20_zapina) | C++17 | 225 ms | 2408 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
#define AT "CHIAKEO"
#define ll long long
const ll MOD = 1e9 + 7;
const int N = 360;
int n;
ll gt[N], inv[N];
ll binpow(ll x, ll p) {
    ll res = 1;
    while (p > 0) {
        if (p & 1) {
            res = (res * x) % MOD;
        }
        p >>= 1;
        x = (x * x) % MOD;
    }
    return res;
}
ll nCk(ll x, ll k) {
    ll res = gt[x] * inv[x - k] % MOD * inv[k] % MOD;
    return res;
}
namespace subtask2 {
    void main() {
        ll RealAns = 0;
        for (int i = 1; i < (1 << n); ++i) {
            ll way = 1;
            ll sum = n;
            bool ck = true;
            for (int j = 0; (1 << j) <= i; ++j) {
                if (i >> j & 1) {
                    if (sum < (ll)(j + 1)) {
                        ck = false;
                        break;
                    }
                    way = (way * nCk(sum, j + 1)) % MOD;
                    sum -= (ll)(j + 1);
                }
            }
            int bit = __builtin_popcount(i);
            ll k = n - bit;
            way = (way * binpow(k, sum)) % MOD;
            if (ck) {
                if (bit % 2) {
                    RealAns = (RealAns + way) % MOD;
                } else {
                    RealAns = (RealAns - way + MOD * MOD) % MOD;
                }
            }
        }
        cout << RealAns;
    }
};
ll dp[N][N][2];
int main() {
    if (fopen(AT".inp", "r")) {
        freopen(AT".INP", "r", stdin);
        freopen(AT".OUT", "w", stdout);
    }
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cin >> n;
    gt[0] = 1;
    inv[0] = 1;
    for (int i = 1; i <= n; ++i) {
        gt[i] = (gt[i - 1] * (ll)i) % MOD;
        inv[i] = binpow(gt[i], MOD - 2);
    }
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k <= j; ++k) {
                if (i == k) {
                    dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j - k][1] * nCk(j, k) % MOD + dp[i - 1][j - k][0] * nCk(j, k) % MOD) % MOD;
                } else {
                    dp[i][j][0] = (dp[i - 1][j - k][0] * nCk(j, k) % MOD + dp[i][j][0]) % MOD;
                    dp[i][j][1] = (dp[i - 1][j - k][1] * nCk(j, k) % MOD + dp[i][j][1]) % MOD;
                }
            }
        }
    }
    cout << dp[n][n][1] << endl;
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
