Submission #317776

# Submission time Handle Problem Language Result Execution time Memory
317776 2020-10-30T11:15:36 Z Return_0 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
946 ms 3828 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("O2,unroll-loops")
// #pragma GCC target ("avx,avx2,fma")

using namespace std;
using namespace __gnu_pbds;

typedef int ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#ifdef LOCAL
#define dbg(x) cout<< #x << " : " << x << endl
#define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1);
#else
#define dbg(x) 0
#define dbg2(x, j, n) 0
#endif
#define SZ(x) ((ll)((x).size()))
#define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout);
#define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i];
#define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n');
#define kill(x) return cout<< x << endl, 0
#define cl const ll
#define fr first
#define sc second
#define mid ((l + r) / 2)
#define All(x) (x).begin(), (x).end()

const long long inf = 1e18;
cl mod = 1e9 + 7, MOD = 998244353;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
    return out << '(' << a.first << ", " << a.second << ')';    }
template <class A> ostream& operator << (ostream& out, const vector<A> &a) {
    if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']';  }
template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>;

cl N = 3e4 + 7;

ll dis [N], pos [N], p [N];
priority_queue <pll> pq;
bool mark [N];
vector <ll> vec [N];

int main ()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    memset(dis, 61, sizeof dis);

    ll n, m, i, j, k, v;

    cin>> n >> m;

    for (i = 0; i < m; i++) {
        cin>> pos[i] >> p[i];
        vec[pos[i]].push_back(p[i]);
    }

    dis[pos[0]] = 0;
    pq.push({0, pos[0]});

    while (!pq.empty()) {
        v = pq.top().sc, pq.pop();

        if (mark[v])    continue;
        mark[v] = true;
        
        for (ll p : vec[v]) {
            for (i = v, j = 0; i < n; i += p, j++)  if (dis[v] + j < dis[i])    dis[i] = dis[v] + j, pq.push({-dis[i], i});
            for (i = v, j = 0; i >= 0; i -= p, j++)  if (dis[v] + j < dis[i])    dis[i] = dis[v] + j, pq.push({-dis[i], i});
        }
    }

    if (dis[pos[1]] > mod)   kill(-1);

    cout<< dis[pos[1]] << endl;

    // cerr<< "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}
/*
5 3
0 2
1 1
4 1

*/

Compilation message

skyscraper.cpp: In function 'std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)':
skyscraper.cpp:40:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   40 |     if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']';  }
      |     ^~
skyscraper.cpp:40:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   40 |     if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']';  }
      |                                    ^~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:56:20: warning: unused variable 'k' [-Wunused-variable]
   56 |     ll n, m, i, j, k, v;
      |                    ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1152 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 1 ms 1152 KB Output is correct
12 Correct 1 ms 1152 KB Output is correct
13 Correct 1 ms 1152 KB Output is correct
14 Correct 1 ms 1152 KB Output is correct
15 Correct 1 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1152 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 1 ms 1152 KB Output is correct
12 Correct 2 ms 1152 KB Output is correct
13 Correct 1 ms 1152 KB Output is correct
14 Correct 1 ms 1152 KB Output is correct
15 Correct 1 ms 1152 KB Output is correct
16 Correct 1 ms 1152 KB Output is correct
17 Correct 2 ms 1280 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 1152 KB Output is correct
20 Correct 5 ms 1280 KB Output is correct
21 Correct 2 ms 1152 KB Output is correct
22 Correct 1 ms 1152 KB Output is correct
23 Correct 2 ms 1280 KB Output is correct
24 Correct 2 ms 1280 KB Output is correct
25 Correct 2 ms 1280 KB Output is correct
26 Correct 5 ms 1152 KB Output is correct
27 Correct 4 ms 1152 KB Output is correct
28 Correct 2 ms 1280 KB Output is correct
29 Correct 2 ms 1280 KB Output is correct
30 Correct 2 ms 1280 KB Output is correct
31 Correct 2 ms 1280 KB Output is correct
32 Correct 2 ms 1280 KB Output is correct
33 Correct 2 ms 1280 KB Output is correct
34 Correct 3 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1152 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 1 ms 1152 KB Output is correct
12 Correct 2 ms 1184 KB Output is correct
13 Correct 1 ms 1152 KB Output is correct
14 Correct 1 ms 1152 KB Output is correct
15 Correct 1 ms 1152 KB Output is correct
16 Correct 2 ms 1152 KB Output is correct
17 Correct 2 ms 1280 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 1152 KB Output is correct
20 Correct 5 ms 1280 KB Output is correct
21 Correct 1 ms 1152 KB Output is correct
22 Correct 1 ms 1152 KB Output is correct
23 Correct 2 ms 1280 KB Output is correct
24 Correct 3 ms 1280 KB Output is correct
25 Correct 3 ms 1280 KB Output is correct
26 Correct 4 ms 1152 KB Output is correct
27 Correct 4 ms 1152 KB Output is correct
28 Correct 2 ms 1312 KB Output is correct
29 Correct 2 ms 1280 KB Output is correct
30 Correct 2 ms 1280 KB Output is correct
31 Correct 2 ms 1280 KB Output is correct
32 Correct 2 ms 1280 KB Output is correct
33 Correct 2 ms 1280 KB Output is correct
34 Correct 3 ms 1408 KB Output is correct
35 Correct 9 ms 1664 KB Output is correct
36 Correct 2 ms 1280 KB Output is correct
37 Correct 7 ms 1568 KB Output is correct
38 Correct 11 ms 1792 KB Output is correct
39 Correct 9 ms 1792 KB Output is correct
40 Correct 9 ms 1792 KB Output is correct
41 Correct 9 ms 1792 KB Output is correct
42 Correct 46 ms 1664 KB Output is correct
43 Correct 50 ms 1664 KB Output is correct
44 Correct 46 ms 1664 KB Output is correct
45 Correct 8 ms 1664 KB Output is correct
46 Correct 8 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 1 ms 1152 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 1 ms 1152 KB Output is correct
8 Correct 1 ms 1152 KB Output is correct
9 Correct 1 ms 1152 KB Output is correct
10 Correct 1 ms 1152 KB Output is correct
11 Correct 1 ms 1152 KB Output is correct
12 Correct 1 ms 1152 KB Output is correct
13 Correct 1 ms 1152 KB Output is correct
14 Correct 1 ms 1152 KB Output is correct
15 Correct 1 ms 1152 KB Output is correct
16 Correct 1 ms 1152 KB Output is correct
17 Correct 2 ms 1280 KB Output is correct
18 Correct 1 ms 1152 KB Output is correct
19 Correct 1 ms 1152 KB Output is correct
20 Correct 5 ms 1280 KB Output is correct
21 Correct 1 ms 1152 KB Output is correct
22 Correct 1 ms 1152 KB Output is correct
23 Correct 2 ms 1152 KB Output is correct
24 Correct 2 ms 1280 KB Output is correct
25 Correct 2 ms 1280 KB Output is correct
26 Correct 4 ms 1152 KB Output is correct
27 Correct 4 ms 1152 KB Output is correct
28 Correct 2 ms 1280 KB Output is correct
29 Correct 2 ms 1280 KB Output is correct
30 Correct 2 ms 1280 KB Output is correct
31 Correct 2 ms 1280 KB Output is correct
32 Correct 2 ms 1280 KB Output is correct
33 Correct 2 ms 1280 KB Output is correct
34 Correct 3 ms 1408 KB Output is correct
35 Correct 7 ms 1664 KB Output is correct
36 Correct 3 ms 1280 KB Output is correct
37 Correct 6 ms 1664 KB Output is correct
38 Correct 9 ms 1792 KB Output is correct
39 Correct 9 ms 1792 KB Output is correct
40 Correct 9 ms 1792 KB Output is correct
41 Correct 9 ms 1792 KB Output is correct
42 Correct 46 ms 1712 KB Output is correct
43 Correct 51 ms 1664 KB Output is correct
44 Correct 46 ms 1664 KB Output is correct
45 Correct 8 ms 1664 KB Output is correct
46 Correct 9 ms 1664 KB Output is correct
47 Correct 17 ms 2428 KB Output is correct
48 Correct 8 ms 1792 KB Output is correct
49 Correct 7 ms 1792 KB Output is correct
50 Correct 5 ms 1664 KB Output is correct
51 Correct 28 ms 3252 KB Output is correct
52 Correct 29 ms 2684 KB Output is correct
53 Correct 15 ms 2684 KB Output is correct
54 Correct 2 ms 1408 KB Output is correct
55 Correct 3 ms 1408 KB Output is correct
56 Correct 799 ms 3016 KB Output is correct
57 Correct 45 ms 3440 KB Output is correct
58 Correct 946 ms 1912 KB Output is correct
59 Correct 593 ms 1912 KB Output is correct
60 Correct 858 ms 1912 KB Output is correct
61 Correct 592 ms 1864 KB Output is correct
62 Correct 12 ms 2304 KB Output is correct
63 Correct 24 ms 2808 KB Output is correct
64 Correct 24 ms 2808 KB Output is correct
65 Correct 27 ms 2808 KB Output is correct
66 Correct 36 ms 3828 KB Output is correct
67 Correct 38 ms 3828 KB Output is correct