# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
738942 |
2023-05-09T16:50:41 Z |
rainboy |
W (RMI18_w) |
C |
|
181 ms |
6980 KB |
#include <stdio.h>
#include <string.h>
#define N 300000
#define MD 1000000007
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
void sort(int *aa, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp;
while (j < k)
if (aa[j] == a)
j++;
else if (aa[j] < a) {
tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
i++, j++;
} else {
k--;
tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
}
sort(aa, l, i);
l = k;
}
}
int vv[N + 5], ff[N + 5], gg[N + 5];
void init() {
int i;
ff[0] = gg[0] = 1;
for (i = 1; i <= N + 4; i++) {
vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
ff[i] = (long long) ff[i - 1] * i % MD;
gg[i] = (long long) gg[i - 1] * vv[i] % MD;
}
}
int choose(int n, int k) {
return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}
int dist(int n, int k) {
return n < 0 ? 0 : (k == 0 ? (n == 0 ? 1 : 0) : choose(n + k - 1, k - 1));
}
int main() {
static int aa[N], dp[3][2][2], dq[3][2][2];
int n, i, j, k, s, s_, l, l1, l_, r, r1, r_;
init();
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
sort(aa, 0, n);
for (i = 0; i < n; i = j) {
j = i + 1;
while (j < n && aa[j] == aa[i])
j++;
k = j - i;
memset(dq, 0, sizeof dq);
if (i == 0)
dq[0][0][0] = 2, dq[1][0][0] = k - 1;
else
for (s = 0; s < 3; s++)
for (l = 0; l < 2; l++)
for (r = 0; r < 2; r++) {
int x = dp[s][l][r];
if (x == 0)
continue;
if (s == 0) {
s_ = 0;
for (l1 = 0; l1 < 2; l1++) {
l_ = l | l1, r_ = r;
dq[s_][l_][r_] = (dq[s_][l_][r_] + (long long) x * dist(k - (l1 == 0 ? 0 : 1), l1 == 0 ? 1 : 2)) % MD;
}
s_ = 1;
for (l1 = 0; l1 < 2; l1++) {
l_ = l | l1, r_ = r;
dq[s_][l_][r_] = (dq[s_][l_][r_] + (long long) x * dist(k - 1 - (l1 == 0 ? 0 : 1), l1 == 0 ? 2 : 3)) % MD;
}
} else if (s == 1) {
s_ = 1;
for (l1 = 0; l1 < 2; l1++)
for (r1 = 0; r1 < 2; r1++) {
l_ = l | l1, r_ = r | r1;
dq[s_][l_][r_] = (dq[s_][l_][r_] + (long long) x * dist(k - (l1 == 0 ? 0 : 1) - (r1 == 0 ? 0 : 1), (l1 == 0 ? 0 : 1) + (r1 == 0 ? 0 : 1) + 2)) % MD;
}
s_ = 2;
for (l1 = 0; l1 < 2; l1++)
for (r1 = 0; r1 < 2; r1++) {
l_ = l | l1, r_ = r | r1;
dq[s_][l_][r_] = (dq[s_][l_][r_] + (long long) x * dist(k - 1 - (l1 == 0 ? 0 : 1) - (r1 == 0 ? 0 : 1), (l1 == 0 ? 0 : 1) + (r1 == 0 ? 0 : 1) + 1)) % MD;
}
} else {
s_ = 2;
for (l1 = 0; l1 < 2; l1++)
for (r1 = 0; r1 < 2; r1++) {
l_ = l | l1, r_ = r | r1;
dq[s_][l_][r_] = (dq[s_][l_][r_] + (long long) x * dist(k - (l1 == 0 ? 0 : 1) - (r1 == 0 ? 0 : 1), (l1 == 0 ? 0 : 1) + (r1 == 0 ? 0 : 1))) % MD;
}
}
}
memcpy(dp, dq, sizeof dq);
}
printf("%d\n", dp[2][1][1]);
return 0;
}
Compilation message
w.c: In function 'main':
w.c:58:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
w.c:60:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3812 KB |
Output is correct |
2 |
Correct |
5 ms |
3816 KB |
Output is correct |
3 |
Correct |
14 ms |
4308 KB |
Output is correct |
4 |
Correct |
33 ms |
5836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3796 KB |
Output is correct |
2 |
Correct |
5 ms |
3796 KB |
Output is correct |
3 |
Correct |
22 ms |
4048 KB |
Output is correct |
4 |
Correct |
66 ms |
4936 KB |
Output is correct |
5 |
Correct |
119 ms |
5940 KB |
Output is correct |
6 |
Correct |
181 ms |
6980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3796 KB |
Output is correct |
2 |
Correct |
5 ms |
3808 KB |
Output is correct |
3 |
Correct |
5 ms |
3796 KB |
Output is correct |
4 |
Correct |
5 ms |
3796 KB |
Output is correct |
5 |
Correct |
9 ms |
3784 KB |
Output is correct |
6 |
Correct |
7 ms |
3828 KB |
Output is correct |
7 |
Correct |
10 ms |
3828 KB |
Output is correct |
8 |
Correct |
20 ms |
4796 KB |
Output is correct |
9 |
Correct |
47 ms |
5496 KB |
Output is correct |
10 |
Correct |
180 ms |
6976 KB |
Output is correct |