# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
332502 |
2020-12-02T18:09:23 Z |
alien_lover |
Hacker (BOI15_hac) |
C++14 |
|
563 ms |
20460 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
const int PRIME = 1e9 + 7;
int n;
vector<int> prefSum;
// i1 inclusive, i2 exclusive
int getCumSum(int i1, int i2){
i1 %= n; i2 %= n;
if(i1 > i2){
return prefSum[n] - prefSum[i1] + prefSum[i2];
}
return prefSum[i2] - prefSum[i1];
// use prefix sum vector
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("hacker.in", "r", stdin);
// freopen("TASK_NAME.out", "w", stdout);
// Use scanf printf
cin >> n;
vector<int> scores(n);
prefSum.resize(n + 1);
prefSum[0] = 0;
int maxNumHacked = (n + 1) / 2;
for(int i = 0; i < n; i++){
cin >> scores[i];
prefSum[i+1] = prefSum[i] + scores[i];
}
if(n == 2){
cout << max(scores[0], scores[1]) << '\n';
return 0;
}
multiset<int> sums;
vector<int> minScores(n);
for(int i = 0; i < 2 * n; i++){
if(i >= maxNumHacked){
sums.erase(sums.find(getCumSum(i - maxNumHacked, i)));
// remove sum
}
sums.insert(getCumSum(i, i + maxNumHacked));
// cout << sums.size() << '\n';
minScores[i % n] = *sums.begin();
// compare
}
int ans = INT32_MIN;
for(int minScore: minScores){
ans = max(ans, minScore);
}
cout << ans << '\n';
// int maxScore = INT32_MIN;
// for(int i = 0; i < n; i++){
// // cout << i + 1 << ' ' << i + 1 + splitLen << ' ' << getCumSum(i + 1, i + 1 + splitLen) << '\n';
// // cout << i + (n+1)/2 << ' ' << i + (n+1)/2 + splitLen << ' ' << getCumSum(i + (n+1)/2, i + (n+1)/2 + splitLen) << '\n';
// // cout << '\n';
// maxScore = max(maxScore, min(getCumSum(i + 1, i + 1 + splitLen), getCumSum(i + (n+1)/2, i + (n+1)/2 + splitLen)) + scores[i]);
// }
// // for(int el: prefSum){
// // cout << el << ' ';
// // }
// cout << maxScore << '\n';
// int windowScore = 0;
// for(int i = 0; i < maxNumHacked; i++){
// windowScore += scores[i];
// }
// int minDiff = windowScore * 2 - totSum;
// int bestScore = windowScore;
// for(int i = 0; i < n; i++){
// // compare window starting at i
// // subtract element at i, add next element
// if(abs(windowScore * 2 - totSum) < minDiff && windowScore > totSum - windowScore){
// minDiff = windowScore * 2 - totSum;
// bestScore = windowScore;
// }
// // maxScore = min(minDiff, windowScore);
// windowScore -= scores[i];
// windowScore += scores[(i + maxNumHacked) % n];
// }
// cout << bestScore << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
396 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
3 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
3 ms |
492 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
3 ms |
492 KB |
Output is correct |
4 |
Correct |
61 ms |
3180 KB |
Output is correct |
5 |
Correct |
164 ms |
7404 KB |
Output is correct |
6 |
Correct |
217 ms |
9324 KB |
Output is correct |
7 |
Correct |
242 ms |
10860 KB |
Output is correct |
8 |
Correct |
557 ms |
18028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
396 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
492 KB |
Output is correct |
23 |
Correct |
3 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
3 ms |
492 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
3 ms |
492 KB |
Output is correct |
35 |
Correct |
61 ms |
3180 KB |
Output is correct |
36 |
Correct |
164 ms |
7404 KB |
Output is correct |
37 |
Correct |
217 ms |
9324 KB |
Output is correct |
38 |
Correct |
242 ms |
10860 KB |
Output is correct |
39 |
Correct |
557 ms |
18028 KB |
Output is correct |
40 |
Correct |
8 ms |
748 KB |
Output is correct |
41 |
Correct |
13 ms |
1132 KB |
Output is correct |
42 |
Correct |
19 ms |
1688 KB |
Output is correct |
43 |
Correct |
165 ms |
8312 KB |
Output is correct |
44 |
Correct |
500 ms |
20076 KB |
Output is correct |
45 |
Correct |
72 ms |
4332 KB |
Output is correct |
46 |
Correct |
269 ms |
12268 KB |
Output is correct |
47 |
Correct |
563 ms |
20212 KB |
Output is correct |
48 |
Correct |
328 ms |
20460 KB |
Output is correct |
49 |
Correct |
289 ms |
19564 KB |
Output is correct |
50 |
Correct |
286 ms |
19520 KB |
Output is correct |