Submission #549725

# Submission time Handle Problem Language Result Execution time Memory
549725 2022-04-16T11:08:15 Z CyberSleeper Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 27240 KB
#include <bits/stdc++.h>
#define fastio      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x)    cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define all(x)      x.begin(), x.end()
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back
#define ll          long long
#define ull         unsigned long long
#define pll         pair<ll, ll>
#define pii         pair<int, int>
#define ld          long double
#define nl          endl
#define tb          '\t'
#define sp          ' '
#define sqr(x)      (x)*(x)
#define arr3        array<int, 3>
using namespace std;
 
const int MX=30005, MOD=1000000007, BLOCK=200, INF=2e9+7, LG=62;
const ll INFF=1000000000000000007;
const ld ERR=1e-6, pi=3.14159265358979323846;
 
int N, M, B[MX], P[MX];
int vis[MX][BLOCK+5], vis2[MX];
vector<int> doge[MX];
 
int main(){
    fastio;
    cin >> N >> M;
    for(int i=0; i<=N; i++){
        for(int j=0; j<=BLOCK; j++)
            vis[i][j]=INF;
    }
    for(int i=0; i<M; i++){
        cin >> B[i] >> P[i];
        doge[B[i]].pb(P[i]);
    }
    priority_queue<arr3, vector<arr3>, greater<arr3>> PQ;
    PQ.push({0, B[0], 0});
    vis[B[0]][0]=0;
    while(PQ.size()){
        int cost=PQ.top()[0], idx=PQ.top()[1], p=PQ.top()[2];
        PQ.pop();
        if(vis[idx][p]<cost)
            continue;
        vis[idx][p]=cost;
        if(!p){
            for(int i:doge[idx]){
                if(i<=BLOCK){
                    if(vis[idx][i]<=cost)
                        continue;
                    vis[idx][i]=cost;
                    PQ.push({cost, idx, i});
                }else{
                    for(int j=1, jj; idx+i*j<N; j++){
                        jj=idx+i*j;
                        if(vis[jj][0]>cost+j){
                            vis[jj][0]=cost+j;
                            PQ.push({cost+j, jj, 0});
                        }
                    }
                    for(int j=1, jj; idx-i*j>=0; j++){
                        jj=idx-i*j;
                        if(vis[jj][0]>cost+j){
                            vis[jj][0]=cost+j;
                            PQ.push({cost+j, jj, 0});
                        }
                    }
                }
            }
        }else{
            for(int j=1, jj; j<=1; j++){
                jj=idx+p*j;
                if(jj>=N)
                    continue;
                if(vis[jj][0]>cost+j){
                    vis[jj][0]=cost+j;
                    PQ.push({cost+j, jj, 0});
                }
                if(vis[jj][p]>cost+j){
                    vis[jj][p]=cost+j;
                    PQ.push({cost+j, jj, p});
                }
            }
            for(int j=1, jj; j<=1; j++){
                jj=idx-p*j;
                if(jj<0)
                    continue;
                if(vis[jj][0]>cost+j){
                    vis[jj][0]=cost+j;
                    PQ.push({cost+j, jj, 0});
                }
                if(vis[jj][p]>cost+j){
                    vis[jj][p]=cost+j;
                    PQ.push({cost+j, jj, p});
                }
            }
        }
    }
    int ans=vis[B[1]][0];
    if(ans==INF)
        ans=-1;
    cout << ans << nl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 952 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 1104 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 2 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 2 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 2 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 3 ms 1620 KB Output is correct
18 Correct 3 ms 2388 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 1 ms 1364 KB Output is correct
22 Correct 3 ms 2516 KB Output is correct
23 Correct 3 ms 2260 KB Output is correct
24 Correct 4 ms 2644 KB Output is correct
25 Correct 3 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 3 ms 2644 KB Output is correct
29 Correct 9 ms 2644 KB Output is correct
30 Correct 4 ms 2644 KB Output is correct
31 Correct 5 ms 2644 KB Output is correct
32 Correct 5 ms 2644 KB Output is correct
33 Correct 18 ms 2772 KB Output is correct
34 Correct 21 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 2 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 3 ms 1620 KB Output is correct
18 Correct 2 ms 2388 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 1 ms 1364 KB Output is correct
22 Correct 2 ms 2388 KB Output is correct
23 Correct 4 ms 2260 KB Output is correct
24 Correct 3 ms 2516 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 3 ms 2644 KB Output is correct
29 Correct 9 ms 2692 KB Output is correct
30 Correct 4 ms 2644 KB Output is correct
31 Correct 6 ms 2692 KB Output is correct
32 Correct 5 ms 2684 KB Output is correct
33 Correct 23 ms 2644 KB Output is correct
34 Correct 18 ms 2644 KB Output is correct
35 Correct 18 ms 2776 KB Output is correct
36 Correct 4 ms 2004 KB Output is correct
37 Correct 29 ms 3136 KB Output is correct
38 Correct 21 ms 3276 KB Output is correct
39 Correct 23 ms 3180 KB Output is correct
40 Correct 22 ms 3284 KB Output is correct
41 Correct 22 ms 3232 KB Output is correct
42 Correct 7 ms 3028 KB Output is correct
43 Correct 8 ms 3028 KB Output is correct
44 Correct 6 ms 3028 KB Output is correct
45 Correct 80 ms 3520 KB Output is correct
46 Correct 71 ms 3616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 3 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 3 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 3 ms 1620 KB Output is correct
18 Correct 2 ms 2388 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 1 ms 1364 KB Output is correct
22 Correct 2 ms 2516 KB Output is correct
23 Correct 4 ms 2260 KB Output is correct
24 Correct 5 ms 2644 KB Output is correct
25 Correct 3 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 3 ms 2644 KB Output is correct
29 Correct 9 ms 2644 KB Output is correct
30 Correct 4 ms 2644 KB Output is correct
31 Correct 8 ms 2644 KB Output is correct
32 Correct 5 ms 2688 KB Output is correct
33 Correct 18 ms 2772 KB Output is correct
34 Correct 18 ms 2768 KB Output is correct
35 Correct 16 ms 2772 KB Output is correct
36 Correct 6 ms 2004 KB Output is correct
37 Correct 29 ms 3028 KB Output is correct
38 Correct 24 ms 3184 KB Output is correct
39 Correct 26 ms 3224 KB Output is correct
40 Correct 23 ms 3156 KB Output is correct
41 Correct 21 ms 3280 KB Output is correct
42 Correct 7 ms 3028 KB Output is correct
43 Correct 6 ms 3028 KB Output is correct
44 Correct 5 ms 3028 KB Output is correct
45 Correct 76 ms 3604 KB Output is correct
46 Correct 73 ms 3544 KB Output is correct
47 Correct 110 ms 11936 KB Output is correct
48 Correct 16 ms 20308 KB Output is correct
49 Correct 15 ms 21972 KB Output is correct
50 Correct 15 ms 23812 KB Output is correct
51 Correct 60 ms 26388 KB Output is correct
52 Correct 72 ms 26388 KB Output is correct
53 Correct 32 ms 25944 KB Output is correct
54 Correct 18 ms 24992 KB Output is correct
55 Correct 18 ms 25044 KB Output is correct
56 Correct 21 ms 26192 KB Output is correct
57 Correct 115 ms 25212 KB Output is correct
58 Correct 23 ms 25556 KB Output is correct
59 Correct 24 ms 25572 KB Output is correct
60 Correct 31 ms 25564 KB Output is correct
61 Correct 24 ms 25556 KB Output is correct
62 Correct 56 ms 26260 KB Output is correct
63 Correct 67 ms 27240 KB Output is correct
64 Correct 84 ms 27152 KB Output is correct
65 Correct 484 ms 27160 KB Output is correct
66 Execution timed out 1091 ms 27204 KB Time limit exceeded
67 Halted 0 ms 0 KB -