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"
using namespace std;
#define ar array
#define int long long
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
vector<ar<int, 2>> p(n);
for(int i=0;i<n;i++) cin>>p[i][0]>>p[i][1];
map<int, deque<int>> m1, m2, x, y;
for(int i=0;i<n;i++){
m1[p[i][0] + p[i][1]].push_back(i);
m2[p[i][0] - p[i][1]].push_back(i);
}
for(auto& [x, v] : m1){
sort(v.begin(), v.end(), [&](int i, int j) { return (p[i][0] < p[j][0]); });
//~ for(int i=0;i<(int)v.size();i++) p1[v[i]] = i;
}
for(auto& [x, v] : m2){
sort(v.begin(), v.end(), [&](int i, int j) { return (p[i][0] < p[j][0]); });
//~ for(int i=0;i<(int)v.size();i++) p2[v[i]] = i;
}
int ans = 0;
for(int t=0;t<4;t++){
auto t1 = m1, t2 = m2;
vector<int> T(n, 2e9); T[0] = 0;
priority_queue<ar<int, 3>, vector<ar<int, 3>>, greater<ar<int, 3>>> qq; qq.push({0, t, 0});
int res = 0;
while(!qq.empty()){
auto u = qq.top(); qq.pop();
int i = u[2], t = u[1];
if(u[0] > T[i]) continue;
res++;
{
auto& v = m1[p[i][0] + p[i][1]];
while(!v.empty()){
if(t == 0){
int x = v.front();
if(p[i][0] - p[x][0] < T[i]) break;
v.pop_front();
if(T[x] > abs(p[i][0] - p[x][0])){
T[x] = abs(p[i][0] - p[x][0]);
qq.push({T[x], 1, x});
}
} if(t == 1){
int x = v.back();
if(p[x][0] - p[i][0] < T[i]) break;
v.pop_back();
if(T[x] > abs(p[i][0] - p[x][0])){
T[x] = abs(p[i][0] - p[x][0]);
qq.push({T[x], 0, x});
}
} if(t == 2){
int x = v.back();
if(p[x][0] - p[i][0] < T[i]) break;
v.pop_back();
if(T[x] > abs(p[i][0] - p[x][0])){
T[x] = abs(p[i][0] - p[x][0]);
qq.push({T[x], 3, x});
}
} if(t == 3){
int x = v.front();
if(p[i][0] - p[x][0] < T[i]) break;
v.pop_front();
if(T[x] > abs(p[i][0] - p[x][0])){
T[x] = abs(p[i][0] - p[x][0]);
qq.push({T[x], 2, x});
}
}
}
}
{
auto& v = m2[p[i][0] - p[i][1]];
while(!v.empty()){
if(t == 0){
int x = v.back();
if(p[x][0] - p[i][0] < T[i]) break;
v.pop_back();
if(T[x] > abs(p[i][0] - p[x][0])){
T[x] = abs(p[i][0] - p[x][0]);
qq.push({T[x], 3, x});
}
} if(t == 1){
int x = v.back();
if(p[x][0] - p[i][0] < T[i]) break;
v.pop_back();
if(T[x] > abs(p[i][0] - p[x][0])){
T[x] = abs(p[i][0] - p[x][0]);
qq.push({T[x], 2, x});
}
} if(t == 2){
int x = v.front();
if(p[i][0] - p[x][0] < T[i]) break;
v.pop_front();
if(T[x] > abs(p[i][0] - p[x][0])){
T[x] = abs(p[i][0] - p[x][0]);
qq.push({T[x], 1, x});
}
} if(t == 3){
int x = v.front();
if(p[i][0] - p[x][0] < T[i]) break;
v.pop_front();
if(T[x] > abs(p[i][0] - p[x][0])){
T[x] = abs(p[i][0] - p[x][0]);
qq.push({T[x], 0, x});
}
}
}
}
}
ans = max(ans, res);
m1 = t1, m2 = t2;
}
cout<<ans<<"\n";
}
Compilation message (stderr)
fever.cpp: In function 'int main()':
fever.cpp:19:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
19 | for(auto& [x, v] : m1){
| ^
fever.cpp:24:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
24 | for(auto& [x, v] : m2){
| ^
# | 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... |