Submission #578571

# Submission time Handle Problem Language Result Execution time Memory
578571 2022-06-17T10:09:05 Z dxz05 Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
256 ms 262144 KB
#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << "[" << H << "]";
    debug_out(T...);
}

#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)

clock_t startTime;

double getCurrentTime() {
    return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}

#define MP make_pair

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.000001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 3e2;
const int M = 1111;

vector<pair<int, int>> g[N];
int b[N], p[N];

int d[N];
bool processed[N];

void solve(int TC) {
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++){
        cin >> b[i] >> p[i];
        int j = b[i], cnt = 0;
        while (j < n){
            g[b[i]].emplace_back(j, cnt);
            cnt++;
            j += p[i];
        }

        j = b[i], cnt = 0;
        while (j >= 0){
            g[b[i]].emplace_back(j, cnt);
            cnt++;
            j -= p[i];
        }

    }

    fill(d, d + n, INF);

    d[b[0]] = 0;
    priority_queue<pair<int, int>> pq;
    pq.push(MP(0, b[0]));

    while (!pq.empty()){
        int v = pq.top().second;
        pq.pop();
        if (processed[v]) continue;
        processed[v] = true;
        for (auto [u, w] : g[v]){
            if (d[u] > d[v] + w){
                d[u] = d[v] + w;
                pq.push(MP(-d[u], u));
            }
        }
    }

    cout << (d[b[1]] != INF ? d[b[1]] : -1);

}

int main() {
    startTime = clock();
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int TC = 1;
//    cin >> TC;

    for (int test = 1; test <= TC; test++) {
        //debug(test);
        //cout << "Case #" << test << ": ";
        solve(test);
    }

#ifdef dddxxz
    cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
#endif

    return 0;
}

Compilation message

