# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
470668 | robell | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 354 ms | 180992 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.
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long ll;
#define pb push_back
#define eb emplace_back
#define countbits __builtin_popcount
#define beg0 __builtin_clz
#define terminal0 __builtin_ctz
#define mod 1e9+7
void setIO(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
void setIO(string f){
freopen((f+".in").c_str(),"r",stdin);
freopen((f+".out").c_str(),"w",stdout);
setIO();
}
int jmp[2020][2020];
int b[2020];
int p[2020];
int N, M;
vector<pair<int,int>> adj[2020][2020];
int main(){
setIO();
cin >> N >> M;
for (int i=0;i<M;i++){
cin >> b[i] >> p[i];
for (int j=b[i]-p[i];j>=0;j-=p[i]){
adj[j+p[i]][p[i]].pb({j,p[i]});
adj[j+p[i]][p[i]].pb({j,2010});
}
for (int j=b[i]+p[i];j<N;j+=p[i]){
adj[j-p[i]][p[i]].pb({j,p[i]});
adj[j-p[i]][p[i]].pb({j,2010});
}
adj[b[i]][2010].pb({b[i],p[i]});
adj[b[i]][p[i]].pb({b[i],2010});
}
memset(jmp,-1,sizeof(jmp));
jmp[b[0]][2010]=0;
jmp[b[0]][p[0]]=0;
deque<pair<int,int>> q;
q.push_back({b[0],p[0]});
q.push_back({b[0],2010});
while (!q.empty()){
pair<int,int> n = q.front();
q.pop_front();
int c = 1;
if (n.second==2010){
c=0;
}
for (pair<int,int> s:adj[n.first][n.second]){
if ((jmp[s.first][s.second]==-1)||(jmp[s.first][s.second]>jmp[s.first][s.second]+c)){
jmp[s.first][s.second]=c+jmp[n.first][n.second];
if (c==0){
q.push_front({s.first,s.second});
}else{
q.push_back({s.first,s.second});
}
}
}
}
cout << jmp[b[1]][p[1]] << "\n";
}
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... |