Submission #469931

# Submission time Handle Problem Language Result Execution time Memory
469931 2021-09-02T11:03:12 Z ymm Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 232316 KB
///
///   ♪ Pizza mozzarella rella rella rella... ♪
///

#define _USE_MATH_DEFINES
#define FAST ios::sync_with_stdio(false),cin.tie(0);
#include <bits/stdc++.h>
#define Loop(x, l, r) for(int x = (l); x < (r); ++x)
#define LoopR(x, l, r) for(int x = (r)-1; x >= (l); --x)
#define all(x) x.begin(), x.end()
#define Kill(x) exit((cout << (x) << '\n', 0))
#define YN(flag) ((flag)? "YES": "NO")
#define F first
#define S second
typedef          long long   ll;
typedef unsigned long long  ull;
typedef std::pair<int,int>  pii;
typedef std::pair<ll ,ll >  pll;
using namespace std;

const int N = 30'010;
const int mod = 6000011;
struct mymap
{
    vector<pii> v[mod];

    int count(int x)
    {
        int y = x%mod;
        for(auto& [a, b] : v[y])
            if(a==x)
                return 1;
        return 0;
    }

    int& operator[](int x)
    {
        int y = x%mod;
        for(auto& [a, b] : v[y])
            if(a==x)
                return b;
        v[y].emplace_back(x,0);
        return v[y].back().S;
    }
};
mymap d;
vector<int> P[N];
bool vis[N];
int n, m;

void bfs(int sv, int sp)
{
    vector<int> q;
    vis[sv] = 1;
    for(auto p : P[sv]) if(!d.count(sv<<15^p)) d[sv<<15^p] = 0, q.push_back(sv<<15^p);
    if(!d.count(sv<<15^sp)) d[sv<<15^sp] = 0, q.push_back(sv<<15^sp);
    for(int i = 0, j = q.size(), d = 0; i < q.size(); j = q.size(), ++d) for(; i < j; ++i)
    {
        int v = q[i]>>15, p = q[i]&32767;
        //cerr << v << ' ' << p << ": " << d << '\n';
        int u = v+p;
        if(0 <= u && u < n)
        {
            if(!vis[u]){
                vis[u] = 1;
                for(auto p : P[u]) if(!::d.count(u<<15^p)) ::d[u<<15^p] = d+1, q.push_back(u<<15^p);
            }
            if(!::d.count(u<<15^p)) ::d[u<<15^p] = d+1, q.push_back(u<<15^p);
        }
        u = v-p;
        if(0 <= u && u < n)
        {
            if(!vis[u]){
                vis[u] = 1;
                for(auto p : P[u]) if(!::d.count(u<<15^p)) ::d[u<<15^p] = d+1, q.push_back(u<<15^p);
            }
            if(!::d.count(u<<15^p)) ::d[u<<15^p] = d+1, q.push_back(u<<15^p);
        }
    }
}

int main()
{
    FAST;
    cin >> n >> m;
    int p, src, des, dmy;
    cin >> src >> p;
    cin >> des >> dmy;
    P[des].push_back(dmy);
    Loop(i,2,m)
    {
        int v, p;
        cin >> v >> p;
        P[v].push_back(p);
    }
    bfs(src, p);
    cout << (d.count(des<<15^dmy)? d[des<<15^dmy]: -1) << '\n';
}

Compilation message

skyscraper.cpp: In function 'void bfs(int, int)':
skyscraper.cpp:57:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(int i = 0, j = q.size(), d = 0; i < q.size(); j = q.size(), ++d) for(; i < j; ++i)
      |                                         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 75 ms 141872 KB Output is correct
