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>
#include <ext/pb_ds/assoc_container.hpp>
#define fi first
#define se second
#define ll long long
using namespace std ;
using namespace __gnu_pbds;
const int N = 5e5 ;
bool flag1, us[N + 1] ;
int n, ans ;
pair<int, int> p[N + 1] ;
signed main()
{
ios_base::sync_with_stdio( 0 ) ;
cin.tie( 0 ) ;
cout.tie( 0 ) ;
cin >> n ;
for(int i = 1 ; i <= n ; i++)
{
cin >> p[i].fi >> p[i].se ;
if(p[i].se != p[1].se)
flag1 = 1 ;
}
if(!flag1)
{
ans = 1 ;
sort(p + 1, p + n + 1) ;
for(int i = 1 ; i < n ; i++)
ans += (p[i].fi != p[i + 1].fi) ;
cout << ans ;
return 0 ;
}
if(n <= 1000)
{
set<pair<int, int>> abu ;
set<int> s[n + 1] ;
for(int i = 1 ; i <= n ; i++)
{
for(int q = 1 ; q <= n ; q++)
if(abs(p[i].fi - p[q].fi) <= p[i].se - p[q].se)
s[i].insert(q) ;
abu.insert({s[i].size(), i}) ;
}
while(abu.size())
{
pair<int, int> p = *abu.rbegin() ;
abu.erase(p) ;
// cout << p.fi << ' ' << p.se << '\n' ;
// for(int i = 1 ; i <= n ; i++)
// cout<<s[i].size() << ' ' ;
// cout << '\n' ;
for(int i = 1 ; i <= n ; i++)
{
if(i == p.se)
continue ;
if(s[i].size())
abu.erase({s[i].size(), i}) ;
for(int j : s[p.se])
if(s[i].count(j))
s[i].erase(j) ;
if(s[i].size())
abu.insert({s[i].size(), i}) ;
}
s[p.se].clear() ;
ans++ ;
}
cout << ans ;
return 0 ;
}
// if(n <= 16)
// {
// ans = 1e9 ;
// for(int i = 0 ; i < (1 << n) ; i++)
// {
// int now = 0, cnt = 0 ;
// bool us[n + 1] = {} ;
// for(int j = 0 ; j < n ; j++)
// if((1 << j) & i)
// {
// us[j + 1] = 1 ;
// now++ ;
// for(int q = 1 ; q <= j ; q++)
// if(abs(p[q].fi - p[j + 1].fi) <= p[j + 1].se - p[q].se)
// us[q] = 1 ;
// for(int q = j + 2 ; q <= n ; q++)
// if(abs(p[q].fi - p[j + 1].fi) <= p[j + 1].se - p[q].se)
// us[q] = 1 ;
// }
// for(int j = 1 ; j <= n ; j++)
// cnt += us[j] ;
// if(cnt == n)
// ans = min(ans, now) ;
// }
// cout << ans << '\n' ;
// return 0 ;
// }
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... |