Submission #151866

# Submission time Handle Problem Language Result Execution time Memory
151866 2019-09-05T07:40:50 Z Ruxandra985 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
818 ms 3948 KB
/// cine ia tle ? eu iau tle
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#define DIMN 30010

using namespace std;
priority_queue <pair <int,int> > h;
int f[DIMN],dp[DIMN];
pair <int,int> v[DIMN];
vector <int> poz[DIMN];
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n,m,i,curr,add,jump,p,idx;
    fscanf (fin,"%d%d",&n,&m);
    for (i=1;i<=m;i++){
        fscanf (fin,"%d%d",&v[i].first,&v[i].second);
        v[i].first++;
        poz[v[i].first].push_back(i);
    }
    for (i=1;i<=n;i++)
        dp[i] = 2000000000;
    h.push(make_pair(0,v[1].first));
    dp[v[1].first] = 0;
    while (!h.empty()){
        curr = h.top().second;
        h.pop();
        while (f[curr] && !h.empty()){
            curr = h.top().second;
            h.pop();
        }
        if (h.empty() && f[curr])
            break;
        f[curr] = 1;
        /// cost = dp[curr]
        for (i=0;i<poz[curr].size();i++){
            idx = poz[curr][i];
            add = v[idx].second;
            p = curr + add;
            jump = 1;
            while (p<=n){
                if (dp[p] > dp[curr] + jump){
                    dp[p] = dp[curr] + jump;
                    h.push(make_pair(-dp[p] , p));
                }
                p+=add;
                jump++;
            }
            p = curr - add;
            jump = 1;
            while (p>0){
                if (dp[p] > dp[curr] + jump){
                    dp[p] = dp[curr] + jump;
                    h.push(make_pair(-dp[p] , p));
                }
                p-=add;
                jump++;
            }
        }
    }
    if (dp[v[2].first] == 2000000000)
        dp[v[2].first] = -1;
    fprintf (fout,"%d",dp[v[2].first]);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:39:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i=0;i<poz[curr].size();i++){
                  ~^~~~~~~~~~~~~~~~~
skyscraper.cpp:18:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d",&n,&m);
     ~~~~~~~^~~~~~~~~~~~~~~~~~
skyscraper.cpp:20:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d%d",&v[i].first,&v[i].second);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1016 KB Output is correct
2 Correct 0 ms 1016 KB Output is correct
3 Correct 2 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 2 ms 1016 KB Output is correct
6 Correct 2 ms 1016 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 2 ms 1016 KB Output is correct
4 Correct 2 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 2 ms 1016 KB Output is correct
8 Correct 2 ms 1016 KB Output is correct
9 Correct 2 ms 988 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1016 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1016 KB Output is correct
14 Correct 3 ms 1016 KB Output is correct
15 Correct 3 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 2 ms 1016 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1016 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1016 KB Output is correct
14 Correct 3 ms 1016 KB Output is correct
15 Correct 3 ms 1016 KB Output is correct
16 Correct 3 ms 1016 KB Output is correct
17 Correct 3 ms 1016 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 7 ms 1144 KB Output is correct
21 Correct 3 ms 1016 KB Output is correct
22 Correct 3 ms 1020 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 4 ms 1144 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 7 ms 1016 KB Output is correct
27 Correct 6 ms 1016 KB Output is correct
28 Correct 3 ms 1144 KB Output is correct
29 Correct 4 ms 1144 KB Output is correct
30 Correct 3 ms 1144 KB Output is correct
31 Correct 4 ms 1144 KB Output is correct
32 Correct 3 ms 1144 KB Output is correct
33 Correct 4 ms 1144 KB Output is correct
34 Correct 4 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 2 ms 1016 KB Output is correct
3 Correct 2 ms 1020 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 2 ms 1016 KB Output is correct
7 Correct 2 ms 1016 KB Output is correct
8 Correct 2 ms 1016 KB Output is correct
9 Correct 2 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1016 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1016 KB Output is correct
14 Correct 3 ms 1016 KB Output is correct
15 Correct 3 ms 1016 KB Output is correct
16 Correct 3 ms 1016 KB Output is correct
17 Correct 3 ms 1016 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1016 KB Output is correct
20 Correct 7 ms 1144 KB Output is correct
21 Correct 3 ms 1144 KB Output is correct
22 Correct 3 ms 1016 KB Output is correct
23 Correct 3 ms 1016 KB Output is correct
24 Correct 4 ms 1144 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 7 ms 1172 KB Output is correct
27 Correct 6 ms 1016 KB Output is correct
28 Correct 3 ms 1144 KB Output is correct
29 Correct 4 ms 1144 KB Output is correct
30 Correct 3 ms 1144 KB Output is correct
31 Correct 4 ms 1144 KB Output is correct
32 Correct 3 ms 1144 KB Output is correct
33 Correct 5 ms 1144 KB Output is correct
34 Correct 5 ms 1272 KB Output is correct
35 Correct 12 ms 1464 KB Output is correct
36 Correct 5 ms 1016 KB Output is correct
37 Correct 11 ms 1528 KB Output is correct
38 Correct 13 ms 1656 KB Output is correct
39 Correct 13 ms 1656 KB Output is correct
40 Correct 13 ms 1656 KB Output is correct
41 Correct 13 ms 1656 KB Output is correct
42 Correct 61 ms 1528 KB Output is correct
43 Correct 61 ms 1528 KB Output is correct
44 Correct 62 ms 1528 KB Output is correct
45 Correct 12 ms 1656 KB Output is correct
46 Correct 11 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 2 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 2 ms 1016 KB Output is correct
5 Correct 2 ms 1016 KB Output is correct
6 Correct 3 ms 1020 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 0 ms 1016 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1016 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1016 KB Output is correct
17 Correct 3 ms 1144 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1016 KB Output is correct
20 Correct 7 ms 1144 KB Output is correct
21 Correct 3 ms 1016 KB Output is correct
22 Correct 3 ms 1016 KB Output is correct
23 Correct 3 ms 1016 KB Output is correct
24 Correct 4 ms 1144 KB Output is correct
25 Correct 4 ms 1148 KB Output is correct
26 Correct 6 ms 1020 KB Output is correct
27 Correct 6 ms 1016 KB Output is correct
28 Correct 3 ms 1144 KB Output is correct
29 Correct 4 ms 1144 KB Output is correct
30 Correct 3 ms 1144 KB Output is correct
31 Correct 3 ms 1144 KB Output is correct
32 Correct 3 ms 1144 KB Output is correct
33 Correct 4 ms 1272 KB Output is correct
34 Correct 4 ms 1272 KB Output is correct
35 Correct 11 ms 1528 KB Output is correct
36 Correct 4 ms 1144 KB Output is correct
37 Correct 10 ms 1400 KB Output is correct
38 Correct 13 ms 1656 KB Output is correct
39 Correct 13 ms 1656 KB Output is correct
40 Correct 13 ms 1556 KB Output is correct
41 Correct 13 ms 1656 KB Output is correct
42 Correct 62 ms 1528 KB Output is correct
43 Correct 61 ms 1528 KB Output is correct
44 Correct 62 ms 1528 KB Output is correct
45 Correct 11 ms 1528 KB Output is correct
46 Correct 11 ms 1528 KB Output is correct
47 Correct 23 ms 2296 KB Output is correct
48 Correct 11 ms 1912 KB Output is correct
49 Correct 11 ms 2040 KB Output is correct
50 Correct 8 ms 1784 KB Output is correct
51 Correct 33 ms 3576 KB Output is correct
52 Correct 38 ms 3064 KB Output is correct
53 Correct 23 ms 2936 KB Output is correct
54 Correct 5 ms 1528 KB Output is correct
55 Correct 5 ms 1528 KB Output is correct
56 Correct 818 ms 3216 KB Output is correct
57 Correct 58 ms 3440 KB Output is correct
58 Correct 816 ms 2040 KB Output is correct
59 Correct 807 ms 2296 KB Output is correct
60 Correct 801 ms 2108 KB Output is correct
61 Correct 724 ms 2168 KB Output is correct
62 Correct 17 ms 2680 KB Output is correct
63 Correct 32 ms 3156 KB Output is correct
64 Correct 31 ms 2932 KB Output is correct
65 Correct 34 ms 2988 KB Output is correct
66 Correct 45 ms 3944 KB Output is correct
67 Correct 45 ms 3948 KB Output is correct