# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
196996 | quocnguyen1012 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 6 ms | 1272 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn = 3e4 + 5;
int N, M;
vector<int> have[maxn];
int dist[maxn], b[maxn], p[maxn];
bool Have(int pos, int val)
{
int l = lower_bound(have[pos].begin(), have[pos].end(), val) - have[pos].begin();
return (l < have[pos].size() && have[pos][l] == val);
}
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("A.INP", "r")){
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
cin >> N >> M;
for (int i = 0; i < M; ++i){
cin >> b[i] >> p[i];
have[b[i]].pb(p[i]);
}
pq.push(mp(b[0], 0));
fill_n(&dist[0], maxn, 1e9 + 5);
dist[b[0]] = 0;
for (int i = 0; i < N; ++i){
sort(have[i].begin(), have[i].end());
have[i].erase(unique(have[i].begin(), have[i].end()), have[i].end());
}
while (pq.size()){
auto now = pq.top(); pq.pop();
if (dist[now.se] != now.fi) continue;
//cerr << now.fi << ' ' << now.se << '\n';
for (auto all : have[now.se]){
for (int i = 1; i < maxn; ++i){
if (now.se + i * all < N){
if (dist[now.se + i * all] > now.fi + i){
dist[now.se + i * all] = now.fi + i;
pq.push(mp(now.fi + i, now.se + i * all));
if (Have(now.se + i * all, all)) break;
}
}
else break;
}
for (int i = 1; i < maxn; ++i){
if (now.se - i * all >= 0){
if (dist[now.se - i * all] > now.fi + i){
dist[now.se - i * all] = now.fi + i;
pq.push(mp(now.fi + i, now.se - i * all));
if (Have(now.se - i * all, all)) break;
}
}
else break;
}
}
}
if (dist[b[1]] == 1e9 + 5) dist[b[1]] = -1;
cout << dist[b[1]] << '\n';
}
컴파일 시 표준 에러 (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... |