Submission #2693993
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll M = 1e9 + 7; const int N = 100100; ll binpow(ll a, ll p) { ll s = 1; while (p) { if (p & 1) { s = s * a % M; } a = a * a % M; p >>= 1; } return s; } ll f[N], finv[N]; int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> a(n + 1); for (int i = 0; i <= n; ++i) { cin >> a[i]; } f[0] = finv[0] = 1; for (int i = 1; i <= n + 1; ++i) { f[i] = f[i - 1] * i % M; finv[i] = binpow(f[i], M - 2); } vector<ll> ans(n + 1); for (int i = 0; i <= n; ++i) { ans[i] = f[n + 1] * finv[i + 1] % M * finv[n - i] % M; } vector<int> pos[N]; for (int i = 0; i <= n; ++i) { pos[a[i]].push_back(i); } int l, r; for (int i = 1; i <= n; ++i) { if (pos[i].size() == 2) { l = min(pos[i][0], pos[i][1]); r = max(pos[i][0], pos[i][1]); } } int x = l + n - r; for (int i = 0; i <= n; ++i) { if (x >= i) { ans[i] -= f[x] * finv[i] % M * finv[x - i] % M; } ans[i] = (ans[i] + M) % M; } for (int i = 0; i <= n; ++i) { cout << ans[i] << '\n'; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 11 |
User | meatrow |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 1483 Byte |
Status | AC |
Exec Time | 43 ms |
Memory | 9472 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 600 / 600 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | 1.txt, mx.txt, rnd_0.txt, rnd_1.txt, rnd_2.txt, rnd_3.txt, rnd_4.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
1.txt | AC | 43 ms | 9472 KB |
mx.txt | AC | 42 ms | 9472 KB |
rnd_0.txt | AC | 35 ms | 8192 KB |
rnd_1.txt | AC | 30 ms | 7424 KB |
rnd_2.txt | AC | 10 ms | 3968 KB |
rnd_3.txt | AC | 9 ms | 3712 KB |
rnd_4.txt | AC | 15 ms | 4608 KB |
sample1.txt | AC | 2 ms | 2560 KB |
sample2.txt | AC | 2 ms | 2560 KB |
sample3.txt | AC | 2 ms | 2560 KB |