| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 660787 | danikoynov | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 53 ms | 95200 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 30010;
const ll inf = 1e18;
struct doge
{
int b, p;
} d[maxn];
struct edge
{
int u, p;
ll w;
edge(int _u, int _p, ll _w)
{
p = _p;
u = _u;
w = _w;
}
bool operator < (const edge &e) const
{
return w > e.w;
}
};
vector < edge > g[2010][2010];
int n, m, used[2010][2010];
ll dp[2010][2010];
void dijkstra(int s)
{
for (int i = 0; i <= n; i ++)
for (int j = 0; j <= n; j ++)
{
used[i][j] = -1;
}
deque < edge > dq;
dq.push_back(edge(d[0].b, d[0].p, 0));
while(!dq.empty())
{
edge cur = dq.front();
dq.pop_front();
if (used[cur.u][cur.p] != -1)
continue;
used[cur.u][cur.p] = cur.w;
///cout << cur.u << " : " << cur.p << " " << cur.w << endl;
for (int i = 0; i < g[cur.u][cur.p].size(); i ++)
{
edge nb = g[cur.u][cur.p][i];
if (used[nb.u][nb.p] != -1)
continue;
if (nb.w == 0)
{
dq.push_front(edge(nb.u, nb.p, cur.w));
}
else
{
dq.push_back(edge(nb.u, nb.p, cur.w + 1));
}
}
}
}
void solve()
{
cin >> n >> m;
for (int i = 0; i < m; i ++)
{
cin >> d[i].b >> d[i].p;
}
for (int i = 0; i < n; i ++)
for (int j = 0; j < n - 1; j ++)
{
if (i - j >= 0)
g[i][j].push_back(edge(i - j, j, 1));
if (i + j < n)
g[i][j].push_back(edge(i + j, j, 1));
g[i][j].push_back(edge(i, n, 0));
}
for (int i = 0; i < m; i ++)
{
g[d[i].b][n].push_back(edge(d[i].b, d[i].p, 0));
}
dijkstra(0);
ll best = inf;
for (int j = 0; j < n; j ++)
{
if (used[d[1].b][j] != -1)
best = min(best, (ll)used[d[1].b][j]);
}
if (best == inf)
cout << -1 << endl;
else
cout << best << endl;
}
int main()
{
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... | ||||
