Submission #469947

# Submission time Handle Problem Language Result Execution time Memory
469947 2021-09-02T11:43:08 Z ymm Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
862 ms 262148 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 = 35000011;
struct mymap
{
    pii* bs = new pii[0];
    int v[mod] = {};
    unsigned char sz[mod] = {};

    int count(int x)
    {
        int y = x%mod;
        if(!sz[y]) return 0;
        Loop(i,0,sz[y])
            if((bs+v[y])[i].F==x)
                return 1;
        return 0;
    }

    int& operator[](int x)
    {
        int y = x%mod;
        if(!sz[y]) v[y] = (new pii[1])-bs, sz[y]=0;
        Loop(i,0,sz[y])
            if((bs+v[y])[i].F==x)
                return (bs+v[y])[i].S;
        if(sz[y] && (sz[y]&-sz[y]) == sz[y]){
            auto tmp = new pii[sz[y]*2];
            Loop(i,0,sz[y]) tmp[i] = (bs+v[y])[i];
            delete[](bs+v[y]);
            v[y] = tmp-bs;
        }
        (bs+v[y])[sz[y]++] = {x,0};
        if(sz[y] > 10) exit(0);
        return (bs+v[y])[sz[y]-1].S;
    }
};
mymap d;
vector<int> P[N];
bool vis[N];
int n, m;

void bfs(int sv, int sp)
{
    vector<int> q, q2;
    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 d = 0; q.size();)
    {
        for(ull i = 0; i < q.size(); ++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, q2.push_back(u<<15^p);
                }
                if(!::d.count(u<<15^p)) ::d[u<<15^p] = d+1, q2.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, q2.push_back(u<<15^p);
                }
                if(!::d.count(u<<15^p)) ::d[u<<15^p] = d+1, q2.push_back(u<<15^p);
            }
        }
        q = q2;
        q2.clear();
        ++d;
    }
}

bool isPrime(int n)
{
    for(int d = 2; d*d <= n; ++d)
        if(n%d == 0)
            return 0;
    return 1;
}

