# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
695266 | Mr_Ph | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1 ms | 288 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
///Never gonna give you up.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
const ll mod=(ll)1e9+7;
const ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
///the end of the defines ;)
void bla()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("notsus.txt","w",stdout);
#endif
}
int n,m;
vector<vector<pair<int,int>>>adj;
void preprocess(){}
void solve()
{
cin>>n>>m;
adj.resize(n+1);
map<int,int>mp;
for(int i=0;i<m;i++)
{
int a,b;
cin>>a>>b;
int cnt=0;
mp[i]=a;
for(int i=a-b;i>=0;i-=b)
{
cnt++;
adj[a].push_back({i,cnt});
}
cnt=0;
for(int i=a+b;i<n;i+=b)
{
cnt++;
adj[a].push_back({i,cnt});
}
}
priority_queue<pair<int,int>>q;
q.push({mp[0],0});
vector<int>dis;
for(int i=0;i<=n+3;i++)dis.push_back(1e9);
dis[mp[0]]=0;
bool vs[n+5]={false};
vs[mp[0]]=true;
while(q.sz)
{
int node=q.top().second,cost=q.top().first;
q.pop();
vs[node]=false;
for(auto i:adj[node])
{
if(dis[node]+i.second<dis[i.first])
{
dis[i.first]=dis[node]+i.second;
if(!vs[i.first]) q.push({dis[i.first], i.first});
vs[i.first] = true;
}
}
}
if(dis[mp[1]]==1e9)cout<<-1<<endl;
else
cout<<dis[mp[1]]<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
preprocess();
//bla();
int t=1;
//cin>>t;
while(t--)
solve();
}
컴파일 시 표준 에러 (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... |