超暴力BFS,我感觉不能过的T_
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
map<int, bool> mp;
int res;
typedef pair<int, int> PII;
#define x first
#define y second
void bfs(int s){
queue<PII> q;
q.push({s, 1});
for(auto &[k , v] :mp)
v = false;
mp[s] = true;
int cnt = 1, ans = 1;
while(q.size()){
auto a = q.front();
q.pop();
for(int i = a.x;i <= a.x + a.y;i ++)
if(mp.count(i) && !mp[i]) q.push({i, a.y + 1}), ans ++, mp[i] = true;
for(int i = a.x;i >= a.x - a.y;i --)
if(mp.count(i) && !mp[i]) q.push({i, a.y + 1}), ans ++, mp[i] = true;
}
res = max(res, ans);
}
int main(){
int n;
cin >> n;
while(n --){
int t;
cin >> t;
mp[t] = true;
}
for(auto [k , v]: mp){
bfs(k);
}
cout << res;
}