# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1037625 | Muhammet | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1 ms | 604 KiB |
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>
using namespace std;
#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second
const ll N = 30002;
ll T, n, m, dis[N];
vector <int> v1;
pair<int,int> a[N];
set <int> v;
int main(){
// ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> a[i].ff >> a[i].ss;
if(a[i].ff != a[0].ff){
v.insert(a[i].ff);
}
}
int ind = a[0].ff, p = a[1].ff;
sort (a,a+m);
for(int i = 0; i <= n; i++) dis[i] = 1e9;
dis[ind] = 0;
for(int i = 0; i < m; i++){
if(a[i].ff == ind){
if(sz(v1) > 0 and a[i].ss == v1.back()) continue;
v1.push_back(a[i].ss);
}
}
while(sz(v) > 0){
int mn = 1e9, k = -1, cnt = 0, b = 0;
for(auto i : v1){
for(auto j : v){
if(dis[j] < mn){
mn = dis[j];
k = j;
}
if(abs(j-ind) % i != 0) continue;
dis[j] = min(dis[j],dis[ind]+abs(j-ind)/i);
if(dis[j] < mn){
mn = dis[j];
k = j;
}
}
}
v1.clear();
int l = 0, r = m-1, x;
while(l <= r){
int md = (l + r) / 2;
if(a[md].ff >= k){
x = md;
r = md-1;
}
else {
l = md+1;
}
}
ind = k;
for(int i = x; i < m; i++){
if(a[i].ff == ind){
if(sz(v1) > 0 and a[i].ss == v1.back()) continue;
v1.push_back(a[i].ss);
}
else break;
}
v.erase(v.find(ind));
if(ind == p) break;
}
cout << dis[p];
return 0;
}
Compilation message (stderr)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |