이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Editor: Abdelrahman Hossam
Nickname: Blobo2_Blobo2
IOI next year isA :)
*/
/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")*/
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define gen(arr,n,nxt) generate(arr,arr+n,nxt)
#define Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty ios_base::sync_with_stdio(false);cin.tie(0);
const int mo=1e9+7,INF=1e18;
int nxt(){int x;cin>>x;return x;}
signed main(){
Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty
int n=nxt(),m=nxt();
vector<pair<int,int> >v;
map<pair<int,int>,int>mp;
for(int i=0;i<m;i++){
int b=nxt(),p=nxt();
if(mp[{b,p}])continue;
mp[{b,p}]=1;
v.push_back({b,p});
}
int from = v[0].first,to = v[1].first;
vector<pair<int,int> >adj[n+1];
for(int i=0;i<v.size();i++){
for(int j=v[i].first+v[i].second;j<n;j+=v[i].second){
adj[v[i].first].push_back({j,(j-v[i].first)/v[i].second});
if(mp[{j,v[i].second}])break;
}
}
for(int i=0;i<v.size();i++){
for(int j=v[i].first-v[i].second;j>=0;j-=v[i].second){
adj[v[i].first].push_back({j,(v[i].first-j)/v[i].second});
if(mp[{j,v[i].second}])break;
}
}
int dis[n],vis[n];
for(int i=0;i<n;i++)
dis[i]=INF,vis[i]=0;
dis[from]=0;
priority_queue<pair<int,int> >q;
q.push({0,from});
while(!q.empty()) {
int a=q.top().second;q.pop();
if(vis[a])continue;
vis[a]=1;
for(auto u:adj[a]){
int b=u.first,w=u.second;
if(dis[a]+w<dis[b]){
dis[b]=dis[a]+w;
q.push({-dis[b],b});
}
}
}
if(dis[to]==INF)cout<<-1<<endl;
else cout<<dis[to]<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp:19:24: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
19 | const int mo=1e9+7,INF=1e18;
| ^~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
skyscraper.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
# | 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... |