Submission #338575

# Submission time Handle Problem Language Result Execution time Memory
338575 2020-12-23T12:52:31 Z bigDuck Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
608 ms 12652 KB
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount

/*ifstream fin("test_input.txt");
#define cin fin*/



int t, n, m, k, b[30010], p[30010];
int crd[30010];


int d[30010];
bool v[30010];
vector<pii> g[30010];
bool dog[30010];



void dijkstra(){
multiset<pii> ms;
ms.insert({d[crd[1] ], crd[1]});

while(!ms.empty()){
    auto f=*ms.begin(); ms.erase(ms.begin());
    int nod=f.sc;
    v[nod]=true;
    //cout<<nod<<" "<<d[nod]<<"y\n";
    if(nod==crd[2]){return;}

    for(auto pr:g[nod]){
        int u=pr.ft, c=pr.sc;
        if(v[u]){continue;}
        //cout<<u<<" "<<c<<"x\n";
        auto it=ms.find({d[u], u});
        if(it!=ms.end()){
            ms.erase(it);
            d[u]=min(d[u], d[nod]+c);
            ms.insert({d[u], u});
        }
        else{
                d[u]=d[nod]+c;
            ms.insert({d[u], u} );
        }
    }


}

return;
}




map<pii, int> up, down;
pii pr[30010];



void add_chain(int b, int p){

int lim=down[{b%p, p}];
int cnt=0;
for(int i=b-p; (i>=1) && ( (i>=lim)||(cnt<1) ) ; i-=p){
    if(dog[i]){g[b].pb({i, abs(i-b)/p }); cnt++; }
}
down[{b%p, p}]=max(lim, b);


if(up[{b%p, p}]==0){ up[{b%p, p }]=n+1; }
lim=up[{b%p, p}];
cnt=0;
for(int i=b+p; (i<=n) && ( (i<=lim)|| (cnt<1) ) ; i+=p){
    if(dog[i]){g[b].pb({i, abs(i-b)/p });cnt++; }
}
up[{b%p, p} ]=min( lim, b);

}





int32_t main(){
INIT
cin>>n>>m;

for(int i=1; i<=n; i++){d[i]=-1; }

for(int i=1; i<=m; i++){
cin>>b[i]>>p[i]; b[i]++;
crd[i ]=b[i];
dog[b[i] ]=true;
pr[i]={b[i], p[i]};
}
sort(pr+1, pr+1+m);
for(int i=1; i<=m; i++){
    add_chain(pr[i].ft, pr[i].sc);
}





d[crd[1] ]=0;
dijkstra();
cout<<d[crd[2] ];

/*for(int i=1; i<=n; i++){
    for(auto u:g[i]){
        cout<<u.ft<<" ";
    }
    cout<<"\n";
}*/



return 0;
}



# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 2 ms 1132 KB Output is correct
11 Correct 3 ms 1388 KB Output is correct
12 Correct 2 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 3 ms 1408 KB Output is correct
15 Correct 3 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 2 ms 1132 KB Output is correct
11 Correct 3 ms 1388 KB Output is correct
12 Correct 2 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 3 ms 1388 KB Output is correct
15 Correct 4 ms 1388 KB Output is correct
16 Correct 2 ms 1260 KB Output is correct
17 Correct 5 ms 1516 KB Output is correct
18 Correct 2 ms 1260 KB Output is correct
19 Correct 2 ms 1132 KB Output is correct
20 Correct 2 ms 1260 KB Output is correct
21 Correct 2 ms 1260 KB Output is correct
22 Correct 2 ms 1260 KB Output is correct
23 Correct 2 ms 1260 KB Output is correct
24 Correct 4 ms 1516 KB Output is correct
25 Correct 3 ms 1516 KB Output is correct
26 Correct 2 ms 1260 KB Output is correct
27 Correct 3 ms 1260 KB Output is correct
28 Correct 3 ms 1644 KB Output is correct
29 Correct 2 ms 1260 KB Output is correct
30 Correct 1 ms 1132 KB Output is correct
31 Correct 2 ms 1132 KB Output is correct
32 Correct 1 ms 1132 KB Output is correct
33 Correct 3 ms 1388 KB Output is correct
34 Correct 3 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 2 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 2 ms 1132 KB Output is correct
11 Correct 3 ms 1388 KB Output is correct
12 Correct 2 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 3 ms 1388 KB Output is correct
15 Correct 3 ms 1388 KB Output is correct
16 Correct 2 ms 1260 KB Output is correct
17 Correct 5 ms 1516 KB Output is correct
18 Correct 2 ms 1260 KB Output is correct
19 Correct 2 ms 1132 KB Output is correct
20 Correct 2 ms 1260 KB Output is correct
21 Correct 2 ms 1260 KB Output is correct
22 Correct 3 ms 1260 KB Output is correct
23 Correct 2 ms 1260 KB Output is correct
24 Correct 4 ms 1516 KB Output is correct
25 Correct 3 ms 1516 KB Output is correct
26 Correct 2 ms 1260 KB Output is correct
27 Correct 3 ms 1260 KB Output is correct
28 Correct 4 ms 1644 KB Output is correct
29 Correct 2 ms 1260 KB Output is correct
30 Correct 1 ms 1132 KB Output is correct
31 Correct 2 ms 1132 KB Output is correct
32 Correct 2 ms 1132 KB Output is correct
33 Correct 3 ms 1388 KB Output is correct
34 Correct 3 ms 1388 KB Output is correct
35 Correct 44 ms 5996 KB Output is correct
36 Correct 6 ms 2028 KB Output is correct
37 Correct 50 ms 6124 KB Output is correct
38 Correct 53 ms 7404 KB Output is correct
39 Correct 48 ms 7276 KB Output is correct
40 Correct 46 ms 7276 KB Output is correct
41 Correct 49 ms 7532 KB Output is correct
42 Correct 10 ms 2544 KB Output is correct
43 Correct 19 ms 2540 KB Output is correct
44 Correct 10 ms 2536 KB Output is correct
45 Correct 35 ms 5996 KB Output is correct
46 Correct 34 ms 5996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 1132 KB Output is correct
8 Correct 1 ms 1280 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 1132 KB Output is correct
11 Correct 3 ms 1388 KB Output is correct
12 Correct 2 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 3 ms 1388 KB Output is correct
15 Correct 3 ms 1388 KB Output is correct
16 Correct 2 ms 1260 KB Output is correct
17 Correct 5 ms 1516 KB Output is correct
18 Correct 2 ms 1260 KB Output is correct
19 Correct 2 ms 1132 KB Output is correct
20 Correct 2 ms 1260 KB Output is correct
21 Correct 2 ms 1260 KB Output is correct
22 Correct 2 ms 1260 KB Output is correct
23 Correct 2 ms 1260 KB Output is correct
24 Correct 4 ms 1516 KB Output is correct
25 Correct 3 ms 1516 KB Output is correct
26 Correct 3 ms 1260 KB Output is correct
27 Correct 3 ms 1260 KB Output is correct
28 Correct 4 ms 1644 KB Output is correct
29 Correct 2 ms 1260 KB Output is correct
30 Correct 1 ms 1132 KB Output is correct
31 Correct 2 ms 1132 KB Output is correct
32 Correct 1 ms 1132 KB Output is correct
33 Correct 3 ms 1388 KB Output is correct
34 Correct 4 ms 1388 KB Output is correct
35 Correct 43 ms 5996 KB Output is correct
36 Correct 7 ms 2028 KB Output is correct
37 Correct 50 ms 5996 KB Output is correct
38 Correct 53 ms 7404 KB Output is correct
39 Correct 44 ms 7276 KB Output is correct
40 Correct 45 ms 7276 KB Output is correct
41 Correct 47 ms 7404 KB Output is correct
42 Correct 10 ms 2544 KB Output is correct
43 Correct 16 ms 2540 KB Output is correct
44 Correct 10 ms 2536 KB Output is correct
45 Correct 35 ms 5996 KB Output is correct
46 Correct 36 ms 5996 KB Output is correct
47 Correct 127 ms 12652 KB Output is correct
48 Correct 36 ms 6252 KB Output is correct
49 Correct 29 ms 5356 KB Output is correct
50 Correct 23 ms 4204 KB Output is correct
51 Correct 110 ms 8936 KB Output is correct
52 Correct 87 ms 9064 KB Output is correct
53 Correct 38 ms 6824 KB Output is correct
54 Correct 1 ms 1132 KB Output is correct
55 Correct 1 ms 1132 KB Output is correct
56 Correct 23 ms 4592 KB Output is correct
57 Correct 7 ms 2156 KB Output is correct
58 Correct 608 ms 2692 KB Output is correct
59 Correct 17 ms 2668 KB Output is correct
60 Correct 25 ms 2668 KB Output is correct
61 Correct 25 ms 2916 KB Output is correct
62 Correct 48 ms 10992 KB Output is correct
63 Correct 32 ms 5996 KB Output is correct
64 Correct 33 ms 5868 KB Output is correct
65 Correct 35 ms 5996 KB Output is correct
66 Correct 47 ms 6124 KB Output is correct
67 Correct 43 ms 6124 KB Output is correct