이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#include<fstream>
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
typedef unsigned long long ull;
#define pii pair<int, int>
#define pll pair<ll, ll>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
const ll mod= 1e9 + 7;
const int mxk = 1e3, sq = 750, mxn = 3e4;
const ll inf = -1e18;
int n, m;
vt<pii>adj[mxn + 1];
int b[mxn + 1], p[mxn + 1];
set<int>s[mxn + 1];
ll d[mxn + 1];
struct ch{
int u; ll d;
};
struct cmp{
bool operator ()(const ch &a, const ch &b){
return(a.d > b.d);
}
};
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
forr(i, 0, m){
cin >> b[i] >> p[i];
s[b[i]].insert(p[i]);
}
forr(i, 0, m){
int pos = b[i];
for(int j = pos - p[i]; j >= 0; j -= p[i]){
adj[pos].pb({j, (pos - j) / p[i]});
//cout << pos << ' ' << j << " ";
if(s[j].count(p[i]))break;
}
for(int j = pos + p[i]; j < n; j += p[i]){
adj[pos].pb({j, (j - pos) / p[i]});
if(s[j].count(p[i]))break;
}
}
for(int i = 0; i < n; i++)d[i] = 1e18;
priority_queue<ch, vt<ch>, cmp>pq; d[b[0]] = 0; pq.push({b[0], d[b[0]]});
while(pq.size()){
auto [u, dd] = pq.top(); pq.pop();
if(d[u] != dd)continue;
if(u == b[1]){
cout << d[u];
return(0);
}
for(auto [v, w]: adj[u]){
if(d[u] + w < d[v]){
d[v] = d[u] + w;
pq.push({v, d[v]});
}
}
}
cout << -1;
return(0);
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:58:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
58 | auto [u, dd] = pq.top(); pq.pop();
| ^
skyscraper.cpp:65:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
65 | for(auto [v, w]: adj[u]){
| ^
# | 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... |