# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
25390 | gabrielsimoes | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 3 ms | 2960 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int MAXN = 3e4 + 100;
const ll INF = ll(MAXN)*ll(MAXN);
int N, M;
vector<int> v[MAXN];
ll dp[MAXN];
ll f(int cur) {
if (dp[cur] != -1) return dp[cur];
dp[cur] = INF;
for (int dx : v[cur]) {
int i = cur - dx*(cur/dx);
do dp[cur] = min(dp[cur], f(i) + abs(cur - i)/dx);
while ((i += dx) < N);
}
return dp[cur];
}
int main()
{
scanf("%d %d", &N, &M);
int X, Y;
for (int i = 0,a,b; i < M; i++) {
scanf("%d %d", &a, &b);
if (i == 0) X = a;
else if (i == 1) Y = a;
if (b != 0)
v[a].push_back(b);
}
memset(dp, -1, sizeof(dp));
dp[Y] = 0;
ll ans = f(X);
printf("%lld\n", ans < INF ? ans : -1);
}
컴파일 시 표준 에러 (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... |