#include <bits/stdc++.h>
using namespace std;
#define print(l) for(auto i:l) cout<<i<<" ";cout<<endl;
#define input(t,l,n) vector<t>l(n);for(int i = 0;i<n;i++)cin>>l[i];
#define int long long
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define all(l) l.begin(),l.end()
#define pii pair<int,int>
#define fi first
#define se second
const int M = 1e9+7;
const int inf = 1e18;
void io(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
// freopen("outputf.in","w",stdout);
#endif
}
int bp(int x, int y, int p){
int res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int MI(int n, int p){
return bp(n, p - 2, p);
}
int mul(int x,int y, int p){
return x * 1ull * y % p;
}
int di(int x,int y, int p){
return mul(x, MI(y, p), p);
}
map<int , vector<int>>adj;
map<int,int>give;
int n , m , k , q;
map<int,int>po;
void solve(int testcase_number){
cin>>n;
vector<pii>inp;
for(int i = 0;i<n;i++){
cin>>m>>k;
po[m] = max(po[m],k);
// inp.pb({m,k});
}
for(auto i:po){
inp.pb(i);
// cout<<i.fi<<" "<<i.se<<endl;
}
n = inp.size();
map<int,int>give;
for(int i = 0;i<n;i++){
for(int j = i+1;j<n;j++){
give[inp[i].fi]++;
// cout<<inp[i].fi<<" "<<inp[j].fi<<" "<<(int)(abs(inp[i].fi-inp[j].fi) <= inp[i].se-inp[j].se)<<endl;
if((int)(abs(inp[i].fi-inp[j].fi) <= (inp[i].se-inp[j].se))) adj[inp[i].fi].pb(inp[j].fi);
if((int)(abs(inp[i].fi-inp[j].fi) <= (inp[j].se-inp[i].se))) adj[inp[j].fi].pb(inp[i].fi);
// adj[inp[j].fi].pb({inp[i].fi,(int)(abs(inp[i].fi-inp[j].fi) <= (inp[j].se-inp[i].se))});
}
}
map<int,set<int>>rec;
map<int,set<int>>send;
vector<pii>rem;
map<int,int>recived;
for(auto i:adj){
// print(i.se);
for(auto j:i.se){
send[i.fi].insert(j);
rec[j].insert(i.fi);
give[i.fi]++;
// cout<<i.fi<<" "<<j<<endl;
}
}
for(auto i:give){
rem.pb({i.se+1,i.fi});
}
// print(rem);
int donate = 0;
// int tt = 5;
int don = 0;
while(rem.size()){
sort(all(rem));
// print(rem);
int x = rem.back().se;
// cout<<x<<endl;
rem.clear();
donate++;
if(recived[x] == 0){
don++;
}
recived[x]++;
for(auto j:send[x]){
if(recived[j] == 0){
don++;
}
recived[j]++;
}
send.clear();
rec.clear();
give.clear();
for(auto i:adj){
if(i.fi == x)continue;
for(auto j:i.se){
if(recived[j])continue;
send[i.fi].insert(j);
rec[j].insert(i.fi);
give[i.fi]++;
// cout<<i.fi<<" "<<j<<endl;
}
}
for(auto i:give){
rem.pb({i.se+(recived[i.fi] == 0),i.fi});
}
}
// for(auto i:inp){
// cout<<i.fi<<endl;
// cout<<recived[i.fi]<<endl;
// }
cout<<donate+n-don<<endl;
}
signed main(){
// io();
ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
cin.tie(0), cout.tie(0);
cout << fixed<<setprecision(9);
int t = 1;
// cin>>t;
for(int i = 1;i<=t;i++){
solve(i);
}
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void io()':
Main.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | freopen("input.txt","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~| # | 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... |