Submission #583020

# Submission time Handle Problem Language Result Execution time Memory
583020 2022-06-24T17:33:08 Z gg123_pe Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
6 ms 2388 KB
#include <bits/stdc++.h>
using namespace std; 

typedef long long ll; 
typedef pair<ll,ll> ii; 

#define f(i,a,b) for(int i = a; i < b; i++)
#define fa(i,a,b) for(int i = a; i >= b; i--)

const int N = 2005; 
const ll inf = 1e9;


int n, m, b[N];
ll p[N], d[N];
 
vector <pair<int,ll>> adj[N], v[N];
set <int> s[N]; 

void dij(int x){
    f(i,0,m) d[i] = inf; 
    d[x] = 0; 

    priority_queue <ii, vector <ii>, greater<ii>> q; 
    q.push({0, x}); 

    while(!q.empty()){
        ii p = q.top(); 
        q.pop(); 

        ll d_v = p.first, v = p.second; 

        if(d_v != d[v]) continue; 

        for(auto wi: adj[v]){
            ll u = wi.first, w = wi.second; 
            if(d[u] > d[v] + w){
                d[u] = d[v] + w; 
                q.push({d[u], u}); 
            }
        }
    }
}
int main(){
    cin >> n >> m; 

    f(i,0,m){
        cin >> b[i] >> p[i]; 
        s[b[i]].insert(p[i]); 
        v[b[i]].push_back({p[i], i}); 
    }

    f(i,0,n){
        int l = v[i].size(); 
        f(j,0,l){
            adj[v[i][j].second].push_back({v[i][(j+1)%l].second, 0}); 
        }
    }

    f(i,0,n){
        map <int, bool> us; 

        for(auto p: v[i]){
            int pi = p.first, node = p.second; 
            if(us[pi]) continue; 
            us[pi] = 1; 

            for(ll x = i-pi; x >= 0; x -= pi){
                for(auto u: v[x]){
                    adj[node].push_back({u.second, (i-x)/pi});
                }
                if(s[x].count(pi)) break; 
            }
        }
    }
 
    fa(i,n-1,0){
        map <int, bool> us; 

        for(auto p: v[i]){
            int pi = p.first, node = p.second; 
            if(us[pi]) continue; 
            us[pi] = 1; 

            for(ll x = i+pi; x < n; x += pi){
                for(auto u: v[x]){
                    adj[node].push_back({u.second, (x-i)/pi});
                }
                if(s[x].count(pi)) break; 
            }
        }
    }
    dij(0); 

   
    cout << ((d[1] == inf) ? -1 : d[1]) << "\n"; 
    return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 5 ms 2388 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 4 ms 1748 KB Output is correct
15 Correct 6 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 5 ms 2388 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 4 ms 1748 KB Output is correct
15 Correct 4 ms 1748 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 5 ms 1492 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 3 ms 980 KB Output is correct
25 Correct 3 ms 980 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 3 ms 1108 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 5 ms 1748 KB Output is correct
34 Correct 5 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 5 ms 2388 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 5 ms 1748 KB Output is correct
15 Correct 4 ms 1748 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 4 ms 1492 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 4 ms 1028 KB Output is correct
25 Correct 3 ms 980 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 3 ms 1108 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 5 ms 1684 KB Output is correct
34 Correct 5 ms 1748 KB Output is correct
35 Incorrect 3 ms 980 KB Output isn't correct
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 5 ms 2388 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 6 ms 1748 KB Output is correct
15 Correct 4 ms 1748 KB Output is correct
16 Correct 2 ms 852 KB Output is correct
17 Correct 4 ms 1492 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 3 ms 980 KB Output is correct
25 Correct 3 ms 980 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 3 ms 1108 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 5 ms 1748 KB Output is correct
34 Correct 4 ms 1748 KB Output is correct
35 Incorrect 3 ms 980 KB Output isn't correct
36 Halted 0 ms 0 KB -