int main()
{
    //Loop(i,35000000,INT_MAX) if(isPrime(i)){cout << i;break;}
    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';
}
# Verdict Execution time Memory Grader output
1 Correct 72 ms 172204 KB Output is correct
2 Correct 72 ms 172132 KB Output is correct
3 Correct 72 ms 172112 KB Output is correct
4 Correct 74 ms 172180 KB Output is correct
5 Correct 72 ms 172228 KB Output is correct
6 Correct 73 ms 172228 KB Output is correct
7 Correct 73 ms 172172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 172228 KB Output is correct
2 Correct 73 ms 172136 KB Output is correct
3 Correct 72 ms 172232 KB Output is correct
4 Correct 72 ms 172228 KB Output is correct
5 Correct 73 ms 172212 KB Output is correct
6 Correct 72 ms 172160 KB Output is correct
7 Correct 73 ms 172228 KB Output is correct
8 Correct 71 ms 172200 KB Output is correct
9 Correct 75 ms 172124 KB Output is correct
10 Correct 73 ms 172244 KB Output is correct
11 Correct 76 ms 172356 KB Output is correct
12 Correct 72 ms 172248 KB Output is correct
13 Correct 81 ms 172256 KB Output is correct
14 Correct 72 ms 172356 KB Output is correct
15 Correct 87 ms 172384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 172188 KB Output is correct
2 Correct 74 ms 172228 KB Output is correct
3 Correct 76 ms 172192 KB Output is correct
4 Correct 71 ms 172124 KB Output is correct
5 Correct 70 ms 172128 KB Output is correct
6 Correct 76 ms 172228 KB Output is correct
7 Correct 72 ms 172232 KB Output is correct
8 Correct 73 ms 172204 KB Output is correct
9 Correct 72 ms 172124 KB Output is correct
10 Correct 75 ms 172268 KB Output is correct
11 Correct 73 ms 172316 KB Output is correct
12 Correct 72 ms 172228 KB Output is correct
13 Correct 75 ms 172172 KB Output is correct
14 Correct 74 ms 172424 KB Output is correct
15 Correct 74 ms 172392 KB Output is correct
16 Correct 73 ms 172128 KB Output is correct
17 Correct 78 ms 172624 KB Output is correct
18 Correct 73 ms 172204 KB Output is correct
19 Correct 79 ms 172228 KB Output is correct
20 Correct 74 ms 172340 KB Output is correct
21 Correct 72 ms 172148 KB Output is correct
22 Correct 72 ms 172168 KB Output is correct
23 Correct 83 ms 172484 KB Output is correct
24 Correct 73 ms 172632 KB Output is correct
25 Correct 75 ms 172460 KB Output is correct
26 Correct 74 ms 172416 KB Output is correct
27 Correct 75 ms 172408 KB Output is correct
28 Correct 81 ms 172952 KB Output is correct
29 Correct 84 ms 174156 KB Output is correct
30 Correct 82 ms 172740 KB Output is correct
31 Correct 79 ms 173228 KB Output is correct
32 Correct 78 ms 172908 KB Output is correct
33 Correct 100 ms 175924 KB Output is correct
34 Correct 100 ms 175984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 172228 KB Output is correct
2 Correct 72 ms 172172 KB Output is correct
3 Correct 75 ms 172228 KB Output is correct
4 Correct 76 ms 172156 KB Output is correct
5 Correct 72 ms 172176 KB Output is correct
6 Correct 75 ms 172216 KB Output is correct
7 Correct 74 ms 172172 KB Output is correct
8 Correct 72 ms 172144 KB Output is correct
9 Correct 80 ms 172224 KB Output is correct
10 Correct 72 ms 172192 KB Output is correct
11 Correct 74 ms 172316 KB Output is correct
12 Correct 74 ms 172220 KB Output is correct
13 Correct 72 ms 172152 KB Output is correct
14 Correct 74 ms 172444 KB Output is correct
15 Correct 76 ms 172356 KB Output is correct
16 Correct 73 ms 172252 KB Output is correct
17 Correct 76 ms 172688 KB Output is correct
18 Correct 73 ms 172232 KB Output is correct
19 Correct 73 ms 172168 KB Output is correct
20 Correct 73 ms 172328 KB Output is correct
21 Correct 74 ms 172220 KB Output is correct
22 Correct 73 ms 172240 KB Output is correct
23 Correct 77 ms 172364 KB Output is correct
24 Correct 75 ms 172680 KB Output is correct
25 Correct 79 ms 172396 KB Output is correct
26 Correct 76 ms 172420 KB Output is correct
27 Correct 75 ms 172352 KB Output is correct
28 Correct 80 ms 172924 KB Output is correct
29 Correct 87 ms 174140 KB Output is correct
30 Correct 77 ms 172740 KB Output is correct
31 Correct 82 ms 173200 KB Output is correct
32 Correct 81 ms 172964 KB Output is correct
33 Correct 103 ms 175940 KB Output is correct
34 Correct 102 ms 175972 KB Output is correct
35 Correct 104 ms 175772 KB Output is correct
36 Correct 78 ms 172804 KB Output is correct
37 Correct 122 ms 177908 KB Output is correct
38 Correct 122 ms 177680 KB Output is correct
39 Correct 122 ms 177644 KB Output is correct
40 Correct 118 ms 177592 KB Output is correct
41 Correct 120 ms 177652 KB Output is correct
42 Correct 77 ms 172484 KB Output is correct
43 Correct 81 ms 172568 KB Output is correct
44 Correct 79 ms 172460 KB Output is correct
45 Correct 187 ms 187652 KB Output is correct
46 Correct 197 ms 187724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 172188 KB Output is correct
2 Correct 70 ms 172188 KB Output is correct
3 Correct 73 ms 172132 KB Output is correct
4 Correct 75 ms 172144 KB Output is correct
5 Correct 71 ms 172220 KB Output is correct
6 Correct 72 ms 172144 KB Output is correct
7 Correct 72 ms 172228 KB Output is correct
8 Correct 75 ms 172228 KB Output is correct
9 Correct 72 ms 172148 KB Output is correct
10 Correct 83 ms 172228 KB Output is correct
11 Correct 74 ms 172356 KB Output is correct
12 Correct 71 ms 172240 KB Output is correct
13 Correct 72 ms 172164 KB Output is correct
14 Correct 77 ms 172396 KB Output is correct
15 Correct 73 ms 172460 KB Output is correct
16 Correct 74 ms 172228 KB Output is correct
17 Correct 77 ms 172720 KB Output is correct
18 Correct 73 ms 172232 KB Output is correct
19 Correct 73 ms 172196 KB Output is correct
20 Correct 74 ms 172264 KB Output is correct
21 Correct 74 ms 172228 KB Output is correct
22 Correct 73 ms 172452 KB Output is correct
23 Correct 76 ms 172464 KB Output is correct
24 Correct 76 ms 172672 KB Output is correct
25 Correct 75 ms 172484 KB Output is correct
26 Correct 74 ms 172444 KB Output is correct
27 Correct 83 ms 172420 KB Output is correct
28 Correct 79 ms 172996 KB Output is correct
29 Correct 87 ms 174092 KB Output is correct
30 Correct 76 ms 172692 KB Output is correct
31 Correct 84 ms 173252 KB Output is correct
32 Correct 78 ms 172992 KB Output is correct
33 Correct 105 ms 176088 KB Output is correct
34 Correct 100 ms 176092 KB Output is correct
35 Correct 104 ms 175684 KB Output is correct
36 Correct 78 ms 172824 KB Output is correct
37 Correct 122 ms 177960 KB Output is correct
38 Correct 123 ms 177600 KB Output is correct
39 Correct 119 ms 177664 KB Output is correct
40 Correct 120 ms 177624 KB Output is correct
41 Correct 118 ms 177604 KB Output is correct
42 Correct 79 ms 172524 KB Output is correct
43 Correct 79 ms 172484 KB Output is correct
44 Correct 77 ms 172456 KB Output is correct
45 Correct 174 ms 187680 KB Output is correct
46 Correct 186 ms 187736 KB Output is correct
47 Correct 286 ms 195996 KB Output is correct
48 Correct 85 ms 172612 KB Output is correct
49 Correct 87 ms 172612 KB Output is correct
50 Correct 80 ms 172500 KB Output is correct
51 Correct 168 ms 182784 KB Output is correct
52 Correct 177 ms 183624 KB Output is correct
53 Correct 110 ms 175664 KB Output is correct
54 Correct 78 ms 172724 KB Output is correct
55 Correct 79 ms 172996 KB Output is correct
56 Correct 91 ms 174064 KB Output is correct
57 Correct 192 ms 185784 KB Output is correct
58 Correct 96 ms 174404 KB Output is correct
59 Correct 102 ms 175312 KB Output is correct
60 Correct 110 ms 176284 KB Output is correct
61 Correct 110 ms 175684 KB Output is correct
62 Correct 213 ms 188452 KB Output is correct
63 Correct 713 ms 243300 KB Output is correct
64 Correct 840 ms 259540 KB Output is correct
65 Runtime error 862 ms 262148 KB Execution killed with signal 9
66 Halted 0 ms 0 KB -