이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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] ;
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 ++ ;
v[i].pb ( { j , len } ) ;
if ( s[j] .count ( u ) ) break ;
}
len = 0 ;
for ( int j = i - u ; j >= 0 ; j -= u ) {
len ++ ;
v[i].pb ( { j , len } ) ;
if ( s[j] .count ( u ) ) break ;
}
}
}
priority_queue< pair<int , int> , vector< pair<int , int> > , greater< pair<int , int> > > st ;
dis [sta] = 0 ;
st .push ( { 0 , sta } ) ;
while ( st.size() ) {
int node = st.top().se;
int t = st.top().fi;
st .pop();
if ( node == en ) {
printf("%d\n",t);
exit(0);
}
if ( t > dis[node] ) C ;
for ( auto U : v[node] ) {
int u = U.fi ;
int x = U.se ;
if ( t + x < dis [u] ) {
dis [u] = t + x ;
st.push ( { dis[u] , u } ) ;
}
}
}
printf("-1\n");
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:37:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&pos,&x);
~~~~~^~~~~~~~~~~~~~~~
# | 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... |