2 Correct 77 ms 141900 KB Output is correct
3 Correct 78 ms 141936 KB Output is correct
4 Correct 75 ms 142016 KB Output is correct
5 Correct 75 ms 141868 KB Output is correct
6 Correct 75 ms 141884 KB Output is correct
7 Correct 78 ms 141828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 141944 KB Output is correct
2 Correct 78 ms 141864 KB Output is correct
3 Correct 77 ms 141892 KB Output is correct
4 Correct 76 ms 141784 KB Output is correct
5 Correct 75 ms 141804 KB Output is correct
6 Correct 76 ms 142000 KB Output is correct
7 Correct 80 ms 141892 KB Output is correct
8 Correct 78 ms 141784 KB Output is correct
9 Correct 78 ms 141880 KB Output is correct
10 Correct 77 ms 141892 KB Output is correct
11 Correct 77 ms 142004 KB Output is correct
12 Correct 75 ms 141892 KB Output is correct
13 Correct 77 ms 141940 KB Output is correct
14 Correct 79 ms 142020 KB Output is correct
15 Correct 78 ms 142028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 141904 KB Output is correct
2 Correct 78 ms 141968 KB Output is correct
3 Correct 78 ms 141800 KB Output is correct
4 Correct 77 ms 141824 KB Output is correct
5 Correct 76 ms 141896 KB Output is correct
6 Correct 78 ms 141848 KB Output is correct
7 Correct 78 ms 141868 KB Output is correct
8 Correct 78 ms 141904 KB Output is correct
9 Correct 77 ms 141892 KB Output is correct
10 Correct 77 ms 141848 KB Output is correct
11 Correct 77 ms 142072 KB Output is correct
12 Correct 79 ms 141848 KB Output is correct
13 Correct 78 ms 141892 KB Output is correct
14 Correct 79 ms 142088 KB Output is correct
15 Correct 79 ms 142032 KB Output is correct
16 Correct 76 ms 141840 KB Output is correct
17 Correct 82 ms 142344 KB Output is correct
18 Correct 77 ms 141904 KB Output is correct
19 Correct 77 ms 141804 KB Output is correct
20 Correct 78 ms 141988 KB Output is correct
21 Correct 78 ms 141980 KB Output is correct
22 Correct 76 ms 141888 KB Output is correct
23 Correct 79 ms 142096 KB Output is correct
24 Correct 82 ms 142288 KB Output is correct
25 Correct 78 ms 142172 KB Output is correct
26 Correct 80 ms 142088 KB Output is correct
27 Correct 84 ms 142088 KB Output is correct
28 Correct 83 ms 142668 KB Output is correct
29 Correct 91 ms 143976 KB Output is correct
30 Correct 81 ms 142440 KB Output is correct
31 Correct 84 ms 143192 KB Output is correct
32 Correct 82 ms 142684 KB Output is correct
33 Correct 103 ms 146076 KB Output is correct
34 Correct 106 ms 146080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 141904 KB Output is correct
2 Correct 80 ms 141892 KB Output is correct
3 Correct 76 ms 141856 KB Output is correct
4 Correct 77 ms 141892 KB Output is correct
5 Correct 77 ms 141788 KB Output is correct
6 Correct 75 ms 141900 KB Output is correct
7 Correct 76 ms 141808 KB Output is correct
8 Correct 78 ms 141892 KB Output is correct
9 Correct 78 ms 142020 KB Output is correct
10 Correct 77 ms 141920 KB Output is correct
11 Correct 77 ms 142060 KB Output is correct
12 Correct 82 ms 142020 KB Output is correct
13 Correct 76 ms 141940 KB Output is correct
14 Correct 79 ms 142076 KB Output is correct
15 Correct 78 ms 142136 KB Output is correct
16 Correct 77 ms 141804 KB Output is correct
17 Correct 79 ms 142508 KB Output is correct
18 Correct 76 ms 142000 KB Output is correct
19 Correct 76 ms 141820 KB Output is correct
20 Correct 76 ms 141952 KB Output is correct
21 Correct 79 ms 142020 KB Output is correct
22 Correct 79 ms 141920 KB Output is correct
23 Correct 78 ms 142148 KB Output is correct
24 Correct 80 ms 142304 KB Output is correct
25 Correct 79 ms 142208 KB Output is correct
26 Correct 80 ms 142148 KB Output is correct
27 Correct 80 ms 142156 KB Output is correct
28 Correct 84 ms 142736 KB Output is correct
29 Correct 94 ms 144016 KB Output is correct
30 Correct 82 ms 142524 KB Output is correct
31 Correct 86 ms 143168 KB Output is correct
32 Correct 86 ms 142780 KB Output is correct
33 Correct 105 ms 146096 KB Output is correct
34 Correct 108 ms 146144 KB Output is correct
35 Correct 127 ms 145612 KB Output is correct
36 Correct 84 ms 142548 KB Output is correct
37 Correct 131 ms 148052 KB Output is correct
38 Correct 129 ms 147668 KB Output is correct
39 Correct 130 ms 147760 KB Output is correct
40 Correct 131 ms 147672 KB Output is correct
41 Correct 125 ms 147768 KB Output is correct
42 Correct 86 ms 142188 KB Output is correct
43 Correct 86 ms 142240 KB Output is correct
44 Correct 83 ms 142068 KB Output is correct
45 Correct 189 ms 158960 KB Output is correct
46 Correct 203 ms 159024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 141828 KB Output is correct
2 Correct 77 ms 141892 KB Output is correct
3 Correct 78 ms 141944 KB Output is correct
4 Correct 75 ms 141892 KB Output is correct
5 Correct 78 ms 141860 KB Output is correct
6 Correct 77 ms 141892 KB Output is correct
7 Correct 76 ms 141832 KB Output is correct
8 Correct 76 ms 141912 KB Output is correct
9 Correct 77 ms 141848 KB Output is correct
10 Correct 78 ms 141892 KB Output is correct
11 Correct 80 ms 142132 KB Output is correct
12 Correct 76 ms 141892 KB Output is correct
13 Correct 80 ms 141892 KB Output is correct
14 Correct 77 ms 142080 KB Output is correct
15 Correct 77 ms 142020 KB Output is correct
16 Correct 76 ms 141816 KB Output is correct
17 Correct 81 ms 142372 KB Output is correct
18 Correct 76 ms 141824 KB Output is correct
19 Correct 76 ms 141828 KB Output is correct
20 Correct 77 ms 141960 KB Output is correct
21 Correct 79 ms 141876 KB Output is correct
22 Correct 78 ms 141972 KB Output is correct
23 Correct 79 ms 142224 KB Output is correct
24 Correct 81 ms 142360 KB Output is correct
25 Correct 80 ms 142216 KB Output is correct
26 Correct 79 ms 142160 KB Output is correct
27 Correct 78 ms 142148 KB Output is correct
28 Correct 90 ms 142704 KB Output is correct
29 Correct 93 ms 143972 KB Output is correct
30 Correct 89 ms 142476 KB Output is correct
31 Correct 85 ms 143172 KB Output is correct
32 Correct 82 ms 142628 KB Output is correct
33 Correct 113 ms 146108 KB Output is correct
34 Correct 107 ms 146120 KB Output is correct
35 Correct 111 ms 145660 KB Output is correct
36 Correct 87 ms 142532 KB Output is correct
37 Correct 137 ms 148020 KB Output is correct
38 Correct 128 ms 147712 KB Output is correct
39 Correct 128 ms 147768 KB Output is correct
40 Correct 127 ms 147700 KB Output is correct
41 Correct 130 ms 147728 KB Output is correct
42 Correct 84 ms 142196 KB Output is correct
43 Correct 84 ms 142228 KB Output is correct
44 Correct 83 ms 142148 KB Output is correct
45 Correct 194 ms 159024 KB Output is correct
46 Correct 203 ms 159028 KB Output is correct
47 Correct 324 ms 167336 KB Output is correct
48 Correct 82 ms 142364 KB Output is correct
49 Correct 85 ms 142360 KB Output is correct
50 Correct 83 ms 142164 KB Output is correct
51 Correct 181 ms 153464 KB Output is correct
52 Correct 196 ms 154456 KB Output is correct
53 Correct 112 ms 145596 KB Output is correct
54 Correct 85 ms 142516 KB Output is correct
55 Correct 82 ms 142716 KB Output is correct
56 Correct 92 ms 143820 KB Output is correct
57 Correct 206 ms 157148 KB Output is correct
58 Correct 100 ms 144576 KB Output is correct
59 Correct 109 ms 145420 KB Output is correct
60 Correct 114 ms 146368 KB Output is correct
61 Correct 124 ms 145852 KB Output is correct
62 Correct 231 ms 159812 KB Output is correct
63 Correct 864 ms 217652 KB Output is correct
64 Execution timed out 1016 ms 232316 KB Time limit exceeded
65 Halted 0 ms 0 KB -