Submission #45668

# Submission time Handle Problem Language Result Execution time Memory
45668 2018-04-16T01:44:46 Z Trans Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
92 ms 14248 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <ext/pb_ds/priority_queue.hpp>

#define MAXV 30010
#define MAXE 20000000
#define INF 999999999+208

using namespace std;

struct Pair
{
    int first,second;
    Pair(){}
    Pair(int _f,int _s):first(_f),second(_s){}
};

inline bool operator>(Pair a,Pair b)
{
    return a.first>b.first;
}

int read()
{
    int ans=0;
    char ch=getchar();
    while(ch==' '||ch=='\n') ch=getchar();
    while(ch>='0'&&ch<='9')
    {
        ans=ans*10+ch-'0';
        ch=getchar();
    }
    return ans;
}

int n,m,K;
int dist[MAXV],poslist[MAXV],tot_diff=0;
bool vis[MAXV];
int S,T;
int b[MAXV];
vector<int>p[MAXV];
vector<int>::iterator it;
bool mark[MAXV];

typedef __gnu_pbds :: priority_queue<Pair,greater<Pair>,__gnu_pbds::thin_heap_tag > Heap;
//typedef __gnu_pbds::priority_queue <Pair,greater<Pair >,__gnu_pbds::thin_heap_tag> Heap;
Heap pq;
Heap::point_iterator posmark[MAXV];

inline void update(Pair pr)
{
    if(dist[pr.second]>pr.first)
    {
        pq.modify(posmark[pr.second],pr);
        dist[pr.second]=pr.first; //!!!!!!
    }
}

int Heap_Dij()
{
    memset(dist,127,sizeof(dist));
    dist[S]=0;
    for(int i=0;i<n;i++)
        posmark[i]=pq.push(Pair(dist[i],i));
    while(!pq.empty())
    {
        Pair now=pq.top();
        pq.pop();
        if(now.first>INF) return -1;
        int i=now.second;
        if(i==T) return now.first;
        if(vis[i]) continue;
        vis[i]=true;
        for(int t=0;t<p[i].size();t++)
        {
            int P=p[i][t];
            if(t>0&&P==p[i][t-1]) continue; //!!!!!
            for(int j=i+P,k=1;j<n;j+=P,k++)
            {
                update(Pair(now.first+k,j));
                it=lower_bound(p[j].begin(),p[j].end(),P);
                if(it!=p[j].end()&&*it==P) break;
            }
            for(int j=i-P,k=1;j>=0;j-=P,k++)
            {
                update(Pair(now.first+k,j));
                it=lower_bound(p[j].begin(),p[j].end(),P);
                if(it!=p[j].end()&&*it==P) break;
            }
        }
    }
    return -1;
}

int main()
{
    n=read(),m=read();
    for(int i=1;i<=m;i++)
    {
        int x;
        b[i]=read();
        x=read();
        p[b[i]].push_back(x);
    }
    for(int i=0;i<n;i++)
        sort(p[i].begin(),p[i].end());
    S=b[1],T=b[2];
    printf("%d\n",Heap_Dij());
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int Heap_Dij()':
skyscraper.cpp:79:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int t=0;t<p[i].size();t++)
                     ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1400 KB Output is correct
2 Correct 3 ms 1520 KB Output is correct
3 Correct 3 ms 1520 KB Output is correct
4 Correct 3 ms 1520 KB Output is correct
5 Correct 3 ms 1724 KB Output is correct
6 Correct 2 ms 1724 KB Output is correct
7 Correct 3 ms 1724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1724 KB Output is correct
2 Correct 3 ms 1724 KB Output is correct
3 Correct 3 ms 1724 KB Output is correct
4 Correct 3 ms 1852 KB Output is correct
5 Correct 3 ms 1852 KB Output is correct
6 Correct 3 ms 1852 KB Output is correct
7 Correct 3 ms 1852 KB Output is correct
8 Correct 3 ms 1852 KB Output is correct
9 Correct 3 ms 1852 KB Output is correct
10 Correct 3 ms 1852 KB Output is correct
11 Correct 3 ms 1852 KB Output is correct
12 Correct 3 ms 1852 KB Output is correct
13 Correct 4 ms 1852 KB Output is correct
14 Correct 3 ms 1968 KB Output is correct
15 Correct 3 ms 1968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1968 KB Output is correct
2 Correct 3 ms 1968 KB Output is correct
3 Correct 3 ms 1968 KB Output is correct
4 Correct 3 ms 1968 KB Output is correct
5 Correct 3 ms 1968 KB Output is correct
6 Correct 3 ms 1968 KB Output is correct
7 Correct 3 ms 1968 KB Output is correct
8 Correct 3 ms 1968 KB Output is correct
9 Correct 3 ms 2080 KB Output is correct
10 Correct 3 ms 2080 KB Output is correct
11 Correct 4 ms 2080 KB Output is correct
12 Correct 3 ms 2080 KB Output is correct
13 Correct 3 ms 2080 KB Output is correct
14 Correct 3 ms 2080 KB Output is correct
15 Correct 3 ms 2080 KB Output is correct
16 Correct 3 ms 2080 KB Output is correct
17 Correct 4 ms 2080 KB Output is correct
18 Correct 4 ms 2204 KB Output is correct
19 Correct 3 ms 2216 KB Output is correct
20 Correct 3 ms 2224 KB Output is correct
21 Correct 3 ms 2224 KB Output is correct
22 Correct 4 ms 2252 KB Output is correct
23 Correct 4 ms 2260 KB Output is correct
24 Correct 4 ms 2272 KB Output is correct
25 Correct 4 ms 2292 KB Output is correct
26 Correct 4 ms 2312 KB Output is correct
27 Correct 4 ms 2328 KB Output is correct
28 Correct 4 ms 2328 KB Output is correct
29 Correct 5 ms 2372 KB Output is correct
30 Correct 4 ms 2372 KB Output is correct
31 Correct 4 ms 2380 KB Output is correct
32 Correct 4 ms 2380 KB Output is correct
33 Correct 5 ms 2628 KB Output is correct
34 Correct 5 ms 2628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2628 KB Output is correct
2 Correct 3 ms 2628 KB Output is correct
3 Correct 3 ms 2628 KB Output is correct
4 Correct 3 ms 2628 KB Output is correct
5 Correct 3 ms 2628 KB Output is correct
6 Correct 3 ms 2628 KB Output is correct
7 Correct 3 ms 2628 KB Output is correct
8 Correct 3 ms 2628 KB Output is correct
9 Correct 3 ms 2628 KB Output is correct
10 Correct 4 ms 2628 KB Output is correct
11 Correct 3 ms 2628 KB Output is correct
12 Correct 3 ms 2628 KB Output is correct
13 Correct 3 ms 2628 KB Output is correct
14 Correct 3 ms 2628 KB Output is correct
15 Correct 3 ms 2628 KB Output is correct
16 Correct 3 ms 2628 KB Output is correct
17 Correct 4 ms 2628 KB Output is correct
18 Correct 3 ms 2628 KB Output is correct
19 Correct 3 ms 2628 KB Output is correct
20 Correct 3 ms 2628 KB Output is correct
21 Correct 3 ms 2628 KB Output is correct
22 Correct 3 ms 2668 KB Output is correct
23 Correct 4 ms 2668 KB Output is correct
24 Correct 4 ms 2668 KB Output is correct
25 Correct 3 ms 2688 KB Output is correct
26 Correct 3 ms 2688 KB Output is correct
27 Correct 3 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 5 ms 2824 KB Output is correct
30 Correct 4 ms 2824 KB Output is correct
31 Correct 4 ms 2824 KB Output is correct
32 Correct 4 ms 2824 KB Output is correct
33 Correct 5 ms 2824 KB Output is correct
34 Correct 5 ms 2824 KB Output is correct
35 Correct 9 ms 3128 KB Output is correct
36 Correct 5 ms 3128 KB Output is correct
37 Correct 7 ms 3324 KB Output is correct
38 Correct 10 ms 3740 KB Output is correct
39 Correct 8 ms 3912 KB Output is correct
40 Correct 11 ms 4220 KB Output is correct
41 Correct 11 ms 4528 KB Output is correct
42 Correct 6 ms 4620 KB Output is correct
43 Correct 9 ms 4828 KB Output is correct
44 Correct 9 ms 5056 KB Output is correct
45 Correct 13 ms 5244 KB Output is correct
46 Correct 10 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5456 KB Output is correct
2 Correct 3 ms 5456 KB Output is correct
3 Correct 3 ms 5456 KB Output is correct
4 Correct 3 ms 5456 KB Output is correct
5 Correct 3 ms 5456 KB Output is correct
6 Correct 3 ms 5456 KB Output is correct
7 Correct 3 ms 5456 KB Output is correct
8 Correct 3 ms 5456 KB Output is correct
9 Correct 3 ms 5456 KB Output is correct
10 Correct 4 ms 5456 KB Output is correct
11 Correct 3 ms 5456 KB Output is correct
12 Correct 3 ms 5456 KB Output is correct
13 Correct 3 ms 5456 KB Output is correct
14 Correct 3 ms 5456 KB Output is correct
15 Correct 3 ms 5456 KB Output is correct
16 Correct 3 ms 5456 KB Output is correct
17 Correct 3 ms 5456 KB Output is correct
18 Correct 3 ms 5456 KB Output is correct
19 Correct 3 ms 5456 KB Output is correct
20 Correct 3 ms 5456 KB Output is correct
21 Correct 3 ms 5456 KB Output is correct
22 Correct 4 ms 5464 KB Output is correct
23 Correct 3 ms 5472 KB Output is correct
24 Correct 4 ms 5484 KB Output is correct
25 Correct 3 ms 5504 KB Output is correct
26 Correct 3 ms 5524 KB Output is correct
27 Correct 4 ms 5540 KB Output is correct
28 Correct 4 ms 5556 KB Output is correct
29 Correct 4 ms 5576 KB Output is correct
30 Correct 3 ms 5584 KB Output is correct
31 Correct 4 ms 5588 KB Output is correct
32 Correct 5 ms 5592 KB Output is correct
33 Correct 6 ms 5592 KB Output is correct
34 Correct 4 ms 5608 KB Output is correct
35 Correct 9 ms 6132 KB Output is correct
36 Correct 4 ms 6132 KB Output is correct
37 Correct 7 ms 6136 KB Output is correct
38 Correct 9 ms 6552 KB Output is correct
39 Correct 8 ms 6816 KB Output is correct
40 Correct 8 ms 7080 KB Output is correct
41 Correct 11 ms 7344 KB Output is correct
42 Correct 6 ms 7496 KB Output is correct
43 Correct 6 ms 7704 KB Output is correct
44 Correct 6 ms 7912 KB Output is correct
45 Correct 9 ms 8136 KB Output is correct
46 Correct 9 ms 8332 KB Output is correct
47 Correct 17 ms 9312 KB Output is correct
48 Correct 10 ms 10056 KB Output is correct
49 Correct 13 ms 10428 KB Output is correct
50 Correct 8 ms 10788 KB Output is correct
51 Correct 43 ms 11552 KB Output is correct
52 Correct 34 ms 11676 KB Output is correct
53 Correct 14 ms 12048 KB Output is correct
54 Correct 8 ms 12048 KB Output is correct
55 Correct 9 ms 12048 KB Output is correct
56 Correct 14 ms 12776 KB Output is correct
57 Correct 10 ms 12776 KB Output is correct
58 Correct 13 ms 12776 KB Output is correct
59 Correct 20 ms 12776 KB Output is correct
60 Correct 20 ms 12776 KB Output is correct
61 Correct 22 ms 12776 KB Output is correct
62 Correct 25 ms 13836 KB Output is correct
63 Correct 43 ms 13836 KB Output is correct
64 Correct 47 ms 13836 KB Output is correct
65 Correct 69 ms 13836 KB Output is correct
66 Correct 92 ms 13948 KB Output is correct
67 Correct 76 ms 14248 KB Output is correct