답안 #82824

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82824 2018-11-01T21:00:18 Z Vasiljko Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
242 ms 70248 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1e9+7;
const int N = 3e4+5;
const ll INF = 2e9+1000;

int n,m,b[N],p[N];
int dist[N];
map<pair<int,int>,bool>exist;
vector<pair<int,int> >v[N];
priority_queue<pair<int,int>>pq;
set<int>S[N];

void Dijkstra(){
    for(int i=0;i<n;i++)dist[i]=INF;
    pq.push({0,b[0]});
    dist[b[0]]=0;

    while(!pq.empty()){
        int t=pq.top().second;
        int len=-pq.top().first;
        pq.pop();
        if(dist[t]<len)continue;
        for(auto e:v[t]){
            int to=e.first;
            ll w=e.second;

            if(dist[t]+w<dist[to]){
                dist[to]=w+dist[t];
                pq.push({-dist[to],to});
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>b[i]>>p[i];
        S[b[i]].insert(p[i]);
        /*if(!exist[{b[i],p[i]}]){
            for(int j=b[i]+p[i],cnt=1;j<n;j+=p[i],cnt++){
                v[b[i]].push_back({j,cnt});
                if(exist[{j,p[i]}])break;
                exist[{j,p[i]}]=true;
            }
            exist[{b[i],p[i]}]=true;
        }
        if(!exist[{b[i],-p[i]}]){
            for(int j=b[i]-p[i],cnt=1;j>=0;j-=p[i],cnt++){
                v[b[i]].push_back({j,cnt});
                if(exist[{j,-p[i]}])break;
                exist[{j,-p[i]}]=true;
            }
            exist[{b[i],-p[i]}]=true;
        }*/
    }

    for(int i=0;i<n;i++){
        for(auto e:S[i]){
            for(int j=i+e;j<n;j+=e){
                v[i].push_back({j,(j-i)/e});
                if(S[j].lower_bound(e)!=S[j].end()&&*S[j].lower_bound(e)==e)break;
            }
            for(int j=i-e;j>=0;j-=e){
                v[i].push_back({j,(i-j)/e});
                if(S[j].lower_bound(e)!=S[j].end()&&*S[j].lower_bound(e)==e)break;
            }
        }
    }
    Dijkstra();

    if(dist[b[1]]==INF)cout<<-1;
    else cout<<dist[b[1]];

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 4 ms 2568 KB Output is correct
3 Correct 3 ms 2568 KB Output is correct
4 Correct 4 ms 2568 KB Output is correct
5 Correct 4 ms 2632 KB Output is correct
6 Correct 4 ms 2692 KB Output is correct
7 Correct 4 ms 2692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2692 KB Output is correct
2 Correct 3 ms 2692 KB Output is correct
3 Correct 4 ms 2692 KB Output is correct
4 Correct 4 ms 2692 KB Output is correct
5 Correct 4 ms 2692 KB Output is correct
6 Correct 4 ms 2692 KB Output is correct
7 Correct 4 ms 2692 KB Output is correct
8 Correct 4 ms 2692 KB Output is correct
9 Correct 4 ms 2692 KB Output is correct
10 Correct 4 ms 2784 KB Output is correct
11 Correct 5 ms 2784 KB Output is correct
12 Correct 4 ms 2784 KB Output is correct
13 Correct 4 ms 2784 KB Output is correct
14 Correct 4 ms 2792 KB Output is correct
15 Correct 5 ms 2792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2792 KB Output is correct
2 Correct 4 ms 2792 KB Output is correct
3 Correct 4 ms 2792 KB Output is correct
4 Correct 3 ms 2792 KB Output is correct
5 Correct 4 ms 2792 KB Output is correct
6 Correct 4 ms 2792 KB Output is correct
7 Correct 4 ms 2792 KB Output is correct
8 Correct 5 ms 2792 KB Output is correct
9 Correct 4 ms 2792 KB Output is correct
10 Correct 4 ms 2812 KB Output is correct
11 Correct 5 ms 2812 KB Output is correct
12 Correct 4 ms 2812 KB Output is correct
13 Correct 4 ms 2812 KB Output is correct
14 Correct 5 ms 2824 KB Output is correct
15 Correct 5 ms 2824 KB Output is correct
16 Correct 4 ms 2824 KB Output is correct
17 Correct 6 ms 3068 KB Output is correct
18 Correct 6 ms 3068 KB Output is correct
19 Correct 5 ms 3068 KB Output is correct
20 Correct 5 ms 3068 KB Output is correct
21 Correct 4 ms 3068 KB Output is correct
22 Correct 4 ms 3068 KB Output is correct
23 Correct 6 ms 3068 KB Output is correct
24 Correct 6 ms 3068 KB Output is correct
25 Correct 6 ms 3068 KB Output is correct
26 Correct 5 ms 3068 KB Output is correct
27 Correct 5 ms 3068 KB Output is correct
28 Correct 6 ms 3068 KB Output is correct
29 Correct 7 ms 3452 KB Output is correct
30 Correct 5 ms 3452 KB Output is correct
31 Correct 5 ms 3452 KB Output is correct
32 Correct 6 ms 3452 KB Output is correct
33 Correct 9 ms 4088 KB Output is correct
34 Correct 9 ms 4100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4100 KB Output is correct
2 Correct 4 ms 4100 KB Output is correct
3 Correct 4 ms 4100 KB Output is correct
4 Correct 5 ms 4100 KB Output is correct
5 Correct 4 ms 4100 KB Output is correct
6 Correct 4 ms 4100 KB Output is correct
7 Correct 4 ms 4100 KB Output is correct
8 Correct 4 ms 4100 KB Output is correct
9 Correct 4 ms 4100 KB Output is correct
10 Correct 5 ms 4100 KB Output is correct
11 Correct 5 ms 4100 KB Output is correct
12 Correct 4 ms 4100 KB Output is correct
13 Correct 4 ms 4100 KB Output is correct
14 Correct 5 ms 4100 KB Output is correct
15 Correct 5 ms 4100 KB Output is correct
16 Correct 4 ms 4100 KB Output is correct
17 Correct 5 ms 4100 KB Output is correct
18 Correct 4 ms 4100 KB Output is correct
19 Correct 5 ms 4100 KB Output is correct
20 Correct 4 ms 4100 KB Output is correct
21 Correct 4 ms 4100 KB Output is correct
22 Correct 6 ms 4100 KB Output is correct
23 Correct 4 ms 4100 KB Output is correct
24 Correct 6 ms 4100 KB Output is correct
25 Correct 5 ms 4100 KB Output is correct
26 Correct 4 ms 4100 KB Output is correct
27 Correct 4 ms 4100 KB Output is correct
28 Correct 5 ms 4100 KB Output is correct
29 Correct 6 ms 4100 KB Output is correct
30 Correct 5 ms 4100 KB Output is correct
31 Correct 6 ms 4100 KB Output is correct
32 Correct 5 ms 4100 KB Output is correct
33 Correct 9 ms 4100 KB Output is correct
34 Correct 9 ms 4100 KB Output is correct
35 Correct 25 ms 5116 KB Output is correct
36 Correct 7 ms 5116 KB Output is correct
37 Correct 30 ms 5884 KB Output is correct
38 Correct 50 ms 6140 KB Output is correct
39 Correct 34 ms 6140 KB Output is correct
40 Correct 33 ms 6140 KB Output is correct
41 Correct 36 ms 6268 KB Output is correct
42 Correct 9 ms 6268 KB Output is correct
43 Correct 9 ms 6268 KB Output is correct
44 Correct 9 ms 6268 KB Output is correct
45 Correct 32 ms 8700 KB Output is correct
46 Correct 33 ms 8700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8700 KB Output is correct
2 Correct 4 ms 8700 KB Output is correct
3 Correct 3 ms 8700 KB Output is correct
4 Correct 3 ms 8700 KB Output is correct
5 Correct 4 ms 8700 KB Output is correct
6 Correct 3 ms 8700 KB Output is correct
7 Correct 4 ms 8700 KB Output is correct
8 Correct 3 ms 8700 KB Output is correct
9 Correct 4 ms 8700 KB Output is correct
10 Correct 4 ms 8700 KB Output is correct
11 Correct 5 ms 8700 KB Output is correct
12 Correct 4 ms 8700 KB Output is correct
13 Correct 4 ms 8700 KB Output is correct
14 Correct 5 ms 8700 KB Output is correct
15 Correct 5 ms 8700 KB Output is correct
16 Correct 4 ms 8700 KB Output is correct
17 Correct 5 ms 8700 KB Output is correct
18 Correct 5 ms 8700 KB Output is correct
19 Correct 4 ms 8700 KB Output is correct
20 Correct 4 ms 8700 KB Output is correct
21 Correct 4 ms 8700 KB Output is correct
22 Correct 4 ms 8700 KB Output is correct
23 Correct 4 ms 8700 KB Output is correct
24 Correct 5 ms 8700 KB Output is correct
25 Correct 5 ms 8700 KB Output is correct
26 Correct 4 ms 8700 KB Output is correct
27 Correct 4 ms 8700 KB Output is correct
28 Correct 5 ms 8700 KB Output is correct
29 Correct 6 ms 8700 KB Output is correct
30 Correct 5 ms 8700 KB Output is correct
31 Correct 5 ms 8700 KB Output is correct
32 Correct 6 ms 8700 KB Output is correct
33 Correct 8 ms 8700 KB Output is correct
34 Correct 9 ms 8700 KB Output is correct
35 Correct 26 ms 8700 KB Output is correct
36 Correct 6 ms 8700 KB Output is correct
37 Correct 29 ms 8700 KB Output is correct
38 Correct 35 ms 8700 KB Output is correct
39 Correct 34 ms 8700 KB Output is correct
40 Correct 34 ms 8700 KB Output is correct
41 Correct 33 ms 8700 KB Output is correct
42 Correct 12 ms 8700 KB Output is correct
43 Correct 9 ms 8700 KB Output is correct
44 Correct 9 ms 8700 KB Output is correct
45 Correct 34 ms 8700 KB Output is correct
46 Correct 33 ms 8700 KB Output is correct
47 Correct 69 ms 13292 KB Output is correct
48 Correct 25 ms 13292 KB Output is correct
49 Correct 20 ms 13292 KB Output is correct
50 Correct 16 ms 13292 KB Output is correct
51 Correct 52 ms 13292 KB Output is correct
52 Correct 53 ms 13292 KB Output is correct
53 Correct 25 ms 13292 KB Output is correct
54 Correct 6 ms 13292 KB Output is correct
55 Correct 7 ms 13292 KB Output is correct
56 Correct 18 ms 13292 KB Output is correct
57 Correct 48 ms 14224 KB Output is correct
58 Correct 13 ms 14224 KB Output is correct
59 Correct 14 ms 14224 KB Output is correct
60 Correct 16 ms 14224 KB Output is correct
61 Correct 15 ms 14224 KB Output is correct
62 Correct 32 ms 14224 KB Output is correct
63 Correct 114 ms 29440 KB Output is correct
64 Correct 108 ms 33096 KB Output is correct
65 Correct 131 ms 42764 KB Output is correct
66 Correct 242 ms 70088 KB Output is correct
67 Correct 225 ms 70248 KB Output is correct