Submission #674531

# Submission time Handle Problem Language Result Execution time Memory
674531 2022-12-24T21:25:20 Z AmirH Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
177 ms 68008 KB
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<bitset>
#include<queue>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<unordered_map>
#include<list>
#include<utility>
#include<stack>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
#define cl clear
#define F  first
#define S  second
#define pb push_back
#define Sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define faster ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const int MAX_N = 3e4 + 25;
const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
void free() {
    #ifndef ONLINE_JUDGE
        freopen("inputi.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
}
int n, m;
vector<pii> v;
set<pii> s[MAX_N];
vector<pii> adj[MAX_N];

int dij(int start, int end) {
    vector<int> dist(n, inf);
    dist[start] = 0;
    priority_queue<pii, vector<pii>, greater<pii>> pq;
    pq.push({0, start});
    while(!pq.empty()) {
        auto tren = pq.top();
        pq.pop();
        if(dist[tren.second] != tren.first) 
                continue;
        for(auto e : adj[tren.second]) {
            if(dist[e.first] > dist[tren.second] + e.second) {
                dist[e.first] = dist[tren.second] + e.second;
                pq.push({dist[e.first], e.first});
            }
        }
    }
    return dist[end];
}
int main() {
    faster; //free();
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        v.pb({x, y});
    }
    for(auto i : v) {
        s[i.first].insert(i);
    }
    for(int i = 0; i < n; i++) {
        for(auto z : s[i]) {
            if(z.second == 0) 
                continue;
            for(int j = 1; j < n; j++) {
                int nx = j * z.second + i;
                if(nx >= n) 
                    break;
                adj[i].push_back({nx, j});
                if(s[nx].count({nx, z.second})) 
                    break;
            }
            for(int j = 1; j < n; ++j) {
                int nx = -j * z.second + i;
                if(nx < 0) 
                    break;
                adj[i].push_back({nx, j});
                if(s[nx].count({nx, z.second})) 
                    break;
            }
        }
    }
    int ans = dij(v[0].first, v[1].first);
    if(ans >= inf)
        cout << -1;
    else
        cout << ans;
}

Compilation message

