답안 #142786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
142786 2019-08-11T03:26:06 Z 12tqian Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
240 ms 72380 KB
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

const double PI = 4 * atan(1);

#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>

#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)

void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
void io(string taskname){
    string fin = taskname + ".in";
    string fout = taskname + ".out";
    const char* FIN = fin.c_str();
    const char* FOUT = fout.c_str();
    freopen(FIN, "r", stdin);
    freopen(FOUT, "w", stdout);
    fast_io();
}
const int MAX = 3e4 + 5;
const int INF = 1e9;

int n, m;
map<int, map<int, vi>> um;
///first is the modulus
///next is remainders, then is set of doges that works
vpi d;
vpi adj[MAX];
set<int> power[MAX];



int dist[MAX];
int par[MAX];
int dijkstra(int st, int end) {
    fill(dist, dist + MAX, INF);

    dist[st] = 0;

    // <distance, <previous vertex, current vertex>>
    priority_queue<pair<ll, pair<int, int>>, vector<pair<ll, pair<int, int>> >, greater<pair<ll, pair<int ,int>> > > pq;
    pq.emplace(0, make_pair(st, st));

    while(!pq.empty()){
        auto top = pq.top();
        pq.pop();

        ll d = top.first;
        int prev = top.second.first;
        int cur = top.second.second;

        if(d > dist[cur])
            continue;

        par[cur] = prev;

        for(auto v: adj[cur]){
            int nxt = v.first;
            ll w = v.second;
            if (dist[nxt] > dist[cur] + w) {
                dist[nxt] = dist[cur] + w;
                pq.emplace(dist[nxt], make_pair(cur, nxt));
            }
        }
    }
    return dist[end];
}
int main(){
    fast_io();
    cin >> n >> m;
    f0r(i, m){
        int bi, pi;
        cin >> bi >> pi;
        d.eb(mp(bi, pi));
        power[bi].insert(pi);
    }
    f0r(i, n){
        for(int p: power[i]){
            int cur = i+p;
            int val = 1;
            while(cur<n){
                adj[i].eb(mp(cur, val));
                if(power[cur].find(p) != power[cur].end()) break;
                val++;
                cur += p;
            }
            cur = i-p;
            val = 1;
            while(cur>=0){
                adj[i].eb(mp(cur, val));
                if(power[cur].find(p) != power[cur].end()) break;
                val++;
                cur -= p;
            }
        }
    }
    int res = dijkstra(d[0].f, d[1].f);
    if(res == INF) cout << -1 << endl;
    else cout << res << endl;

    return 0;
}

Compilation message

skyscraper.cpp:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
 
