Submission #916213

# Submission time Handle Problem Language Result Execution time Memory
916213 2024-01-25T13:34:18 Z hariaakas646 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
978 ms 4576 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, l, r) for(int i=l; i<r; i++)
#define frange(i, l) forr(i, 0, l)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef long long lli;
typedef vector<vi> vvi;
typedef vector<lli> vll;
typedef vector<bool> vb;
typedef set<int> seti;
typedef multiset<int> mseti;

void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
}

int main() {
    // usaco();
    int n, m;
    scd(n);
    scd(m);
    vii vec(m);

    vvi pos(n);

    frange(i, m) {
        scd(vec[i].f);
        scd(vec[i].s);
        pos[vec[i].f].pb(i);
    }

    priority_queue<pair<lli, int>> pq;
    vll dist(n, 1e18);
    dist[vec[0].f] = 0;
    for(auto e : pos[vec[0].f])
        pq.push(mp(0, e));
    vb vis(m);

    
    

    while(pq.size()) {
        auto p = pq.top();
        pq.pop();
        if(vis[p.s]) continue;
        vis[p.s] = true;

        int id = vec[p.s].f;
        int pow = vec[p.s].s;

        for(int i=1; id+i*pow<n; i++) {
            if(-p.f + i < dist[id+i*pow]) {
                dist[id+i*pow] = -p.f+i;
                for(auto e : pos[id+i*pow]) pq.push(mp(-dist[id+i*pow], e));
            }
        }

        for(int i=-1; id+i*pow>=0; i--) {
            if(-p.f - i < dist[id+i*pow]) {
                dist[id+i*pow] = -p.f-i;
                for(auto e : pos[id+i*pow]) pq.push(mp(-dist[id+i*pow], e));
            }
        }
    }

    if(dist[vec[1].f] == 1e18) printf("-1");
    else printf("%lld", dist[vec[1].f]);
}

Compilation message

skyscraper.cpp: In function 'void usaco()':
skyscraper.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
skyscraper.cpp:33:5: note: in expansion of macro 'scd'
   33 |     scd(n);
      |     ^~~
skyscraper.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
skyscraper.cpp:34:5: note: in expansion of macro 'scd'
   34 |     scd(m);
      |     ^~~
skyscraper.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
skyscraper.cpp:40:9: note: in expansion of macro 'scd'
   40 |         scd(vec[i].f);
      |         ^~~
skyscraper.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
skyscraper.cpp:41:9: note: in expansion of macro 'scd'
   41 |         scd(vec[i].s);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 440 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 5 ms 604 KB Output is correct
21 Correct 1 ms 444 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 4 ms 604 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 540 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 5 ms 448 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 436 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 5 ms 608 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 500 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 15 ms 2260 KB Output is correct
36 Correct 2 ms 584 KB Output is correct
37 Correct 12 ms 2012 KB Output is correct
38 Correct 18 ms 3280 KB Output is correct
39 Correct 17 ms 3280 KB Output is correct
40 Correct 18 ms 3280 KB Output is correct
41 Correct 19 ms 3284 KB Output is correct
42 Correct 63 ms 1504 KB Output is correct
43 Correct 64 ms 1504 KB Output is correct
44 Correct 64 ms 1760 KB Output is correct
45 Correct 14 ms 2256 KB Output is correct
46 Correct 14 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 440 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 5 ms 600 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 544 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 4 ms 600 KB Output is correct
27 Correct 4 ms 604 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 15 ms 2260 KB Output is correct
36 Correct 3 ms 604 KB Output is correct
37 Correct 12 ms 2112 KB Output is correct
38 Correct 18 ms 3284 KB Output is correct
39 Correct 18 ms 3268 KB Output is correct
40 Correct 19 ms 3284 KB Output is correct
41 Correct 22 ms 3284 KB Output is correct
42 Correct 63 ms 1504 KB Output is correct
43 Correct 64 ms 1504 KB Output is correct
44 Correct 64 ms 1536 KB Output is correct
45 Correct 18 ms 2260 KB Output is correct
46 Correct 13 ms 2260 KB Output is correct
47 Correct 23 ms 3788 KB Output is correct
48 Correct 5 ms 1884 KB Output is correct
49 Correct 5 ms 1884 KB Output is correct
50 Correct 6 ms 2144 KB Output is correct
51 Correct 23 ms 4576 KB Output is correct
52 Correct 21 ms 3544 KB Output is correct
53 Correct 12 ms 3684 KB Output is correct
54 Correct 1 ms 1368 KB Output is correct
55 Correct 1 ms 1372 KB Output is correct
56 Correct 913 ms 3364 KB Output is correct
57 Correct 13 ms 1756 KB Output is correct
58 Correct 978 ms 2264 KB Output is correct
59 Correct 899 ms 2560 KB Output is correct
60 Correct 939 ms 3028 KB Output is correct
61 Correct 778 ms 2572 KB Output is correct
62 Correct 8 ms 2652 KB Output is correct
63 Correct 14 ms 2600 KB Output is correct
64 Correct 14 ms 2524 KB Output is correct
65 Correct 17 ms 2676 KB Output is correct
66 Correct 23 ms 3040 KB Output is correct
67 Correct 24 ms 3040 KB Output is correct