# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238139 | Mercenary | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 9 ms | 3456 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define pb push_back
#define mp make_pair
#define taskname "SKY"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int maxn = 5e4 + 5;
const int mod = 1e9 + 7;
int dis[maxn] , n , m;
unordered_set<int> s[maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP", "r",stdin);
freopen(taskname".OUT", "w",stdout);
}
cin >> n >> m;
int ft = 0 , lt = 0;
for(int i = 0 ; i < m ; ++i){
int u ,v;cin >> u >> v;s[u].insert(v);
if(i == 0)ft = u;
if(i == 1)lt = u;
}
priority_queue<ii , vector<ii> , greater<ii> > pq;
fill_n(dis,maxn,1e9);
dis[ft] = 0;pq.push(mp(0,ft));
while(pq.size()){
auto u = pq.top();pq.pop();
if(dis[u.second] != u.first)continue;
for(auto &c : s[u.second]){
int cnt = 0;
for(int i = u.second + c ; i < n ; i += c){
cnt++;
if(u.first + cnt < dis[i]){
dis[i] = u.first + cnt;pq.push(mp(dis[i],i));
}
if(s[i].count(c))break;
}
cnt = 0;
for(int i = u.second - c ; i > 0 ; i -= c){
cnt++;
if(u.first + cnt < dis[i]){
dis[i] = u.first + cnt;pq.push(mp(dis[i],i));
}
if(s[i].count(c))break;
}
}
}
if(dis[lt] == 1e9)cout << -1;
else cout << dis[lt];
}
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... |