skyscraper.cpp: In function 'void io(std::__cxx11::string)':
skyscraper.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FIN, "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FOUT, "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2552 KB Output is correct
3 Correct 4 ms 2552 KB Output is correct
4 Correct 4 ms 2552 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 4 ms 2552 KB Output is correct
7 Correct 4 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2552 KB Output is correct
2 Correct 4 ms 2552 KB Output is correct
3 Correct 4 ms 2552 KB Output is correct
4 Correct 4 ms 2552 KB Output is correct
5 Correct 4 ms 2552 KB Output is correct
6 Correct 4 ms 2556 KB Output is correct
7 Correct 4 ms 2556 KB Output is correct
8 Correct 4 ms 2552 KB Output is correct
9 Correct 4 ms 2556 KB Output is correct
10 Correct 4 ms 2680 KB Output is correct
11 Correct 5 ms 2680 KB Output is correct
12 Correct 5 ms 2680 KB Output is correct
13 Correct 4 ms 2680 KB Output is correct
14 Correct 5 ms 2808 KB Output is correct
15 Correct 6 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2552 KB Output is correct
2 Correct 4 ms 2552 KB Output is correct
3 Correct 5 ms 2552 KB Output is correct
4 Correct 4 ms 2552 KB Output is correct
5 Correct 4 ms 2552 KB Output is correct
6 Correct 4 ms 2552 KB Output is correct
7 Correct 4 ms 2552 KB Output is correct
8 Correct 4 ms 2552 KB Output is correct
9 Correct 4 ms 2524 KB Output is correct
10 Correct 5 ms 2700 KB Output is correct
11 Correct 5 ms 2792 KB Output is correct
12 Correct 5 ms 2652 KB Output is correct
13 Correct 5 ms 2552 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 5 ms 2680 KB Output is correct
16 Correct 6 ms 2680 KB Output is correct
17 Correct 6 ms 2936 KB Output is correct
18 Correct 7 ms 2680 KB Output is correct
19 Correct 5 ms 2680 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
21 Correct 5 ms 2656 KB Output is correct
22 Correct 5 ms 2680 KB Output is correct
23 Correct 5 ms 2808 KB Output is correct
24 Correct 7 ms 2940 KB Output is correct
25 Correct 6 ms 2936 KB Output is correct
26 Correct 5 ms 2680 KB Output is correct
27 Correct 5 ms 2684 KB Output is correct
28 Correct 6 ms 2936 KB Output is correct
29 Correct 8 ms 3580 KB Output is correct
30 Correct 6 ms 3064 KB Output is correct
31 Correct 6 ms 3192 KB Output is correct
32 Correct 6 ms 3064 KB Output is correct
33 Correct 13 ms 4468 KB Output is correct
34 Correct 13 ms 4468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2552 KB Output is correct
2 Correct 4 ms 2552 KB Output is correct
3 Correct 6 ms 2552 KB Output is correct
4 Correct 4 ms 2552 KB Output is correct
5 Correct 4 ms 2552 KB Output is correct
6 Correct 4 ms 2500 KB Output is correct
7 Correct 5 ms 2552 KB Output is correct
8 Correct 6 ms 2552 KB Output is correct
9 Correct 5 ms 2552 KB Output is correct
10 Correct 5 ms 2552 KB Output is correct
11 Correct 5 ms 2680 KB Output is correct
12 Correct 5 ms 2552 KB Output is correct
13 Correct 4 ms 2552 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 5 ms 2680 KB Output is correct
16 Correct 5 ms 2680 KB Output is correct
17 Correct 6 ms 2936 KB Output is correct
18 Correct 5 ms 2728 KB Output is correct
19 Correct 5 ms 2680 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
21 Correct 5 ms 2680 KB Output is correct
22 Correct 5 ms 2680 KB Output is correct
23 Correct 5 ms 2812 KB Output is correct
24 Correct 6 ms 2936 KB Output is correct
25 Correct 6 ms 2936 KB Output is correct
26 Correct 5 ms 2680 KB Output is correct
27 Correct 6 ms 2652 KB Output is correct
28 Correct 5 ms 2936 KB Output is correct
29 Correct 8 ms 3592 KB Output is correct
30 Correct 6 ms 3064 KB Output is correct
31 Correct 7 ms 3192 KB Output is correct
32 Correct 6 ms 3064 KB Output is correct
33 Correct 10 ms 4468 KB Output is correct
34 Correct 11 ms 4468 KB Output is correct
35 Correct 26 ms 5364 KB Output is correct
36 Correct 7 ms 3064 KB Output is correct
37 Correct 28 ms 6004 KB Output is correct
38 Correct 33 ms 6392 KB Output is correct
39 Correct 34 ms 6368 KB Output is correct
40 Correct 34 ms 6384 KB Output is correct
41 Correct 34 ms 6388 KB Output is correct
42 Correct 10 ms 3200 KB Output is correct
43 Correct 10 ms 3200 KB Output is correct
44 Correct 10 ms 3244 KB Output is correct
45 Correct 34 ms 9216 KB Output is correct
46 Correct 34 ms 9348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2552 KB Output is correct
2 Correct 4 ms 2552 KB Output is correct
3 Correct 5 ms 2552 KB Output is correct
4 Correct 7 ms 2552 KB Output is correct
5 Correct 7 ms 2552 KB Output is correct
6 Correct 4 ms 2552 KB Output is correct
7 Correct 4 ms 2552 KB Output is correct
8 Correct 4 ms 2552 KB Output is correct
9 Correct 4 ms 2552 KB Output is correct
10 Correct 4 ms 2556 KB Output is correct
11 Correct 5 ms 2680 KB Output is correct
12 Correct 4 ms 2552 KB Output is correct
13 Correct 4 ms 2552 KB Output is correct
14 Correct 5 ms 2760 KB Output is correct
15 Correct 6 ms 2808 KB Output is correct
16 Correct 5 ms 2680 KB Output is correct
17 Correct 6 ms 2936 KB Output is correct
18 Correct 5 ms 2680 KB Output is correct
19 Correct 5 ms 2680 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
21 Correct 5 ms 2680 KB Output is correct
22 Correct 5 ms 2680 KB Output is correct
23 Correct 5 ms 2680 KB Output is correct
24 Correct 6 ms 2936 KB Output is correct
25 Correct 6 ms 2936 KB Output is correct
26 Correct 5 ms 2808 KB Output is correct
27 Correct 5 ms 2680 KB Output is correct
28 Correct 6 ms 2936 KB Output is correct
29 Correct 8 ms 3592 KB Output is correct
30 Correct 6 ms 2936 KB Output is correct
31 Correct 6 ms 3192 KB Output is correct
32 Correct 6 ms 3064 KB Output is correct
33 Correct 10 ms 4340 KB Output is correct
34 Correct 11 ms 4464 KB Output is correct
35 Correct 26 ms 5364 KB Output is correct
36 Correct 8 ms 3064 KB Output is correct
37 Correct 29 ms 6136 KB Output is correct
38 Correct 37 ms 6384 KB Output is correct
39 Correct 33 ms 6388 KB Output is correct
40 Correct 35 ms 6388 KB Output is correct
41 Correct 35 ms 6344 KB Output is correct
42 Correct 10 ms 3196 KB Output is correct
43 Correct 10 ms 3200 KB Output is correct
44 Correct 10 ms 3244 KB Output is correct
45 Correct 34 ms 9220 KB Output is correct
46 Correct 36 ms 9220 KB Output is correct
47 Correct 68 ms 13936 KB Output is correct
48 Correct 25 ms 6388 KB Output is correct
49 Correct 21 ms 5492 KB Output is correct
50 Correct 17 ms 4984 KB Output is correct
51 Correct 58 ms 9088 KB Output is correct
52 Correct 61 ms 9632 KB Output is correct
53 Correct 28 ms 6644 KB Output is correct
54 Correct 7 ms 3316 KB Output is correct
55 Correct 8 ms 3828 KB Output is correct
56 Correct 20 ms 5488 KB Output is correct
57 Correct 48 ms 12280 KB Output is correct
58 Correct 14 ms 4336 KB Output is correct
59 Correct 15 ms 4724 KB Output is correct
60 Correct 16 ms 5500 KB Output is correct
61 Correct 17 ms 4636 KB Output is correct
62 Correct 34 ms 9844 KB Output is correct
63 Correct 93 ms 29032 KB Output is correct
64 Correct 102 ms 32360 KB Output is correct
65 Correct 130 ms 41832 KB Output is correct
66 Correct 240 ms 72164 KB Output is correct
67 Correct 240 ms 72380 KB Output is correct