답안 #200983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200983 2020-02-09T02:37:44 Z model_code Zapina (COCI20_zapina) C++17
55 / 110
70 ms 892 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long ll;

const int MOD = 1e9 + 7;
int add(int a, int b) { return (a + b) % MOD; }
int mul(int a, int b) { return (ll)a * b % MOD; }
int pow(int a, int b) {
    int r = 1;
    for (; b; b >>= 1) {
        if (b & 1) r = mul(r, a);
        a = mul(a, a);
    }
    return r;
}
  
const int MAXN = 510;
int n, choose[MAXN][MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;

    choose[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        choose[i][0] = 1;
        for (int j = 1; j <= n; j++)
            choose[i][j] = add(choose[i - 1][j], choose[i - 1][j - 1]);
    }

    int sol = 0;
    for (int mask = 1; mask < (1 << n); mask++) {
        int sum = 0, k = __builtin_popcount(mask);
        for (int i = 0; i < n; i++) if ((1 << i) & mask) sum += i + 1;
        if (sum > n) continue;
        int tmp = 1, tot = n;
        for (int i = 0; i < n; i++)
            if ((1 << i) & mask) {
                tmp = mul(tmp, choose[tot][i + 1]);
                tot -= i + 1;
            }
        tmp = mul(tmp, pow(n - k, tot));
        if (!(k & 1)) tmp = MOD - tmp;
        sol = add(sol, tmp);
    }

    cout << sol << "\n";

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 6 ms 372 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 6 ms 372 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 7 ms 376 KB Output is correct
14 Correct 10 ms 376 KB Output is correct
15 Correct 16 ms 376 KB Output is correct
16 Correct 29 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 6 ms 372 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 7 ms 376 KB Output is correct
14 Correct 10 ms 376 KB Output is correct
15 Correct 16 ms 376 KB Output is correct
16 Correct 29 ms 376 KB Output is correct
17 Incorrect 70 ms 892 KB Output isn't correct
18 Halted 0 ms 0 KB -