Submission #695152

#TimeUsernameProblemLanguageResultExecution timeMemory
695152edogawa_somethingJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
793 ms262144 KiB
#include<bits/stdc++.h> #include<chrono> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef string st; typedef bool bl; typedef vector<ll> vii; typedef pair<ll,ll> pii; typedef vector<pii> vpi; #define pu push #define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> #define fast ios_base::sync_with_stdio(0);cin.tie(); #define test ll qqqqq;cin>>qqqqq;while(qqqqq--) #define F first #define S second #define forn(i,n) for(ll i=0;i<n;i++) #define forx(i,j,n) for(ll i=j;i<n;i++) #define pb push_back #define pob pop_back #define all(v) v.begin(),v.end() #define lb lower_bound #define ub upper_bound #define pof pop_front #define pow powww #define prtll(x) printf("%lld",x) #define prtld(x) printf("%Lf",x) #define prtst(x) printf("%s",x) #define prtch(x) printf("%c",x) #define measure chrono::high_resolution_clock::now() const ll dx[]{1,0,-1,0}; const ll dy[]{0,-1,0,1}; const ll inf=2e18; const ll mod=1e9+7; const ll LM=2e7+1; const ll M=2e6+1; const ll MM=3002; const ll MMM=501; const ld pi=acos(-1); //const ll mod=998244353; ll pow(ll r,ll to,ll m=mod){ ll res=1; r%=mod; while(to){ if((to&1)){ res*=r,res%=mod; } r*=r,r%=mod; to=(to>>1); } return res; } ll n,m,a[M],p[M],dis[MM][MM],ind0,ind1,dist[M]; vii v[M]; vpi vv[M]; void dij(ll ind){ priority_queue<pii,vpi,greater<pii>>q; q.push({0,ind}); dist[ind]=0; while(!q.empty()){ pii x=q.top(); q.pop(); for(auto it:vv[x.S]){ if(dist[it.F]>x.F+it.S) q.push({x.F+it.S,it.F}),dist[it.F]=x.F+it.S; } } } int main(){ fast memset(dis,mod,sizeof dis); memset(dist,mod,sizeof dist); cin>>n>>m; forn(i,m){ cin>>a[i]>>p[i]; v[a[i]].pb(p[i]); if(i==0) ind0=a[i]; if(i==1) ind1=a[i]; } forn(i,n){ forn(j,n){ for(auto it:v[i]){ if(abs(i-j)%it==0) dis[i][j]=min(dis[i][j],abs(i-j)/it); } } } forn(i,n){ forn(j,n){ if(dis[i][j]<mod) vv[i].pb({j,dis[i][j]}); } } dij(ind0); if(dist[ind1]>=mod) dist[ind1]=-1; cout<<dist[ind1]; return 0; } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...