이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
template<class T>
bool operator()(T const &a, T const &b) const { return a > b; }
};
ll n,v;
set<ll>scrapes[30006];
set<dos>scrapes1[30006];
ll dist[30006];
void preprocess(int tower,int range)
{
int weight=1;
for (int i = tower+range; i < n; i+=range)
{
scrapes1[tower].insert({i,weight});
weight++;
if(scrapes[i].find(range)!=scrapes[i].end())break;
}
weight=1;
for (int i = tower-range; i >= 0; i-=range)
{
scrapes1[tower].insert({i,weight});
weight++;
if(scrapes[i].find(range)!=scrapes[i].end())break;
}
}
int start[30001],endi[30001];
int main()
{
//flash;
cin>>n>>v;
ll rooto,dest;
for (ll i = 0; i < v; ++i)
{
ll x,y;
cin>>x>>y;
start[i]=x,endi[i]=y;
scrapes[x].insert(y);
if(i==0)rooto=x;
else if(i==1)dest=x;
}
for (ll i = 0; i < v; ++i)
{
preprocess(start[i],endi[i]);
}
for (ll i = 0; i < n; ++i)
{
dist[i]=INF;
}
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>g;
g.push({0,rooto});
dist[rooto]=0;
while(!g.empty())
{
auto u = g.top();
auto tower = u.second;
g.pop();
if(dist[tower]<u.first)continue;
if(tower==dest)break;
for (auto k:scrapes1[tower])
{
if(dist[k.first]>u.first+k.second)
{
dist[k.first]=u.first+k.second;
g.push({u.first+k.second,k.first});
}
}
}
ll ans=INF;
//debugs(rooto,dest);
ans=min(ans,dist[dest]);
if(ans==INF)cout<<-1;
else cout<<ans;
return 0;
}
//code the AC sol !
// BS/queue/map
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("O3")
skyscraper.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("unroll-loops")
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:77:5: warning: 'dest' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(tower==dest)break;
^~
skyscraper.cpp:70:14: warning: 'rooto' may be used uninitialized in this function [-Wmaybe-uninitialized]
dist[rooto]=0;
~~~~~~~~~~~^~
# | 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... |