답안 #892359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892359 2023-12-25T09:10:47 Z tradz Magneti (COCI21_magneti) C++14
10 / 110
1000 ms 4596 KB
#include <bits/stdc++.h>

#define For(i,a,b) for(int i = a; i <= b; i++)
#define Ford(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define RRH(v) v.resize(unique(all(v)) - v.begin())

using namespace std;
const int  N = 1e6+7;
const int M = 1e9+7;
const ll oo = 3e18;

ll gt[N], igt[N];
int n, l;

ll poww(ll a, ll b) {
    if(b == 0) return 1;
    ll t = poww(a, b / 2);
    t = t * t % M;
    if(b & 1) t = t * a % M;
    return t;
}

ll ncr(ll nn, ll rr) {
    if (rr > nn || rr < 0) return 0;
    return ((gt[nn] * igt[rr]) % M * igt[nn - rr]) % M;
}

ii a[N];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    #define TASK ""
    if (fopen (".inp", "r")) {
        freopen (".inp", "r", stdin);
        freopen (".out", "w", stdout);
    }
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    cin >> n >> l;

    For(i, 1, n) cin >> a[i].fi, a[i].se = i;
    gt[0] = gt[1] = 1;
    For(i, 2, l) gt[i] = (i * gt[i - 1]) % M;
    igt[l] = poww(gt[l], M - 2);

    Ford(i, l - 1, 0) igt[i] = (igt[i + 1] * (i + 1)) % M;

    sort(a + 1, a + n + 1);

    ll ans = 0;
    if (a[1].fi == a[n].fi) {
        int tmp = l - (1 + a[1].fi * (n - 1));
        cout << (ncr(n + tmp, tmp) * gt[n]) % M << "\n";
        return 0;
    }

    while((next_permutation(a + 1, a + n + 1))) {
        int tmp = l - n;
        For(i, 2, n) tmp -= max(a[i - 1].fi - 1, a[i].fi - 1);
        ans = (ans + ncr(n + tmp, tmp)) % M;
    }
    cout << ans << "\n";

    return 0;
}



Compilation message

Main.cpp: In function 'int main()':
Main.cpp:40:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen (".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:41:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen (".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4564 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 4596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 4444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4564 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Incorrect 63 ms 4596 KB Output isn't correct
12 Halted 0 ms 0 KB -