0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-09 16:18:49 +00:00

#2887. 「APIO2015」雅加达的摩天楼 Jakarta Skyscrapers

https://loj.ac/s/1527787
This commit is contained in:
Baoshuo Ren 2022-07-24 20:43:09 +08:00
parent c436e4bf97
commit 11b0627902
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
135 changed files with 496 additions and 0 deletions

94
LibreOJ/2887/2887.cpp Normal file
View File

@ -0,0 +1,94 @@
#include <iostream>
#include <bitset>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 30001;
int n, m, l, s, t;
std::vector<std::pair<int, short>> g[N * 101];
int dist[N * 101];
std::bitset<N * 101> vis;
int spfa() {
memset(dist, 0x3f, sizeof(dist));
std::queue<int> q;
dist[s] = 0;
q.push(s);
vis[s] = true;
while (!q.empty()) {
int u = q.front();
q.pop();
vis[u] = false;
for (auto t : g[u]) {
int v = t.first;
short w = t.second;
if (dist[v] > dist[u] + w) {
dist[v] = dist[u] + w;
if (!vis[v]) {
q.push(v);
vis[v] = true;
}
}
}
}
return dist[t] == 0x3f3f3f3f ? -1 : dist[t];
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
l = std::min(static_cast<int>(std::sqrt(n)), 100);
for (int i = 1, b, p; i <= m; i++) {
cin >> b >> p;
b++;
if (i == 1) s = b;
if (i == 2) t = b;
if (p <= l) {
g[b].emplace_back(p * n + b, 0);
} else {
for (int j = 1; b + j * p <= n; j++) {
g[b].emplace_back(b + j * p, j);
}
for (int j = 1; b - j * p > 0; j++) {
g[b].emplace_back(b - j * p, j);
}
}
}
for (int i = 1; i <= l; i++) {
for (int j = 1; j <= n; j++) {
g[i * n + j].emplace_back(j, 0);
}
for (int j = 1; j <= n - i; j++) {
g[i * n + j].emplace_back(i * n + j + i, 1);
g[i * n + j + i].emplace_back(i * n + j, 1);
}
}
cout << spfa() << endl;
return 0;
}

BIN
LibreOJ/2887/data/skyscraper_0_1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_0_1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_1_1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_1_1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_1_2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_1_2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_1_3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_1_3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_1_4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_1_4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_1_5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_1_5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_1_6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_1_6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_2_8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_3_9.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_4_9.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_5_1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_5_1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_5_10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_5_10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_5_11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_5_11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2887/data/skyscraper_5_12.in (Stored with Git LFS) Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More