# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
82193 | wjoao | Doktor (COCI17_doktor) | C++11 | 273 ms | 49200 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define maxn 500100
using namespace std;
int n;
vector<int> v[2*maxn];
int entrada[2*maxn], prefix[2*maxn];
int query(int a, int b){
return prefix[b]-prefix[a-1];
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++){
scanf(" %d", &entrada[i*2]);
entrada[i*2] = entrada[i*2]*2;
}
//for(int i = 1; i <= 2*n; i++){
// cout << i << " - " << entrada[i] << endl;
// }
for(int i = 1; i <= n; i++){
if(i*2 == entrada[i*2]) {
prefix[i*2] = 1;
continue;
}
int middle = ( entrada[i*2] + i*2 ) / 2;
// cout << "Novo middle: " << middle << " Valor: " << entrada[i*2] << endl;
v[middle].push_back(abs(middle-i*2));
}
//cout << "X" << endl;
for(int i = 1; i < 2*maxn; i++) prefix[i] += prefix[i-1];
//for(int i = 1; i <= 2*n; i++){
// cout << i << " prefix - " << prefix[i] << endl;
//}
int res = 0;
int A = 2;
int B = 2;
for(int i = 2; i < 2*maxn; i++){
sort(v[i].begin(), v[i].end());
for(int j = 0; j < v[i].size(); j++){
int valor = v[i][j];
int atual =
j
- query(i-valor, i+valor)
+ ( (i%2 == 0 && i == entrada[i] ) ? 1 : 0 );
if(atual > res){
res = atual;
A = i-valor;
B = i+valor;
}
}
}
printf("%d %d\n", entrada[A]/2, entrada[B]/2);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |