#include<bits/stdc++.h>
using namespace std;
int N;
int MOD = 1e9 + 7;
vector<int> tastes;
int main(){
cin >> N;
tastes = vector<int>(N);
unordered_map<int, int> frequency;
frequency.reserve(N);
for(int i = 0; i < N; ++i) {
cin >> tastes[i];
frequency[tastes[i]] = 0;
}
long long int ans = 0;
int previousWinner = -1;
for(int i = 0; i < N; ++i){
previousWinner = tastes[i];
ans++;
frequency[tastes[i]]++;
for(int j = i+1; j < N; ++j){
frequency[tastes[j]]++;
if(frequency[tastes[j]] > frequency[previousWinner])previousWinner = tastes[j];
int dist = j - i +1;
if(2*frequency[previousWinner] > dist) ans++;
}
for(int i = 0; i < N; ++i) frequency[tastes[i]] = 0;
ans = ans%MOD;
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
4 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
4 ms |
212 KB |
Output is correct |
7 |
Correct |
41 ms |
252 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
133 ms |
320 KB |
Output is correct |
10 |
Correct |
133 ms |
332 KB |
Output is correct |
11 |
Correct |
130 ms |
212 KB |
Output is correct |
12 |
Correct |
129 ms |
316 KB |
Output is correct |
13 |
Correct |
137 ms |
384 KB |
Output is correct |
14 |
Correct |
131 ms |
316 KB |
Output is correct |
15 |
Correct |
132 ms |
212 KB |
Output is correct |
16 |
Correct |
132 ms |
316 KB |
Output is correct |
17 |
Correct |
129 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3071 ms |
1968 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
4 ms |
212 KB |
Output is correct |
7 |
Correct |
41 ms |
252 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
133 ms |
320 KB |
Output is correct |
10 |
Correct |
133 ms |
332 KB |
Output is correct |
11 |
Correct |
130 ms |
212 KB |
Output is correct |
12 |
Correct |
129 ms |
316 KB |
Output is correct |
13 |
Correct |
137 ms |
384 KB |
Output is correct |
14 |
Correct |
131 ms |
316 KB |
Output is correct |
15 |
Correct |
132 ms |
212 KB |
Output is correct |
16 |
Correct |
132 ms |
316 KB |
Output is correct |
17 |
Correct |
129 ms |
320 KB |
Output is correct |
18 |
Execution timed out |
3071 ms |
1968 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |