답안 #469944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469944 2021-09-02T11:34:45 Z ymm Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
326 ms 158784 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 = 25000009;
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};
        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;
    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)
    {
        if(q.size() > 1'000'000) exit(0);
        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);
        }
    }
}

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

int main()
{
    //Loop(i,25000000,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';
}

Compilation message

skyscraper.cpp: In function 'void bfs(int, int)':
skyscraper.cpp:67:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i = 0, j = q.size(), d = 0; i < q.size(); j = q.size(), ++d) for(; i < j; ++i)
      |                                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 123228 KB Output is correct
2 Correct 58 ms 123228 KB Output is correct
3 Correct 52 ms 123204 KB Output is correct
4 Correct 56 ms 123228 KB Output is correct
5 Correct 55 ms 123208 KB Output is correct
6 Correct 53 ms 123244 KB Output is correct
7 Correct 54 ms 123204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 123204 KB Output is correct
2 Correct 54 ms 123244 KB Output is correct
3 Correct 57 ms 123320 KB Output is correct
4 Correct 55 ms 123184 KB Output is correct
5 Correct 55 ms 123184 KB Output is correct
6 Correct 53 ms 123200 KB Output is correct
7 Correct 51 ms 123212 KB Output is correct
8 Correct 52 ms 123276 KB Output is correct
9 Correct 54 ms 123312 KB Output is correct
10 Correct 66 ms 123332 KB Output is correct
11 Correct 53 ms 123472 KB Output is correct
12 Correct 52 ms 123268 KB Output is correct
13 Correct 53 ms 123292 KB Output is correct
14 Correct 52 ms 123488 KB Output is correct
15 Correct 53 ms 123452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 123200 KB Output is correct
2 Correct 54 ms 123332 KB Output is correct
3 Correct 57 ms 123252 KB Output is correct
4 Correct 53 ms 123284 KB Output is correct
5 Correct 54 ms 123228 KB Output is correct
6 Correct 54 ms 123296 KB Output is correct
7 Correct 52 ms 123204 KB Output is correct
8 Correct 52 ms 123272 KB Output is correct
9 Correct 53 ms 123208 KB Output is correct
10 Correct 53 ms 123388 KB Output is correct
11 Correct 53 ms 123460 KB Output is correct
12 Correct 55 ms 123332 KB Output is correct
13 Correct 52 ms 123276 KB Output is correct
14 Correct 54 ms 123424 KB Output is correct
15 Correct 54 ms 123508 KB Output is correct
16 Correct 53 ms 123284 KB Output is correct
17 Correct 57 ms 123820 KB Output is correct
18 Correct 54 ms 123344 KB Output is correct
19 Correct 53 ms 123220 KB Output is correct
20 Correct 55 ms 123332 KB Output is correct
21 Correct 55 ms 123204 KB Output is correct
22 Correct 53 ms 123204 KB Output is correct
23 Correct 53 ms 123460 KB Output is correct
24 Correct 55 ms 123716 KB Output is correct
25 Correct 54 ms 123588 KB Output is correct
26 Correct 55 ms 123596 KB Output is correct
27 Correct 58 ms 123452 KB Output is correct
28 Correct 58 ms 124080 KB Output is correct
29 Correct 65 ms 125388 KB Output is correct
30 Correct 56 ms 123904 KB Output is correct
31 Correct 63 ms 124532 KB Output is correct
32 Correct 60 ms 124108 KB Output is correct
33 Correct 81 ms 127448 KB Output is correct
34 Correct 81 ms 127600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 123196 KB Output is correct
2 Correct 60 ms 123284 KB Output is correct
3 Correct 52 ms 123252 KB Output is correct
4 Correct 54 ms 123256 KB Output is correct
5 Correct 55 ms 123264 KB Output is correct
6 Correct 54 ms 123208 KB Output is correct
7 Correct 53 ms 123332 KB Output is correct
8 Correct 55 ms 123276 KB Output is correct
9 Correct 56 ms 123204 KB Output is correct
10 Correct 55 ms 123316 KB Output is correct
11 Correct 55 ms 123384 KB Output is correct
12 Correct 53 ms 123308 KB Output is correct
13 Correct 52 ms 123332 KB Output is correct
14 Correct 62 ms 123452 KB Output is correct
15 Correct 53 ms 123504 KB Output is correct
16 Correct 53 ms 123228 KB Output is correct
17 Correct 57 ms 123800 KB Output is correct
18 Correct 52 ms 123232 KB Output is correct
19 Correct 54 ms 123204 KB Output is correct
20 Correct 54 ms 123436 KB Output is correct
21 Correct 53 ms 123244 KB Output is correct
22 Correct 52 ms 123340 KB Output is correct
23 Correct 56 ms 123556 KB Output is correct
24 Correct 56 ms 123720 KB Output is correct
25 Correct 55 ms 123584 KB Output is correct
26 Correct 57 ms 123588 KB Output is correct
27 Correct 57 ms 123528 KB Output is correct
28 Correct 58 ms 124100 KB Output is correct
29 Correct 68 ms 125380 KB Output is correct
30 Correct 55 ms 123968 KB Output is correct
31 Correct 63 ms 124624 KB Output is correct
32 Correct 59 ms 124052 KB Output is correct
33 Correct 79 ms 127544 KB Output is correct
34 Correct 79 ms 127552 KB Output is correct
35 Correct 90 ms 127056 KB Output is correct
36 Correct 59 ms 123996 KB Output is correct
37 Correct 107 ms 129456 KB Output is correct
38 Correct 100 ms 129180 KB Output is correct
39 Correct 102 ms 129080 KB Output is correct
40 Correct 101 ms 129176 KB Output is correct
41 Correct 100 ms 129168 KB Output is correct
42 Correct 59 ms 123588 KB Output is correct
43 Correct 60 ms 123584 KB Output is correct
44 Correct 60 ms 123544 KB Output is correct
45 Correct 152 ms 140352 KB Output is correct
46 Correct 157 ms 140512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 123280 KB Output is correct
2 Correct 53 ms 123204 KB Output is correct
3 Correct 55 ms 123196 KB Output is correct
4 Correct 52 ms 123268 KB Output is correct
5 Correct 51 ms 123244 KB Output is correct
6 Correct 55 ms 123204 KB Output is correct
7 Correct 52 ms 123248 KB Output is correct
8 Correct 52 ms 123216 KB Output is correct
9 Correct 56 ms 123320 KB Output is correct
10 Correct 53 ms 123332 KB Output is correct
11 Correct 55 ms 123472 KB Output is correct
12 Correct 57 ms 123236 KB Output is correct
13 Correct 54 ms 123328 KB Output is correct
14 Correct 53 ms 123464 KB Output is correct
15 Correct 53 ms 123488 KB Output is correct
16 Correct 53 ms 123208 KB Output is correct
17 Correct 55 ms 123804 KB Output is correct
18 Correct 61 ms 123332 KB Output is correct
19 Correct 55 ms 123296 KB Output is correct
20 Correct 54 ms 123460 KB Output is correct
21 Correct 52 ms 123296 KB Output is correct
22 Correct 52 ms 123324 KB Output is correct
23 Correct 55 ms 123460 KB Output is correct
24 Correct 55 ms 123756 KB Output is correct
25 Correct 61 ms 123576 KB Output is correct
26 Correct 57 ms 123588 KB Output is correct
27 Correct 60 ms 123476 KB Output is correct
28 Correct 59 ms 124108 KB Output is correct
29 Correct 68 ms 125428 KB Output is correct
30 Correct 57 ms 123956 KB Output is correct
31 Correct 60 ms 124620 KB Output is correct
32 Correct 60 ms 124096 KB Output is correct
33 Correct 79 ms 127516 KB Output is correct
34 Correct 87 ms 127544 KB Output is correct
35 Correct 82 ms 127040 KB Output is correct
36 Correct 62 ms 123980 KB Output is correct
37 Correct 99 ms 129464 KB Output is correct
38 Correct 117 ms 129132 KB Output is correct
39 Correct 104 ms 129116 KB Output is correct
40 Correct 99 ms 129076 KB Output is correct
41 Correct 101 ms 129060 KB Output is correct
42 Correct 60 ms 123608 KB Output is correct
43 Correct 70 ms 123588 KB Output is correct
44 Correct 63 ms 123444 KB Output is correct
45 Correct 159 ms 140440 KB Output is correct
46 Correct 154 ms 140412 KB Output is correct
47 Correct 272 ms 149416 KB Output is correct
48 Correct 59 ms 123712 KB Output is correct
49 Correct 58 ms 123676 KB Output is correct
50 Correct 57 ms 123588 KB Output is correct
51 Correct 156 ms 134972 KB Output is correct
52 Correct 158 ms 136084 KB Output is correct
53 Correct 89 ms 127036 KB Output is correct
54 Correct 59 ms 123776 KB Output is correct
55 Correct 67 ms 124108 KB Output is correct
56 Correct 78 ms 125424 KB Output is correct
57 Correct 193 ms 138544 KB Output is correct
58 Correct 76 ms 126008 KB Output is correct
59 Correct 95 ms 126852 KB Output is correct
60 Correct 97 ms 127788 KB Output is correct
61 Correct 102 ms 127320 KB Output is correct
62 Correct 198 ms 141360 KB Output is correct
63 Incorrect 326 ms 158784 KB Output isn't correct
64 Halted 0 ms 0 KB -