# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
223559 | infinite_iq | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1084 ms | 38540 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.
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 547
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll inf=1e18;
const ld pai=acos(-1);
int n , m , sta , en ;
vpi v[30009] ;
unordered_set<int>s[30009];
int dis[30009] , done[30009] ;
int main () {
scanf("%d%d",&n,&m);
for ( int i = 0 ; i < m ; i ++ ) {
int pos , x ;
scanf("%d%d",&pos,&x);
if ( i == 0 ) sta = pos ;
if ( i == 1 ) en = pos ;
s[pos].ins ( x ) ;
}
for ( int i = 0 ; i < n ; i ++ ) {
dis [i] = 1e9 ;
for ( auto u : s[i] ) {
int len = 0 ;
for ( int j = i + u ; j < n ; j += u ) {
len ++ ;
int a = i ;
int b = j ;
v[a].pb ( { b , len } ) ;
if ( s[j] .find ( u ) != s[j] .end() ) break ;
}
len = 0 ;
for ( int j = i - u ; j >= 0 ; j -= u ) {
len ++ ;
int a = i ;
int b = j ;
v[a].pb ( { b , len } ) ;
if ( s[j] .find ( u ) != s[j] .end() ) break ;
}
}
}
set<pi>st;
dis [sta] = 0 ;
st .ins ( { 0 , sta } ) ;
while ( st.size() ) {
int node = st.begin()->se;
int t = st.begin()->fi;
st .era( st.begin() );
done [ node ] =1 ;
for ( auto U : v[node] ) {
int u = U.fi ;
int x = U.se ;
if ( done [u] ) C ;
if ( st.find ( { dis[u] , u } ) != st.end() ) st.era ( { dis[u] , u } ) ;
dis [u] = min ( dis[u] , t + x ) ;
st.ins ( { dis[u] , u } ) ;
}
}
if ( dis [ en ] == 1e9 ) dis[ en ] = -1 ;
printf("%d\n",dis[en]);
}
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... |