답안 #851868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851868 2023-09-20T17:35:32 Z vjudge1 Magneti (COCI21_magneti) C++17
30 / 110
1000 ms 600 KB
//author:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

#define ONLINE_JUDGE

const int MOD = 1e9 + 7;
const int MAXN = 1e4 + 5;

int fak[MAXN];

int fp(int a, int b) {
    int res = 1;
    while(b) {
        if(b & 1) {
            res = (1LL * res * a) % MOD;
        }

        a = (1LL * a * a) % MOD;
        b >>= 1;
    }

    return res;
}

int divide(int a) {
    return fp(a, MOD -2);
}

int divide(int a, int b) {
    return (1LL * a * divide(b)) % MOD;
}

int comb(int n, int r) {
    if(n < r) 
        return 0;

    return divide(fak[n], (1LL * fak[r] * fak[n - r]) % MOD);
}

int cnts[MAXN];

void solve() {
    int n, l;
    cin >> n >> l;

    vector <int> vec(n);
    for(int &i : vec) 
        cin >> i;

    sort(vec.begin(), vec.end());
        
    int res = 0;
    do {
        int parca = l;
        for(int i = 0; i +1 < n; i++) {
            parca -= max(vec[i], vec[i +1]) -1;
        }

        res = (0LL + res + comb(parca, n)) % MOD;

    } while(next_permutation(vec.begin(), vec.end()));

    for(int &i : vec)
        cnts[i]++;

    for(int i = 1; i < MAXN; i++) {
        res = (1LL * res * fak[cnts[i]]) % MOD;
    }

    cout << res;
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif

    fak[0] = 1;
    for(int i = 1; i < MAXN; i++)
        fak[i] = (1LL * fak[i -1] * i) % MOD;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    while(t--)
        solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 591 ms 472 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 597 ms 596 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 19 ms 348 KB Output is correct
8 Correct 36 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1054 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 591 ms 472 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 597 ms 596 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 19 ms 348 KB Output is correct
18 Correct 36 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Execution timed out 1054 ms 344 KB Time limit exceeded
22 Halted 0 ms 0 KB -