# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
735363 | ReLice | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 122 ms | 48460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define pb push_back
#define endl "\n"
#define fr first
#define sc second
#define sz size()
#define bc back()
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}*/
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e9+7;
const ll mod=1e9+7;
const ll N=2e3+7;
ll n,l,r,d[N];
int edge[N][N];
vector <vector <pair<ll,ll>> > g(N);
void dijkstra(ll val){
set <pair<ll,ll>> q;
q.insert({0,val});
d[val]=0;
while(!q.empty()){
ll x=q.begin()->sc;
q.erase(q.begin());
for(auto i : g[x]){
ll len=i.sc,to=i.fr;
if(d[to]>d[x]+len){
q.erase({d[to], to});
d[to]=d[x]+len;
q.insert({d[to],to});
}
}
}
}
void solve(){
ll i,j,q,sum=0,ans=0,b,mx=-1,c=1,m,t;
ll k;
cin>>n>>m;
memset(edge, -1, sizeof(edge));
for(i=0;i<m;i++){
cin>>b>>t;
if(i==0) k=b;
if(i==1) q=b;
c=0;
for(j=b+t;j<n;j+=t){
c++;
if (edge[b][j] == -1 || edge[b][j] > c) {
edge[b][j] = c;
}
}
c=0;
for(j=b-t;j>=0;j-=t){
c++;
if (edge[b][j] == -1 || edge[b][j] > c) {
edge[b][j] = c;
}
}
}
for (int a = 0; a < n; ++a) {
for (int b = 0; b < n; ++b) {
if (edge[a][b] == -1) {
continue;
}
g[a].push_back({b, edge[a][b]});
}
}
for(i=0;i<n;i++) d[i]=inf;
dijkstra(k);
if(d[q]==inf) cout<<-1<<endl;
else cout<<d[q]<<endl;
}
signed main(){
//start();
//fre("");
ll t=1;
//cin>>t;
while(t--) solve();
}
/*
5 3
0 2
1 1
4 1
*/
컴파일 시 표준 에러 (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... |