skyscraper.cpp: In function 'void free()':
skyscraper.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen("inputi.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 1 ms 2388 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 2 ms 2388 KB Output is correct
5 Correct 1 ms 2436 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 2 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 2 ms 2388 KB Output is correct
3 Correct 1 ms 2436 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 1 ms 2436 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 2 ms 2388 KB Output is correct
8 Correct 1 ms 2388 KB Output is correct
9 Correct 1 ms 2440 KB Output is correct
10 Correct 2 ms 2388 KB Output is correct
11 Correct 2 ms 2516 KB Output is correct
12 Correct 2 ms 2388 KB Output is correct
13 Correct 2 ms 2444 KB Output is correct
14 Correct 2 ms 2516 KB Output is correct
15 Correct 2 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 1 ms 2388 KB Output is correct
3 Correct 1 ms 2436 KB Output is correct
4 Correct 2 ms 2436 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 2 ms 2388 KB Output is correct
9 Correct 2 ms 2436 KB Output is correct
10 Correct 2 ms 2388 KB Output is correct
11 Correct 2 ms 2516 KB Output is correct
12 Correct 2 ms 2444 KB Output is correct
13 Correct 2 ms 2388 KB Output is correct
14 Correct 3 ms 2568 KB Output is correct
15 Correct 2 ms 2572 KB Output is correct
16 Correct 2 ms 2516 KB Output is correct
17 Correct 2 ms 2704 KB Output is correct
18 Correct 2 ms 2516 KB Output is correct
19 Correct 2 ms 2516 KB Output is correct
20 Correct 2 ms 2580 KB Output is correct
21 Correct 2 ms 2516 KB Output is correct
22 Correct 2 ms 2516 KB Output is correct
23 Correct 2 ms 2572 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 3 ms 2644 KB Output is correct
26 Correct 2 ms 2472 KB Output is correct
27 Correct 2 ms 2572 KB Output is correct
28 Correct 3 ms 2700 KB Output is correct
29 Correct 4 ms 3284 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 3 ms 2900 KB Output is correct
32 Correct 3 ms 2860 KB Output is correct
33 Correct 8 ms 3924 KB Output is correct
34 Correct 6 ms 3924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2436 KB Output is correct
2 Correct 1 ms 2388 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 2 ms 2388 KB Output is correct
5 Correct 1 ms 2412 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 2 ms 2388 KB Output is correct
8 Correct 2 ms 2388 KB Output is correct
9 Correct 1 ms 2436 KB Output is correct
10 Correct 2 ms 2388 KB Output is correct
11 Correct 2 ms 2572 KB Output is correct
12 Correct 2 ms 2388 KB Output is correct
13 Correct 2 ms 2388 KB Output is correct
14 Correct 2 ms 2576 KB Output is correct
15 Correct 2 ms 2516 KB Output is correct
16 Correct 2 ms 2516 KB Output is correct
17 Correct 2 ms 2708 KB Output is correct
18 Correct 2 ms 2516 KB Output is correct
19 Correct 1 ms 2516 KB Output is correct
20 Correct 2 ms 2516 KB Output is correct
21 Correct 2 ms 2444 KB Output is correct
22 Correct 2 ms 2516 KB Output is correct
23 Correct 2 ms 2516 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2516 KB Output is correct
27 Correct 2 ms 2572 KB Output is correct
28 Correct 2 ms 2772 KB Output is correct
29 Correct 4 ms 3284 KB Output is correct
30 Correct 3 ms 2772 KB Output is correct
31 Correct 3 ms 2900 KB Output is correct
32 Correct 3 ms 2772 KB Output is correct
33 Correct 6 ms 3924 KB Output is correct
34 Correct 6 ms 3980 KB Output is correct
35 Correct 14 ms 4996 KB Output is correct
36 Correct 4 ms 2900 KB Output is correct
37 Correct 16 ms 5720 KB Output is correct
38 Correct 20 ms 6060 KB Output is correct
39 Correct 19 ms 6076 KB Output is correct
40 Correct 19 ms 6092 KB Output is correct
41 Correct 19 ms 6016 KB Output is correct
42 Correct 5 ms 3032 KB Output is correct
43 Correct 6 ms 3028 KB Output is correct
44 Correct 5 ms 3032 KB Output is correct
45 Correct 20 ms 8712 KB Output is correct
46 Correct 20 ms 8784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 1 ms 2388 KB Output is correct
3 Correct 1 ms 2388 KB Output is correct
4 Correct 1 ms 2388 KB Output is correct
5 Correct 2 ms 2436 KB Output is correct
6 Correct 1 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 1 ms 2400 KB Output is correct
9 Correct 1 ms 2388 KB Output is correct
10 Correct 1 ms 2388 KB Output is correct
11 Correct 2 ms 2516 KB Output is correct
12 Correct 2 ms 2388 KB Output is correct
13 Correct 2 ms 2440 KB Output is correct
14 Correct 2 ms 2572 KB Output is correct
15 Correct 2 ms 2576 KB Output is correct
16 Correct 2 ms 2436 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2516 KB Output is correct
19 Correct 2 ms 2516 KB Output is correct
20 Correct 2 ms 2516 KB Output is correct
21 Correct 2 ms 2516 KB Output is correct
22 Correct 2 ms 2516 KB Output is correct
23 Correct 2 ms 2516 KB Output is correct
24 Correct 3 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2516 KB Output is correct
27 Correct 2 ms 2572 KB Output is correct
28 Correct 2 ms 2772 KB Output is correct
29 Correct 4 ms 3284 KB Output is correct
30 Correct 2 ms 2696 KB Output is correct
31 Correct 3 ms 2900 KB Output is correct
32 Correct 2 ms 2772 KB Output is correct
33 Correct 6 ms 3924 KB Output is correct
34 Correct 6 ms 3924 KB Output is correct
35 Correct 14 ms 5080 KB Output is correct
36 Correct 4 ms 2900 KB Output is correct
37 Correct 16 ms 5696 KB Output is correct
38 Correct 19 ms 6096 KB Output is correct
39 Correct 20 ms 6096 KB Output is correct
40 Correct 21 ms 6040 KB Output is correct
41 Correct 19 ms 6108 KB Output is correct
42 Correct 6 ms 2956 KB Output is correct
43 Correct 7 ms 3032 KB Output is correct
44 Correct 6 ms 3032 KB Output is correct
45 Correct 22 ms 8776 KB Output is correct
46 Correct 20 ms 8708 KB Output is correct
47 Correct 40 ms 13116 KB Output is correct
48 Correct 14 ms 6308 KB Output is correct
49 Correct 12 ms 5384 KB Output is correct
50 Correct 10 ms 4948 KB Output is correct
51 Correct 33 ms 8468 KB Output is correct
52 Correct 33 ms 8916 KB Output is correct
53 Correct 16 ms 5936 KB Output is correct
54 Correct 3 ms 3028 KB Output is correct
55 Correct 4 ms 3408 KB Output is correct
56 Correct 11 ms 5336 KB Output is correct
57 Correct 29 ms 11672 KB Output is correct
58 Correct 8 ms 3856 KB Output is correct
59 Correct 9 ms 4308 KB Output is correct
60 Correct 12 ms 4984 KB Output is correct
61 Correct 10 ms 4420 KB Output is correct
62 Correct 20 ms 9596 KB Output is correct
63 Correct 61 ms 26900 KB Output is correct
64 Correct 72 ms 30024 KB Output is correct
65 Correct 94 ms 39660 KB Output is correct
66 Correct 173 ms 67996 KB Output is correct
67 Correct 177 ms 68008 KB Output is correct