# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
905871 | Sir_Ahmed_Imran | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1048 ms | 55460 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.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define M 30001
#define N 30001
int x[M];
int e[N];
vector<int> a[N];
vector<int> b[N];
map<int,int> vis[N];
void solve(){
int n,m,o,p,q,r;
cin>>n>>m;
for(int i=o=0;i<m;i++){
cin>>x[i]>>q;
if(!vis[x[i]][q])
a[x[i]].append(q);
vis[x[i]][q]=1;
}
set<int> c;
unordered_set<int> v{x[0]},u;
while(!v.empty()){
for(auto& i:v){
e[i]=1;
if(i==x[1]){
cout<<o;
return;
}
}
for(auto& i:v){
for(auto& j:a[i]){
if(i>=j && !vis[i-j][j]){
if(e[i-j]){
c.insert(i-j);
b[i-j].append(j);
}
else a[i-j].append(j);
vis[i-j][j]=1;
u.insert(i-j);
}
if(i+j<n && !vis[i+j][j]){
if(e[i+j]){
c.insert(i+j);
b[i+j].append(j);
}
else a[i+j].append(j);
vis[i+j][j]=1;
u.insert(i+j);
}
if(i>=j && !a[i-j].empty() && !e[i-j])
u.insert(i-j);
if(i+j<n && !a[i+j].empty() && !e[i+j])
u.insert(i+j);
}
e[i]=0;
a[i].clear();
}
o++;
for(auto& i:c){
for(auto& j:b[i])
a[i].append(j);
b[i].clear();
}
swap(v,u);
u.clear();
c.clear();
}
cout<<-1;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
solve();
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... |