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;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define endl "\n"
#define out(x) "[" << #x << "=" << x << "]"
struct debug {
debug() { cerr << "DEBUGGER: " << endl; }
~debug() { cerr << endl << "DEBUGGER_END " << endl; }
template<class T>
debug& operator <<(const T x) {
cerr << x << " ";
return *this;
}
};
template<class T> inline ostream &operator <<(ostream &out, const vector<T> &x) {
for(const auto &it : x) {
out << it << " ";
}
return out;
}
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) {
return out << x.first << " " << x.second;
}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
typedef long long ll;
const ll mod = 1e9 + 7;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
const int MAX_N = 5e5 + 10;
int n;
pair<int, int> p[MAX_N];
bool used[MAX_N];
enum DIR {
RIGHT,
DOWN,
LEFT,
UP
};
void dfs(int x, DIR dir) {
used[x] = true;
if(dir == DIR::RIGHT) {
for(int i = 0; i < n; i ++) {
if(used[i]) {continue;}
if(p[x].first > p[i].first) {continue;}
if(p[x].second == p[i].second) {
dfs(i, DIR::LEFT);
continue;
}
if(p[x].first - p[x].second == p[i].first - p[i].second) {
dfs(i, DIR::DOWN);
continue;
}
if(p[x].first + p[x].second == p[i].first + p[i].second) {
dfs(i, DIR::UP);
continue;
}
}
} else if(dir == DIR::DOWN) {
for(int i = 0; i < n; i ++) {
if(used[i]) {continue;}
if(p[x].second < p[i].second) {continue;}
if(p[x].first == p[i].first) {
dfs(i, DIR::UP);
continue;
}
if(p[x].first - p[x].second == p[i].first - p[i].second) {
dfs(i, DIR::RIGHT);
continue;
}
if(p[x].first + p[x].second == p[i].first + p[i].second) {
dfs(i, DIR::LEFT);
continue;
}
}
} else if(dir == DIR::LEFT) {
for(int i = 0; i < n; i ++) {
if(used[i]) {continue;}
if(p[x].first < p[i].first) {continue;}
if(p[x].second == p[i].second) {
dfs(i, DIR::RIGHT);
continue;
}
if(p[x].first - p[x].second == p[i].first - p[i].second) {
dfs(i, DIR::UP);
continue;
}
if(p[x].first + p[x].second == p[i].first + p[i].second) {
dfs(i, DIR::DOWN);
continue;
}
}
} else {
for(int i = 0; i < n; i ++) {
if(used[i]) {continue;}
if(p[x].second > p[i].second) {continue;}
if(p[x].first == p[i].first) {
dfs(i, DIR::DOWN);
continue;
}
if(p[x].first - p[x].second == p[i].first - p[i].second) {
dfs(i, DIR::LEFT);
continue;
}
if(p[x].first + p[x].second == p[i].first + p[i].second) {
dfs(i, DIR::RIGHT);
continue;
}
}
}
}
signed main() {
#ifndef LOCAL
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#endif
cin >> n;
for(int i = 0; i < n; i ++) {
cin >> p[i].first >> p[i].second;
}
int ret = 0;
int now = 0;
now = 0;
dfs(0, DIR::DOWN);
for(int i = 0; i < n; i ++) {
if(used[i]) {
now ++;
used[i] = false;
}
}
chkmax(ret, now);
now = 0;
dfs(0, DIR::UP);
for(int i = 0; i < n; i ++) {
if(used[i]) {
now ++;
used[i] = false;
}
}
chkmax(ret, now);
now = 0;
dfs(0, DIR::LEFT);
for(int i = 0; i < n; i ++) {
if(used[i]) {
now ++;
used[i] = false;
}
}
chkmax(ret, now);
now = 0;
dfs(0, DIR::RIGHT);
for(int i = 0; i < n; i ++) {
if(used[i]) {
now ++;
used[i] = false;
}
}
chkmax(ret, now);
cout << ret << endl;
return 0;
}
# | 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... |