#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
int n;
multiset<int> s;
void fix(int x) {
int c = s.count(x);
if (c == 1) {
if (s.count(x - 1)) {
s.erase(x - 1);
s.erase(x);
s.insert(x + 1);
fix(x + 1);
return;
}
if (s.count(x + 1)) {
s.erase(x + 1);
s.erase(x);
s.insert(x + 2);
fix(x + 2);
}
return;
}
// c == 2
if (x == 1) {
s.erase(x);
s.insert(x + 1);
fix(x + 1);
return;
}
if (s.count(x + 1)) {
s.erase(s.find(x));
s.erase(x + 1);
s.insert(x + 2);
fix(x + 2);
return;
}
if (s.count(x - 1)) {
s.erase(s.find(x));
s.erase(x - 1);
s.insert(x + 1);
fix(x + 1);
return;
}
if (x == 2) {
s.erase(x);
s.insert(x - 1);
s.insert(x + 1);
fix(x - 1);
fix(x + 1);
} else {
s.erase(x);
s.insert(x - 2);
s.insert(x + 1);
fix(x - 2);
fix(x + 1);
}
}
const int M = 1e9 + 7;
int b[N];
long long dp[N][2];
int main() {
cin.tie(0)->sync_with_stdio(0);
// freopen("in", "r", stdin);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
s.insert(a[i]);
fix(a[i]);
int m = 0;
for (int x : s) b[++m] = x;
// for (int i = 1; i <= m; ++i) {
// cerr << b[i] << " \n"[i == m];
// }
dp[1][0] = 1;
dp[1][1] = (b[1] - 1) / 2;
for (int i = 2; i <= m; ++i) {
int len = b[i] - b[i - 1];
if (len & 1) {
dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % M;
dp[i][1] = (dp[i - 1][0] + dp[i - 1][1]) * (len / 2) % M;
} else {
dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % M;
dp[i][1] = (dp[i - 1][0] * (len / 2 - 1) % M) +
(dp[i - 1][1] * (len / 2) % M) % M;
}
}
cout << (dp[m][0] + dp[m][1]) % M << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
4042 ms |
2516 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Execution timed out |
4042 ms |
2516 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |