이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;
template <class _T>
bool chmin(_T &x, const _T &y){
bool f=0;
if (x>y){x=y;f=1;}
return f;
}
template <class _T>
bool chmax(_T &x, const _T &y){
bool f=0;
if (x<y){x=y;f=1;}
return f;
}
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e18+7;
const ll mod=1e9+7;
const ll N=1e5+7;
const ld eps=1e-9;
void solve(){
ll i,j;
ll n;
cin>>n;
pll v2,v(n);
for(i=0;i<n;i++) cin>>v[i].fr>>v[i].sc;
sort(all(v));
for(i=0;i<n;i++){
v2.pb({v[i].sc,i});
}
sort(rall(v2));
vector<bool> f(n,false);
ll ans=0;
for(i=0;i<n;i++){
ll x=v2[i].sc;
if(f[x]) continue;
ll l=x-1,r=x+1;
f[x]=1;
ans++;
while(l>=0 && abs(v[x].fr-v[l].fr)<=v[x].sc-v[l].sc && !f[l]){
f[l]=1;
l--;
}
while(r<n && abs(v[x].fr-v[r].fr)<=v[x].sc-v[r].sc && !f[r]){
f[r]=1;
r++;
}
}
cout<<ans<<endl;
}
signed main(){
start();
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void solve()':
Main.cpp:46:10: warning: unused variable 'j' [-Wunused-variable]
46 | ll i,j;
| ^
# | 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... |