# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
861589 | anha3k25cvp | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1 ms | 600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define dl double
#define st first
#define nd second
#define II pair <int, int>
using namespace std;
const int N = 5 + 1e5;
const int inf = 7 + 1e9;
int n, m;
vector <int> b, p;
namespace subtask1 {
void main() {
vector <vector <int>> g(2000);
for (int i = 1; i <= m; i ++)
g[b[i]].push_back(i);
vector <vector <II>> adj(m + 1);
for (int i = 1; i <= m; i ++) {
int x = b[i], w = 0;
while (x - p[i] >= 0) {
x -= p[i];
w ++;
for (int j : g[x])
adj[i].push_back({j, w});
}
x = b[i]; w = 0;
while (x + p[i] < n) {
x += p[i];
w ++;
for (int j : g[x])
adj[i].push_back({j, w});
}
}
vector <int> f(m + 1, inf);
priority_queue <II> q;
q.push({-(f[1] = 0), 1});
while (!q.empty()) {
int du = -q.top().st, u = q.top().nd;
q.pop();
if (f[u] < du)
continue;
for (auto z : adj[u]) {
int v = z.st, w = z.nd;
if (du + w < f[v])
q.push({-(f[v] = du + w), v});
}
}
if (f[2] == inf)
f[2] = -1;
cout << f[2];
}
}
int main() {
#define TASKNAME ""
ios_base :: sync_with_stdio (0);
cin.tie (0);
if ( fopen( TASKNAME".inp", "r" ) ) {
freopen (TASKNAME".inp", "r", stdin);
freopen (TASKNAME".out", "w", stdout);
}
cin >> n >> m;
b.assign(m + 1, 0);
p.assign(m + 1, 0);
int check1 = n <= 2000;
for (int i = 1; i <= m; i ++) {
cin >> b[i] >> p[i];
if (b[i] > 2000 || p[i] > 2000)
check1 = 0;
}
if (check1)
subtask1 :: main();
return 0;
}
Compilation message (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... |