skyscraper.cpp: In function 'void solve(int)':
skyscraper.cpp:84:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   84 |         for (auto [u, w] : g[v]){
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23764 KB Output is correct
2 Correct 15 ms 23764 KB Output is correct
3 Correct 16 ms 23828 KB Output is correct
4 Correct 15 ms 23764 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 15 ms 23824 KB Output is correct
7 Correct 18 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23764 KB Output is correct
2 Correct 19 ms 23844 KB Output is correct
3 Correct 16 ms 23764 KB Output is correct
4 Correct 15 ms 23764 KB Output is correct
5 Correct 15 ms 23820 KB Output is correct
6 Correct 15 ms 23876 KB Output is correct
7 Correct 15 ms 23764 KB Output is correct
8 Correct 15 ms 23764 KB Output is correct
9 Correct 15 ms 23764 KB Output is correct
10 Correct 15 ms 23836 KB Output is correct
11 Correct 15 ms 23960 KB Output is correct
12 Correct 17 ms 25936 KB Output is correct
13 Correct 17 ms 26072 KB Output is correct
14 Correct 15 ms 23956 KB Output is correct
15 Correct 18 ms 23964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23832 KB Output is correct
2 Correct 17 ms 23820 KB Output is correct
3 Correct 17 ms 23824 KB Output is correct
4 Correct 16 ms 23820 KB Output is correct
5 Correct 17 ms 23768 KB Output is correct
6 Correct 19 ms 23800 KB Output is correct
7 Correct 16 ms 23764 KB Output is correct
8 Correct 15 ms 23764 KB Output is correct
9 Correct 15 ms 23820 KB Output is correct
10 Correct 15 ms 23820 KB Output is correct
11 Correct 15 ms 23948 KB Output is correct
12 Correct 18 ms 25996 KB Output is correct
13 Correct 18 ms 26004 KB Output is correct
14 Correct 16 ms 23932 KB Output is correct
15 Correct 16 ms 23980 KB Output is correct
16 Correct 16 ms 23956 KB Output is correct
17 Correct 15 ms 24080 KB Output is correct
18 Correct 17 ms 23960 KB Output is correct
19 Correct 19 ms 23828 KB Output is correct
20 Correct 58 ms 55908 KB Output is correct
21 Correct 15 ms 23892 KB Output is correct
22 Correct 16 ms 23840 KB Output is correct
23 Correct 16 ms 23892 KB Output is correct
24 Correct 17 ms 24020 KB Output is correct
25 Correct 17 ms 24020 KB Output is correct
26 Correct 63 ms 56964 KB Output is correct
27 Correct 59 ms 56788 KB Output is correct
28 Correct 16 ms 24148 KB Output is correct
29 Correct 18 ms 24592 KB Output is correct
30 Correct 17 ms 24076 KB Output is correct
31 Correct 20 ms 24276 KB Output is correct
32 Correct 20 ms 24140 KB Output is correct
33 Correct 21 ms 25300 KB Output is correct
34 Correct 18 ms 25364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23792 KB Output is correct
2 Correct 17 ms 23824 KB Output is correct
3 Correct 15 ms 23812 KB Output is correct
4 Correct 14 ms 23728 KB Output is correct
5 Correct 15 ms 23808 KB Output is correct
6 Correct 14 ms 23784 KB Output is correct
7 Correct 16 ms 23752 KB Output is correct
8 Correct 15 ms 23764 KB Output is correct
9 Correct 16 ms 23764 KB Output is correct
10 Correct 16 ms 23764 KB Output is correct
11 Correct 17 ms 24020 KB Output is correct
12 Correct 18 ms 25960 KB Output is correct
13 Correct 19 ms 25936 KB Output is correct
14 Correct 15 ms 23924 KB Output is correct
15 Correct 15 ms 23872 KB Output is correct
16 Correct 15 ms 23892 KB Output is correct
17 Correct 15 ms 24104 KB Output is correct
18 Correct 16 ms 23980 KB Output is correct
19 Correct 15 ms 23892 KB Output is correct
20 Correct 56 ms 55984 KB Output is correct
21 Correct 16 ms 23892 KB Output is correct
22 Correct 18 ms 23816 KB Output is correct
23 Correct 17 ms 23936 KB Output is correct
24 Correct 15 ms 24020 KB Output is correct
25 Correct 16 ms 23952 KB Output is correct
26 Correct 60 ms 56888 KB Output is correct
27 Correct 60 ms 56900 KB Output is correct
28 Correct 16 ms 24112 KB Output is correct
29 Correct 18 ms 24660 KB Output is correct
30 Correct 16 ms 24088 KB Output is correct
31 Correct 18 ms 24404 KB Output is correct
32 Correct 17 ms 24120 KB Output is correct
33 Correct 19 ms 25300 KB Output is correct
34 Correct 18 ms 25300 KB Output is correct
35 Correct 22 ms 26472 KB Output is correct
36 Correct 16 ms 24208 KB Output is correct
37 Correct 24 ms 27964 KB Output is correct
38 Correct 24 ms 27716 KB Output is correct
39 Correct 25 ms 27928 KB Output is correct
40 Correct 29 ms 27776 KB Output is correct
41 Correct 29 ms 27652 KB Output is correct
42 Runtime error 255 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23816 KB Output is correct
2 Correct 17 ms 23764 KB Output is correct
3 Correct 14 ms 23764 KB Output is correct
4 Correct 17 ms 23732 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 15 ms 23816 KB Output is correct
7 Correct 16 ms 23764 KB Output is correct
8 Correct 16 ms 23808 KB Output is correct
9 Correct 15 ms 23820 KB Output is correct
10 Correct 16 ms 23804 KB Output is correct
11 Correct 15 ms 23956 KB Output is correct
12 Correct 17 ms 25936 KB Output is correct
13 Correct 18 ms 26072 KB Output is correct
14 Correct 15 ms 23952 KB Output is correct
15 Correct 15 ms 23924 KB Output is correct
16 Correct 15 ms 23820 KB Output is correct
17 Correct 16 ms 24148 KB Output is correct
18 Correct 15 ms 23892 KB Output is correct
19 Correct 15 ms 23916 KB Output is correct
20 Correct 59 ms 55960 KB Output is correct
21 Correct 16 ms 23892 KB Output is correct
22 Correct 16 ms 23876 KB Output is correct
23 Correct 16 ms 23892 KB Output is correct
24 Correct 17 ms 24084 KB Output is correct
25 Correct 15 ms 23952 KB Output is correct
26 Correct 66 ms 56880 KB Output is correct
27 Correct 62 ms 56888 KB Output is correct
28 Correct 18 ms 24084 KB Output is correct
29 Correct 18 ms 24652 KB Output is correct
30 Correct 16 ms 24148 KB Output is correct
31 Correct 20 ms 24276 KB Output is correct
32 Correct 16 ms 24112 KB Output is correct
33 Correct 17 ms 25288 KB Output is correct
34 Correct 18 ms 25300 KB Output is correct
35 Correct 23 ms 26540 KB Output is correct
36 Correct 19 ms 24216 KB Output is correct
37 Correct 25 ms 27916 KB Output is correct
38 Correct 26 ms 27672 KB Output is correct
39 Correct 28 ms 27956 KB Output is correct
40 Correct 26 ms 27796 KB Output is correct
41 Correct 26 ms 27708 KB Output is correct
42 Runtime error 256 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -