| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 249268 | hunni10 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1095 ms | 25668 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<stdio.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<math.h>
#include<string.h>
#include<queue>
#include<list>
#include<time.h>
#include<assert.h>
#include<unordered_set>
#define MAX_DIVISOR 128
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
int n, m;
int b[30000];
int p[30000];
int shortest[30000];
vector<int> building_doge[30000];
vector<vector<int> > div_grid[MAX_DIVISOR+1];
bool visited[30000] = {0, };
bool inSorted[30000] = { 0, };
set<pii> sorted;
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d %d", b + i, p + i);
}
for (int i = 0; i < m; i++) {
shortest[i] = 0x7FFFFFFF;
}
for (int i = 1; i <= MAX_DIVISOR; i++) {
div_grid[i].assign(i, {});
}
for (int i = 0; i < m; i++) {
building_doge[b[i]].push_back(i);
for (int divisor = 1; divisor <= MAX_DIVISOR; divisor++) {
div_grid[divisor][b[i] % divisor].push_back(i);
}
}
shortest[0] = 0;
inSorted[0] = true;
sorted.insert({ 0, 0 });
while (true) {
if (sorted.empty()) { printf("-1"); break; }
pii now = *sorted.begin();
if (now.second == 1) {
printf("%d", now.first);
break;
}
visited[now.second] = true;
if (p[now.second] <= MAX_DIVISOR) {
for (int v : div_grid[p[now.second]][b[now.second] % p[now.second]]) {
if (visited[v]) continue;
int times = (b[v] - b[now.second]) / p[now.second];
if (times < 0) times = -times;
times += now.first;
if (times < shortest[v]) {
if (inSorted[v]) {
sorted.erase({ shortest[v], v });
}
shortest[v] = times;
sorted.insert({ shortest[v], v });
inSorted[v] = true;
}
}
}
else {
int i = b[now.second] % p[now.second];
for (; i < n; i+= p[now.second]) {
for (int v : building_doge[i]) {
if (visited[v]) continue;
if ((i - b[now.second]) % p[now.second] == 0) {
int times = (i - b[now.second]) / p[now.second];
if (times < 0) times = -times;
times += now.first;
if (times < shortest[v]) {
if (inSorted[v]) {
sorted.erase({ shortest[v], v });
}
shortest[v] = times;
sorted.insert({ shortest[v], v });
inSorted[v] = true;
}
}
}
}
}
sorted.erase(sorted.begin());
}
}
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... | ||||
