답안 #578631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578631 2022-06-17T12:09:01 Z dxz05 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
178 ms 118852 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 = 30001;
const int M = 1111;

bitset<30001> bit[30000];

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

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

set<int> s[N];

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

    for (int i = 0; i < m; i++){
        cin >> b[i] >> p[i];
        bit[b[i]].set(p[i]);
    }

    for (int i = 0; i < m; i++){
        if (s[b[i]].find(p[i]) != s[b[i]].end()) continue;
        s[b[i]].insert(p[i]);

        int j = b[i] + p[i], cnt = 1;
        while (j < n){
            g[b[i]].emplace_back(j, cnt);
            if (bit[j][p[i]]) break;
            cnt++;
            j += p[i];
        }

        j = b[i] - p[i], cnt = 1;
        while (j >= 0){
            g[b[i]].emplace_back(j, cnt);
            if (bit[j][p[i]]) break;
            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:97:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   97 |         for (auto [u, w] : g[v]){
      |                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 1 ms 2388 KB Output is correct
3 Correct 2 ms 2388 KB Output is correct
4 Correct 2 ms 2388 KB Output is correct
5 Correct 2 ms 2388 KB Output is correct
6 Correct 2 ms 2388 KB Output is correct
7 Correct 3 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2388 KB Output is correct
2 Correct 2 ms 2456 KB Output is correct
3 Correct 2 ms 2388 KB Output is correct
4 Correct 2 ms 2388 KB Output is correct
5 Correct 2 ms 2388 KB Output is correct
6 Correct 2 ms 2388 KB Output is correct
7 Correct 2 ms 2388 KB Output is correct
8 Correct 1 ms 2516 KB Output is correct
9 Correct 2 ms 2516 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2388 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2772 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 2 ms 2388 KB Output is correct
3 Correct 2 ms 2388 KB Output is correct
4 Correct 2 ms 2388 KB Output is correct
5 Correct 2 ms 2388 KB Output is correct
6 Correct 2 ms 2388 KB Output is correct
7 Correct 2 ms 2388 KB Output is correct
8 Correct 2 ms 2516 KB Output is correct
9 Correct 2 ms 2516 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2388 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 3 ms 2772 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
16 Correct 2 ms 3156 KB Output is correct
17 Correct 3 ms 5204 KB Output is correct
18 Correct 4 ms 5460 KB Output is correct
19 Correct 4 ms 4436 KB Output is correct
20 Correct 5 ms 9940 KB Output is correct
21 Correct 2 ms 3924 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 4 ms 5332 KB Output is correct
24 Correct 5 ms 7252 KB Output is correct
25 Correct 5 ms 7508 KB Output is correct
26 Correct 3 ms 2900 KB Output is correct
27 Correct 3 ms 2772 KB Output is correct
28 Correct 6 ms 10112 KB Output is correct
29 Correct 5 ms 3412 KB Output is correct
30 Correct 3 ms 2772 KB Output is correct
31 Correct 3 ms 3028 KB Output is correct
32 Correct 4 ms 3028 KB Output is correct
33 Correct 7 ms 4180 KB Output is correct
34 Correct 7 ms 4228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 2388 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 2516 KB Output is correct
9 Correct 2 ms 2516 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 3 ms 2900 KB Output is correct
12 Correct 2 ms 2388 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2772 KB Output is correct
15 Correct 3 ms 2772 KB Output is correct
16 Correct 2 ms 3156 KB Output is correct
17 Correct 4 ms 5204 KB Output is correct
18 Correct 4 ms 5460 KB Output is correct
19 Correct 4 ms 4436 KB Output is correct
20 Correct 5 ms 9940 KB Output is correct
21 Correct 2 ms 3924 KB Output is correct
22 Correct 3 ms 4820 KB Output is correct
23 Correct 4 ms 5332 KB Output is correct
24 Correct 5 ms 7252 KB Output is correct
25 Correct 5 ms 7508 KB Output is correct
26 Correct 3 ms 2900 KB Output is correct
27 Correct 3 ms 2772 KB Output is correct
28 Correct 5 ms 10068 KB Output is correct
29 Correct 4 ms 3412 KB Output is correct
30 Correct 4 ms 2772 KB Output is correct
31 Correct 3 ms 3156 KB Output is correct
32 Correct 4 ms 3028 KB Output is correct
33 Correct 6 ms 4128 KB Output is correct
34 Correct 6 ms 4308 KB Output is correct
35 Correct 16 ms 10144 KB Output is correct
36 Correct 5 ms 6868 KB Output is correct
37 Correct 17 ms 12684 KB Output is correct
38 Correct 19 ms 13136 KB Output is correct
39 Correct 19 ms 13264 KB Output is correct
40 Correct 20 ms 13220 KB Output is correct
41 Correct 20 ms 13152 KB Output is correct
42 Correct 6 ms 3028 KB Output is correct
43 Correct 6 ms 2900 KB Output is correct
44 Correct 9 ms 10104 KB Output is correct
45 Correct 22 ms 9372 KB Output is correct
46 Correct 24 ms 9424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2388 KB Output is correct
2 Correct 2 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 2 ms 2388 KB Output is correct
6 Correct 2 ms 2388 KB Output is correct
7 Correct 1 ms 2388 KB Output is correct
8 Correct 2 ms 2516 KB Output is correct
9 Correct 2 ms 2516 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2900 KB Output is correct
12 Correct 2 ms 2388 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2772 KB Output is correct
15 Correct 3 ms 2772 KB Output is correct
16 Correct 2 ms 3156 KB Output is correct
17 Correct 4 ms 5204 KB Output is correct
18 Correct 4 ms 5460 KB Output is correct
19 Correct 4 ms 4436 KB Output is correct
20 Correct 5 ms 9940 KB Output is correct
21 Correct 2 ms 3924 KB Output is correct
22 Correct 3 ms 4820 KB Output is correct
23 Correct 4 ms 5332 KB Output is correct
24 Correct 5 ms 7252 KB Output is correct
25 Correct 5 ms 7508 KB Output is correct
26 Correct 3 ms 2900 KB Output is correct
27 Correct 3 ms 2772 KB Output is correct
28 Correct 6 ms 10068 KB Output is correct
29 Correct 5 ms 3412 KB Output is correct
30 Correct 3 ms 2796 KB Output is correct
31 Correct 4 ms 3028 KB Output is correct
32 Correct 4 ms 3028 KB Output is correct
33 Correct 6 ms 4180 KB Output is correct
34 Correct 6 ms 4180 KB Output is correct
35 Correct 17 ms 10088 KB Output is correct
36 Correct 6 ms 6868 KB Output is correct
37 Correct 17 ms 12692 KB Output is correct
38 Correct 19 ms 13224 KB Output is correct
39 Correct 20 ms 13204 KB Output is correct
40 Correct 22 ms 13264 KB Output is correct
41 Correct 20 ms 13140 KB Output is correct
42 Correct 6 ms 3028 KB Output is correct
43 Correct 7 ms 3012 KB Output is correct
44 Correct 9 ms 10180 KB Output is correct
45 Correct 24 ms 9472 KB Output is correct
46 Correct 22 ms 9488 KB Output is correct
47 Correct 58 ms 52836 KB Output is correct
48 Correct 46 ms 61748 KB Output is correct
49 Correct 44 ms 61076 KB Output is correct
50 Correct 37 ms 50204 KB Output is correct
51 Correct 78 ms 81628 KB Output is correct
52 Correct 81 ms 81940 KB Output is correct
53 Correct 56 ms 78596 KB Output is correct
54 Correct 16 ms 3368 KB Output is correct
55 Correct 18 ms 3816 KB Output is correct
56 Correct 62 ms 115512 KB Output is correct
57 Correct 53 ms 20636 KB Output is correct
58 Correct 21 ms 4148 KB Output is correct
59 Correct 23 ms 4668 KB Output is correct
60 Correct 24 ms 6060 KB Output is correct
61 Correct 23 ms 6124 KB Output is correct
62 Correct 77 ms 118852 KB Output is correct
63 Correct 88 ms 31496 KB Output is correct
64 Correct 99 ms 39752 KB Output is correct
65 Correct 120 ms 50832 KB Output is correct
66 Correct 173 ms 79676 KB Output is correct
67 Correct 178 ms 78920 KB Output is correct