답안 #56868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
56868 2018-07-13T01:08:18 Z Benq Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
741 ms 123684 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 30001;

int N,M, st, en;
bitset<MX> oc[MX], visit;
vi sky[MX];

queue<array<int,3>> q;

void tri(int x, array<int,3> y) {
    if (x < 0 || x >= N) return;
    if (oc[x][y[2]]) return;
    oc[x][y[2]] = 1;
    q.push({y[0]+1,x,y[2]});
    
    if (!visit[x]) {
        for (int i: sky[x]) q.push({y[0]+1,x,i});
        visit[x] = 1;
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    F0R(i,M) {
        int B,P; cin >> B >> P;
        sky[B].pb(P);
        if (i == 0) st = B;
        if (i == 1) en = B;
    }
    for (int i: sky[st]) {
        oc[st][i] = 1;
        q.push({0,st,i});
    }
    while (sz(q)) {
        auto a = q.front(); q.pop();
        if (a[1] == en) {
            cout << a[0];
            exit(0);
        }
        tri(a[1]-a[2],a);
        tri(a[1]+a[2],a);
    }
    cout << -1;
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 2 ms 1268 KB Output is correct
3 Correct 3 ms 1268 KB Output is correct
4 Correct 4 ms 1268 KB Output is correct
5 Correct 5 ms 1616 KB Output is correct
6 Correct 4 ms 1616 KB Output is correct
7 Correct 3 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1616 KB Output is correct
2 Correct 4 ms 1680 KB Output is correct
3 Correct 4 ms 1680 KB Output is correct
4 Correct 3 ms 1680 KB Output is correct
5 Correct 3 ms 1820 KB Output is correct
6 Correct 4 ms 1820 KB Output is correct
7 Correct 3 ms 1820 KB Output is correct
8 Correct 3 ms 1820 KB Output is correct
9 Correct 3 ms 1820 KB Output is correct
10 Correct 3 ms 1900 KB Output is correct
11 Correct 4 ms 2032 KB Output is correct
12 Correct 4 ms 2044 KB Output is correct
13 Correct 4 ms 2200 KB Output is correct
14 Correct 5 ms 2228 KB Output is correct
15 Correct 5 ms 2256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2256 KB Output is correct
2 Correct 3 ms 2256 KB Output is correct
3 Correct 3 ms 2256 KB Output is correct
4 Correct 4 ms 2256 KB Output is correct
5 Correct 3 ms 2256 KB Output is correct
6 Correct 4 ms 2256 KB Output is correct
7 Correct 2 ms 2256 KB Output is correct
8 Correct 4 ms 2256 KB Output is correct
9 Correct 4 ms 2256 KB Output is correct
10 Correct 4 ms 2256 KB Output is correct
11 Correct 3 ms 2264 KB Output is correct
12 Correct 3 ms 2268 KB Output is correct
13 Correct 14 ms 2280 KB Output is correct
14 Correct 6 ms 2300 KB Output is correct
15 Correct 5 ms 2436 KB Output is correct
16 Correct 4 ms 2436 KB Output is correct
17 Correct 8 ms 4768 KB Output is correct
18 Correct 4 ms 4768 KB Output is correct
19 Correct 4 ms 4768 KB Output is correct
20 Correct 13 ms 9400 KB Output is correct
21 Correct 3 ms 9400 KB Output is correct
22 Correct 4 ms 9400 KB Output is correct
23 Correct 10 ms 9400 KB Output is correct
24 Correct 15 ms 9400 KB Output is correct
25 Correct 7 ms 9400 KB Output is correct
26 Correct 11 ms 9400 KB Output is correct
27 Correct 13 ms 9400 KB Output is correct
28 Correct 14 ms 9520 KB Output is correct
29 Correct 15 ms 9540 KB Output is correct
30 Correct 13 ms 9540 KB Output is correct
31 Correct 16 ms 9552 KB Output is correct
32 Correct 16 ms 9552 KB Output is correct
33 Correct 22 ms 9560 KB Output is correct
34 Correct 14 ms 9576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9576 KB Output is correct
2 Correct 3 ms 9576 KB Output is correct
3 Correct 3 ms 9576 KB Output is correct
4 Correct 2 ms 9576 KB Output is correct
5 Correct 3 ms 9576 KB Output is correct
6 Correct 3 ms 9576 KB Output is correct
7 Correct 3 ms 9576 KB Output is correct
8 Correct 3 ms 9576 KB Output is correct
9 Correct 3 ms 9576 KB Output is correct
10 Correct 5 ms 9576 KB Output is correct
11 Correct 4 ms 9576 KB Output is correct
12 Correct 3 ms 9576 KB Output is correct
13 Correct 3 ms 9576 KB Output is correct
14 Correct 3 ms 9576 KB Output is correct
15 Correct 3 ms 9576 KB Output is correct
16 Correct 4 ms 9576 KB Output is correct
17 Correct 8 ms 9576 KB Output is correct
18 Correct 4 ms 9576 KB Output is correct
19 Correct 3 ms 9576 KB Output is correct
20 Correct 12 ms 9892 KB Output is correct
21 Correct 4 ms 9892 KB Output is correct
22 Correct 3 ms 9892 KB Output is correct
23 Correct 10 ms 9892 KB Output is correct
24 Correct 12 ms 9892 KB Output is correct
25 Correct 5 ms 9892 KB Output is correct
26 Correct 11 ms 9892 KB Output is correct
27 Correct 12 ms 9892 KB Output is correct
28 Correct 16 ms 9892 KB Output is correct
29 Correct 17 ms 9908 KB Output is correct
30 Correct 15 ms 9916 KB Output is correct
31 Correct 14 ms 9920 KB Output is correct
32 Correct 13 ms 9924 KB Output is correct
33 Correct 18 ms 10056 KB Output is correct
34 Correct 15 ms 10056 KB Output is correct
35 Correct 24 ms 10056 KB Output is correct
36 Correct 8 ms 10056 KB Output is correct
37 Correct 16 ms 10588 KB Output is correct
38 Correct 28 ms 11172 KB Output is correct
39 Correct 12 ms 11172 KB Output is correct
40 Correct 15 ms 11172 KB Output is correct
41 Correct 18 ms 11292 KB Output is correct
42 Correct 20 ms 11292 KB Output is correct
43 Correct 17 ms 11636 KB Output is correct
44 Correct 19 ms 12564 KB Output is correct
45 Correct 32 ms 13072 KB Output is correct
46 Correct 23 ms 13292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 13292 KB Output is correct
2 Correct 4 ms 13292 KB Output is correct
3 Correct 2 ms 13292 KB Output is correct
4 Correct 2 ms 13292 KB Output is correct
5 Correct 4 ms 13292 KB Output is correct
6 Correct 4 ms 13292 KB Output is correct
7 Correct 3 ms 13292 KB Output is correct
8 Correct 3 ms 13292 KB Output is correct
9 Correct 4 ms 13292 KB Output is correct
10 Correct 5 ms 13292 KB Output is correct
11 Correct 4 ms 13292 KB Output is correct
12 Correct 4 ms 13292 KB Output is correct
13 Correct 5 ms 13292 KB Output is correct
14 Correct 5 ms 13292 KB Output is correct
15 Correct 5 ms 13292 KB Output is correct
16 Correct 4 ms 13292 KB Output is correct
17 Correct 8 ms 13292 KB Output is correct
18 Correct 4 ms 13292 KB Output is correct
19 Correct 4 ms 13292 KB Output is correct
20 Correct 14 ms 13292 KB Output is correct
21 Correct 3 ms 13292 KB Output is correct
22 Correct 3 ms 13292 KB Output is correct
23 Correct 9 ms 13292 KB Output is correct
24 Correct 12 ms 13292 KB Output is correct
25 Correct 6 ms 13292 KB Output is correct
26 Correct 11 ms 13292 KB Output is correct
27 Correct 13 ms 13292 KB Output is correct
28 Correct 16 ms 13292 KB Output is correct
29 Correct 15 ms 13292 KB Output is correct
30 Correct 12 ms 13292 KB Output is correct
31 Correct 14 ms 13292 KB Output is correct
32 Correct 14 ms 13292 KB Output is correct
33 Correct 19 ms 13292 KB Output is correct
34 Correct 16 ms 13292 KB Output is correct
35 Correct 18 ms 13292 KB Output is correct
36 Correct 9 ms 13292 KB Output is correct
37 Correct 23 ms 13600 KB Output is correct
38 Correct 25 ms 14188 KB Output is correct
39 Correct 14 ms 14188 KB Output is correct
40 Correct 18 ms 14188 KB Output is correct
41 Correct 20 ms 14324 KB Output is correct
42 Correct 20 ms 14324 KB Output is correct
43 Correct 18 ms 14592 KB Output is correct
44 Correct 19 ms 15444 KB Output is correct
45 Correct 37 ms 16032 KB Output is correct
46 Correct 27 ms 16244 KB Output is correct
47 Correct 61 ms 38952 KB Output is correct
48 Correct 13 ms 38952 KB Output is correct
49 Correct 11 ms 38952 KB Output is correct
50 Correct 12 ms 38952 KB Output is correct
51 Correct 133 ms 91504 KB Output is correct
52 Correct 148 ms 99432 KB Output is correct
53 Correct 39 ms 99432 KB Output is correct
54 Correct 74 ms 99432 KB Output is correct
55 Correct 87 ms 99432 KB Output is correct
56 Correct 144 ms 121320 KB Output is correct
57 Correct 6 ms 121320 KB Output is correct
58 Correct 141 ms 121320 KB Output is correct
59 Correct 133 ms 121320 KB Output is correct
60 Correct 151 ms 121320 KB Output is correct
61 Correct 139 ms 121320 KB Output is correct
62 Correct 196 ms 122480 KB Output is correct
63 Correct 336 ms 122480 KB Output is correct
64 Correct 416 ms 122696 KB Output is correct
65 Correct 553 ms 122848 KB Output is correct
66 Correct 741 ms 123344 KB Output is correct
67 Correct 506 ms 123684 KB Output is correct