답안 #249711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
249711 2020-07-15T15:08:41 Z receed Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
301 ms 50040 KB
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;

const int N = 30001, M = 7500000;
map<pair<int, int>, vector<int>> li;
vector<int> g[N];
bitset<M> nx, pr;
short num[M];
int d[M];
bitset<M> used;

void adde(int u, int v, bool w) {
    g[u].push_back(v * 2 + w);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m, cb, cp, s, t;
    cin >> n >> m;
    rep(i, m) {
        cin >> cb >> cp;
        if (i == 0)
            s = cb;
        else if (i == 1)
            t = cb;
        li[{cp, cb % cp}].push_back(cb);
    }
    int cs = n;
    for (auto &pp : li) {
        auto p = pp.first;
        int ck = (n - p.second + p.first - 1) / p.first;
        rep(i, ck - 1) {
            nx[cs + i] = 1;
            pr[cs + i + 1] = 1;
        }
        rep(i, ck)
            num[cs + i] = p.second + i * p.first;
        for (int i : pp.second)
            adde(i, cs + (i - p.second) / p.first, 0);
        cs += ck;
        assert(cs < M);
    }
    deque<int> q {s};
    rep(i, cs)
        d[i] = M;
    d[s] = 0;
    while (!q.empty()) {
        int v = q.front();
        q.pop_front();
        if (used[v])
            continue;
        used[v] = 1;
        if (v < n)
            for (int p : g[v]) {
                int u = p / 2;
                if (p % 2) {
                    if (d[u] > d[v] + 1) {
                        d[u] = d[v] + 1;
                        q.push_back(u);
                    }
                }
                else if (d[u] > d[v]) {
                    d[u] = d[v];
                    q.push_front(u);
                }
            }
        else {
            if (nx[v] && d[v + 1] > d[v] + 1) {
                d[v + 1] = d[v] + 1;
                q.push_back(v + 1);
            }
            if (pr[v] && d[v - 1] > d[v] + 1) {
                d[v - 1] = d[v] + 1;
                q.push_back(v - 1);
            }
            if (d[num[v]] > d[v]) {
                d[num[v]] = d[v];
                q.push_front(num[v]);
            }
        }
    }
    if (d[t] == M)
        cout << -1;
    else
        cout << d[t];
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:106:12: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if (d[t] == M)
         ~~~^
skyscraper.cpp:70:10: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
     d[s] = 0;
     ~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1024 KB Output is correct
9 Correct 1 ms 1024 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 2 ms 1280 KB Output is correct
12 Correct 1 ms 1152 KB Output is correct
13 Correct 1 ms 1152 KB Output is correct
14 Correct 2 ms 1408 KB Output is correct
15 Correct 2 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1024 KB Output is correct
9 Correct 1 ms 1024 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 2 ms 1280 KB Output is correct
12 Correct 1 ms 1152 KB Output is correct
13 Correct 1 ms 1152 KB Output is correct
14 Correct 2 ms 1408 KB Output is correct
15 Correct 2 ms 1408 KB Output is correct
16 Correct 2 ms 1152 KB Output is correct
17 Correct 2 ms 1408 KB Output is correct
18 Correct 2 ms 1280 KB Output is correct
19 Correct 1 ms 1152 KB Output is correct
20 Correct 1 ms 1152 KB Output is correct
21 Correct 1 ms 1280 KB Output is correct
22 Correct 1 ms 1152 KB Output is correct
23 Correct 1 ms 1280 KB Output is correct
24 Correct 2 ms 1408 KB Output is correct
25 Correct 2 ms 1408 KB Output is correct
26 Correct 1 ms 1152 KB Output is correct
27 Correct 1 ms 1152 KB Output is correct
28 Correct 3 ms 1536 KB Output is correct
29 Correct 2 ms 1536 KB Output is correct
30 Correct 1 ms 1152 KB Output is correct
31 Correct 3 ms 1536 KB Output is correct
32 Correct 2 ms 1280 KB Output is correct
33 Correct 4 ms 2048 KB Output is correct
34 Correct 4 ms 2048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1024 KB Output is correct
9 Correct 1 ms 1024 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 2 ms 1280 KB Output is correct
12 Correct 1 ms 1152 KB Output is correct
13 Correct 1 ms 1152 KB Output is correct
14 Correct 2 ms 1408 KB Output is correct
15 Correct 2 ms 1408 KB Output is correct
16 Correct 1 ms 1152 KB Output is correct
17 Correct 2 ms 1408 KB Output is correct
18 Correct 1 ms 1280 KB Output is correct
19 Correct 1 ms 1152 KB Output is correct
20 Correct 2 ms 1152 KB Output is correct
21 Correct 1 ms 1280 KB Output is correct
22 Correct 1 ms 1152 KB Output is correct
23 Correct 1 ms 1280 KB Output is correct
24 Correct 2 ms 1408 KB Output is correct
25 Correct 2 ms 1408 KB Output is correct
26 Correct 1 ms 1152 KB Output is correct
27 Correct 2 ms 1152 KB Output is correct
28 Correct 2 ms 1536 KB Output is correct
29 Correct 2 ms 1536 KB Output is correct
30 Correct 1 ms 1152 KB Output is correct
31 Correct 2 ms 1408 KB Output is correct
32 Correct 1 ms 1280 KB Output is correct
33 Correct 4 ms 2048 KB Output is correct
34 Correct 4 ms 2048 KB Output is correct
35 Correct 20 ms 4736 KB Output is correct
36 Correct 5 ms 1792 KB Output is correct
37 Correct 17 ms 4480 KB Output is correct
38 Correct 24 ms 5632 KB Output is correct
39 Correct 24 ms 5624 KB Output is correct
40 Correct 24 ms 5632 KB Output is correct
41 Correct 25 ms 5540 KB Output is correct
42 Correct 6 ms 1408 KB Output is correct
43 Correct 7 ms 1536 KB Output is correct
44 Correct 8 ms 1536 KB Output is correct
45 Correct 34 ms 7680 KB Output is correct
46 Correct 28 ms 7680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1024 KB Output is correct
2 Correct 1 ms 1024 KB Output is correct
3 Correct 1 ms 1024 KB Output is correct
4 Correct 1 ms 1024 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 1 ms 1024 KB Output is correct
8 Correct 1 ms 1024 KB Output is correct
9 Correct 1 ms 1024 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 2 ms 1280 KB Output is correct
12 Correct 1 ms 1152 KB Output is correct
13 Correct 1 ms 1152 KB Output is correct
14 Correct 2 ms 1408 KB Output is correct
15 Correct 2 ms 1408 KB Output is correct
16 Correct 1 ms 1152 KB Output is correct
17 Correct 2 ms 1408 KB Output is correct
18 Correct 2 ms 1280 KB Output is correct
19 Correct 1 ms 1152 KB Output is correct
20 Correct 1 ms 1152 KB Output is correct
21 Correct 1 ms 1280 KB Output is correct
22 Correct 1 ms 1152 KB Output is correct
23 Correct 1 ms 1280 KB Output is correct
24 Correct 3 ms 1408 KB Output is correct
25 Correct 2 ms 1408 KB Output is correct
26 Correct 1 ms 1152 KB Output is correct
27 Correct 1 ms 1152 KB Output is correct
28 Correct 2 ms 1536 KB Output is correct
29 Correct 2 ms 1536 KB Output is correct
30 Correct 1 ms 1152 KB Output is correct
31 Correct 1 ms 1408 KB Output is correct
32 Correct 2 ms 1280 KB Output is correct
33 Correct 4 ms 2048 KB Output is correct
34 Correct 4 ms 2048 KB Output is correct
35 Correct 20 ms 4736 KB Output is correct
36 Correct 4 ms 1792 KB Output is correct
37 Correct 17 ms 4480 KB Output is correct
38 Correct 25 ms 5624 KB Output is correct
39 Correct 26 ms 5632 KB Output is correct
40 Correct 25 ms 5632 KB Output is correct
41 Correct 24 ms 5624 KB Output is correct
42 Correct 7 ms 1508 KB Output is correct
43 Correct 7 ms 1536 KB Output is correct
44 Correct 6 ms 1536 KB Output is correct
45 Correct 29 ms 7680 KB Output is correct
46 Correct 36 ms 7672 KB Output is correct
47 Correct 40 ms 8960 KB Output is correct
48 Correct 21 ms 5496 KB Output is correct
49 Correct 18 ms 4864 KB Output is correct
50 Correct 13 ms 4096 KB Output is correct
51 Correct 36 ms 7032 KB Output is correct
52 Correct 37 ms 7288 KB Output is correct
53 Correct 29 ms 5632 KB Output is correct
54 Correct 1 ms 1408 KB Output is correct
55 Correct 1 ms 1536 KB Output is correct
56 Correct 11 ms 2432 KB Output is correct
57 Correct 12 ms 4076 KB Output is correct
58 Correct 6 ms 1920 KB Output is correct
59 Correct 9 ms 2048 KB Output is correct
60 Correct 8 ms 2304 KB Output is correct
61 Correct 11 ms 2560 KB Output is correct
62 Correct 37 ms 8448 KB Output is correct
63 Correct 83 ms 19192 KB Output is correct
64 Correct 96 ms 22388 KB Output is correct
65 Correct 146 ms 30072 KB Output is correct
66 Correct 288 ms 49912 KB Output is correct
67 Correct 301 ms 50040 KB Output is correct