이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 1000007;
const ll inf = 1e9;
const ll INF = 1e12;
const ll mod = 1e9 + 7;
const double eps = 1e-6;
vector < pair <ll,ll> > order;
vector <int> adj[M];
map <ll,ll> mp;
ll n, a[M], b[M], dist[M];
bool reached[M];
void AddEdges(){
for(int i = 1; i < order.size(); ++i){
int l = order[i - 1].S;
int r = order[i].S;
adj[l].pb(r);
adj[r].pb(l);
}
return;
}
void Dijkstra(){
priority_queue < pair <ll,ll> > q;
for(int i = 1; i <= n; ++i){
q.push({b[i], i});
dist[i] = b[i];
}
while(!q.empty()){
int node = q.top().S;
ll cost = q.top().F;
q.pop();
if(dist[node] > cost) continue;
for(auto i : adj[node]){
ll d = abs(a[i] - a[node]);
if(dist[node] - d >= b[i]) reached[i] = 1;
if(dist[node] - d > dist[i]){
dist[i] = dist[node] - d;
q.push({dist[i], i});
}
}
}
return;
}
void solve(int _){
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> a[i] >> b[i];
mp[a[i]] = max(mp[a[i]], b[i]);
}
int idx = 0;
for(auto i : mp){
++idx;
a[idx] = i.F;
b[idx] = i.S;
}
n = idx;
for(int i = 1; i <= n; ++i) order.pb({a[i], i});
sort(all(order));
AddEdges();
Dijkstra();
ll ans = n;
for(int i = 1; i <= n; ++i) if(reached[i]) --ans;
cout << ans << endl;
return;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
for(int i = 1; i <= t; ++i) solve(t);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void AddEdges()':
Main.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i = 1; i < order.size(); ++i){
| ~~^~~~~~~~~~~~~~
# | 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... |