#include <bits/stdc++.h>
using namespace std;
const int maxn = 2*500010;
int v[maxn], pref[maxn], n;
typedef pair<int, int> pii;
vector<int> c[maxn];
vector<pii> p;
vector<int> ord[maxn];
inline int qq(int a, int b){
return pref[b] - pref[a-1];
}
void ordena(){
for(auto v : p)
ord[v.first].push_back(v.second);
p.clear();
for(int i=1;i<=2*n+100;i++){
if(ord[i].empty()) continue;
for(auto v : ord[i])
p.push_back({i, v});
}
}
int main(){
ios::sync_with_stdio(false), cin.tie(0);
cin >> n;
for(int i=1;i<=n;i++){
cin >> v[i<<1];
v[i<<1] *= 2;
int centro = (v[(i<<1)] + (i<<1))/2;
p.push_back({abs(centro - (i<<1)), centro});
}
ordena();
for(int i=1;i<=n;i++)
c[p[i].second].push_back(p[i].first);
for(int i=1;i<=n;i++)
if(v[i<<1] == (i<<1)) pref[i<<1] = 1;
for(int i=1;i<=2*n;i++)
pref[i] += pref[i-1];
int ans=0, a, b;
for(int i=1;i<=2*n;i++){
//sort(c[i].begin(), c[i].end());
for(int j=0;j<c[i].size();j++){
int qtd = j + 1 - qq(i-c[i][j], i+c[i][j]) + (!(i&1) && v[i] == i);
if(qtd > ans){
ans = qtd;
a = i-c[i][j];
b = i+c[i][j];
}
}
}
cout << v[a]/2 << " " << v[b]/2 << "\n";
return 0;
}
Compilation message
doktor.cpp: In function 'int main()':
doktor.cpp:52:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<c[i].size();j++){
~^~~~~~~~~~~~
doktor.cpp:63:30: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
cout << v[a]/2 << " " << v[b]/2 << "\n";
~~~^
doktor.cpp:63:13: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
cout << v[a]/2 << " " << v[b]/2 << "\n";
~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
47352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
47484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
47484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
47600 KB |
Output is correct |
2 |
Correct |
46 ms |
47600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
47872 KB |
Output is correct |
2 |
Correct |
46 ms |
47872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
47872 KB |
Output is correct |
2 |
Correct |
44 ms |
47872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
48220 KB |
Output is correct |
2 |
Correct |
114 ms |
62516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
62516 KB |
Output is correct |
2 |
Correct |
67 ms |
62516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
357 ms |
79148 KB |
Output is correct |
2 |
Runtime error |
219 ms |
126408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
211 ms |
129184 KB |
Output is correct |
2 |
Runtime error |
170 ms |
132096 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |