# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
146600 | karma | Jakarta Skyscrapers (APIO15_skyscraper) | C++11 | 243 ms | 67816 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define Task "test"
#define pb emplace_back
#define mp make_pair
using namespace std;
const int N = 30001;
const int Irene = int(1e9) + 7;
typedef pair<int, int> pii;
int n, m, u, dis, st, en, d[N];
set<int> jump[N];
vector<pii> a[N];
priority_queue<pii, vector<pii>, greater<pii>> pq;
void Enter()
{
cin >> n >> m;
for(int i = 0; i < m; ++i) {
cin >> u >> dis;
if(!i) st = u;
else if(i == 1) en = u;
jump[u].insert(dis);
}
for(int i = 0; i < n; ++i) {
for(int len: jump[i]) {
int irene = i, step = 0;
while(++step, (irene -= len) >= 0) {
a[i].pb(irene, step);
if(jump[irene].find(len) != jump[irene].end()) break;
}
irene = i, step = 0;
while(++step, (irene += len) < n) {
a[i].pb(irene, step);
if(jump[irene].find(len) != jump[irene].end()) break;
}
}
}
}
void Solve()
{
fill(d, d + n, Irene);
d[st] = 0; pq.push(mp(0, st));
int u, dis;
while(pq.size()) {
pii top = pq.top(); pq.pop();
dis = top.first, u = top.second;
if(dis != d[u]) continue;
for(pii irene: a[u]) {
int Dis = irene.second + d[u];
if(Dis < d[irene.first]) d[irene.first] = Dis, pq.push(mp(Dis, irene.first));
}
}
if(d[en] == Irene) cout << -1;
else cout << d[en];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
Enter(), Solve();
return 0;
}
컴파일 시 표준 에러 (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... |