#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
map<int, int> mp;
void getValues(int x){
if(mp[x] != 0){
if(mp[x] == 1){
if(x >= 1 && mp[x - 1] != 0){
mp[x - 1]--;
mp[x]--;
mp[x + 1]++;
getValues(x + 1);
}
else if(mp[x + 1] != 0) {
mp[x]--;
mp[x + 1]--;
mp[x + 2]++;
getValues(x + 2);
}
}
else{
mp[x] = 0;
mp[x + 1]++;
getValues(x + 1);
if(x > 1){
mp[x - 2]++;
getValues(x - 2);
}
else if(x == 1){
mp[0]++;
getValues(0);
}
}
}
}
int main(){
int n;
cin >> n;
for(int i = 0; i < n; i++){
int x;
cin >> x;
x--;
mp[x]++;
getValues(x);
vector<long long> a;
for(auto it : mp){
if(it.second != 0){
a.push_back(it.first);
}
}
vector<long long> dp((int)a.size());
dp[0] = a[0]/2;
int ans = 1;
for(int j = 1; j < (int)a.size(); j++){
dp[j] = ((a[j] - a[j - 1])/2LL * dp[j - 1] + (a[j] - a[j - 1] - 1)/2LL * ans) % MOD;
ans += dp[j - 1];
ans %= MOD;
}
cout << ans + dp.back() << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |